Mercurial > pidgin
comparison src/server.c @ 12949:9a5b9680aaeb
[gaim-migrate @ 15302]
SF Patch #1406080 from Sadrul
"Gaim leaks when you are away on AIM without any away
message and autoreply is enabled for `When Away'. This
patch fixes that.
It also updates the timestamp for last-sent autoreply
only when the autoreply was actually sent."
It also removes some duplicated code.
I tweaked a couple other things in the function to narrow variable scope a
little more.
It looked good and even compiled. What more can you ask for?
committer: Tailor Script <tailor@pidgin.im>
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Thu, 19 Jan 2006 07:36:38 +0000 |
| parents | 7dc00a9dfba5 |
| children | b7fd4315ab79 |
comparison
equal
deleted
inserted
replaced
| 12948:563fb4f1e9fc | 12949:9a5b9680aaeb |
|---|---|
| 496 /* | 496 /* |
| 497 * XXX: Should we be setting this here, or relying on prpls to set it? | 497 * XXX: Should we be setting this here, or relying on prpls to set it? |
| 498 */ | 498 */ |
| 499 flags |= GAIM_MESSAGE_RECV; | 499 flags |= GAIM_MESSAGE_RECV; |
| 500 | 500 |
| 501 if (cnv == NULL) | |
| 502 cnv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, name); | |
| 503 | |
| 504 gaim_conv_im_write(GAIM_CONV_IM(cnv), NULL, message, flags, mtime); | |
| 505 g_free(message); | |
| 506 | |
| 501 /* | 507 /* |
| 502 * Alright. Two cases for how to handle this. Either we're away or | 508 * Don't autorespond if: |
| 503 * we're not. If we're not, then it's easy. If we are, then there | 509 * |
| 504 * are three or four different ways of handling it and different | 510 * - it's not supported on this connection |
| 505 * things we have to do for each. | 511 * - we are available |
| 512 * - or it's disabled | |
| 513 * - or we're not idle and the 'only auto respond if idle' pref | |
| 514 * is set | |
| 506 */ | 515 */ |
| 507 if (!gaim_presence_is_available(presence)) | 516 if (gc->flags & GAIM_CONNECTION_AUTO_RESP) |
| 508 { | 517 { |
| 509 time_t t = time(NULL); | |
| 510 struct last_auto_response *lar; | |
| 511 const gchar *auto_reply_pref; | 518 const gchar *auto_reply_pref; |
| 512 const char *away_msg; | 519 const char *away_msg = NULL; |
| 513 | 520 |
| 514 if (cnv == NULL) | |
| 515 cnv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, name); | |
| 516 | |
| 517 gaim_conv_im_write(GAIM_CONV_IM(cnv), NULL, message, flags, mtime); | |
| 518 | |
| 519 /* | |
| 520 * Don't autorespond if: | |
| 521 * | |
| 522 * - it's not supported on this connection | |
| 523 * - we are available | |
| 524 * - or it's disabled | |
| 525 * - or we're not idle and the 'only auto respond if idle' pref | |
| 526 * is set | |
| 527 */ | |
| 528 auto_reply_pref = gaim_prefs_get_string("/core/away/auto_reply"); | 521 auto_reply_pref = gaim_prefs_get_string("/core/away/auto_reply"); |
| 529 | 522 |
| 530 if (!(gc->flags & GAIM_CONNECTION_AUTO_RESP) || | 523 if (gaim_presence_is_available(presence) || |
| 531 gaim_presence_is_available(presence) || | 524 !strcmp(auto_reply_pref, "never") || |
| 532 !strcmp(auto_reply_pref, "never") || | 525 (!gaim_presence_is_idle(presence) && |
| 533 (!gaim_presence_is_idle(presence) && | 526 !strcmp(auto_reply_pref, "awayidle"))) |
| 534 !strcmp(auto_reply_pref, "awayidle"))) { | 527 { |
| 535 | |
| 536 g_free(name); | 528 g_free(name); |
| 537 g_free(message); | |
| 538 return; | 529 return; |
| 539 } | 530 } |
| 540 | 531 |
| 541 /* | 532 status = gaim_presence_get_active_status(presence); |
| 542 * This used to be based on the conversation window. But um, if | 533 if (status != NULL) |
| 543 * you went away, and someone sent you a message and got your | 534 away_msg = gaim_value_get_string( |
| 544 * auto-response, and then you closed the window, and then the | 535 gaim_status_get_attr_value(status, "message")); |
| 545 * sent you another one, they'd get the auto-response back too | 536 |
| 546 * soon. Besides that, we need to keep track of this even if we've | 537 if ((away_msg != NULL) && (*away_msg != '\0')) { |
| 547 * got a queue. So the rest of this block is just the auto-response, | 538 struct last_auto_response *lar; |
| 548 * if necessary. | 539 time_t now = time(NULL); |
| 549 */ | 540 |
| 550 lar = get_last_auto_response(gc, name); | 541 /* |
| 551 if ((t - lar->sent) < SECS_BEFORE_RESENDING_AUTORESPONSE) { | 542 * This used to be based on the conversation window. But um, if |
| 552 g_free(name); | 543 * you went away, and someone sent you a message and got your |
| 553 g_free(message); | 544 * auto-response, and then you closed the window, and then they |
| 554 return; | 545 * sent you another one, they'd get the auto-response back too |
| 546 * soon. Besides that, we need to keep track of this even if we've | |
| 547 * got a queue. So the rest of this block is just the auto-response, | |
| 548 * if necessary. | |
| 549 */ | |
| 550 lar = get_last_auto_response(gc, name); | |
| 551 if ((now - lar->sent) >= SECS_BEFORE_RESENDING_AUTORESPONSE) | |
| 552 { | |
| 553 lar->sent = now; | |
| 554 | |
| 555 serv_send_im(gc, name, away_msg, GAIM_MESSAGE_AUTO_RESP); | |
| 556 | |
| 557 gaim_conv_im_write(GAIM_CONV_IM(cnv), NULL, away_msg, | |
| 558 GAIM_MESSAGE_SEND | GAIM_MESSAGE_AUTO_RESP, | |
| 559 mtime); | |
| 560 } | |
| 555 } | 561 } |
| 556 lar->sent = t; | |
| 557 | |
| 558 status = gaim_presence_get_active_status(presence); | |
| 559 if (status == NULL) | |
| 560 return; | |
| 561 | |
| 562 away_msg = gaim_value_get_string( | |
| 563 gaim_status_get_attr_value(status, "message")); | |
| 564 | |
| 565 if ((away_msg == NULL) || (*away_msg == '\0')) | |
| 566 return; | |
| 567 | |
| 568 serv_send_im(gc, name, away_msg, GAIM_MESSAGE_AUTO_RESP); | |
| 569 | |
| 570 gaim_conv_im_write(GAIM_CONV_IM(cnv), NULL, away_msg, | |
| 571 GAIM_MESSAGE_SEND | GAIM_MESSAGE_AUTO_RESP, | |
| 572 mtime); | |
| 573 } | |
| 574 else | |
| 575 { | |
| 576 /* | |
| 577 * We're not away. This is easy. If the convo window doesn't | |
| 578 * exist, create and update it (if it does exist it was updated | |
| 579 * earlier), then play a sound indicating we've received it and | |
| 580 * then display it. Easy. | |
| 581 */ | |
| 582 | |
| 583 if (cnv == NULL) | |
| 584 cnv = gaim_conversation_new(GAIM_CONV_TYPE_IM, gc->account, name); | |
| 585 | |
| 586 gaim_conv_im_write(GAIM_CONV_IM(cnv), NULL, message, flags, mtime); | |
| 587 } | 562 } |
| 588 | 563 |
| 589 g_free(name); | 564 g_free(name); |
| 590 g_free(message); | |
| 591 } | 565 } |
| 592 | 566 |
| 593 void serv_got_typing(GaimConnection *gc, const char *name, int timeout, | 567 void serv_got_typing(GaimConnection *gc, const char *name, int timeout, |
| 594 GaimTypingState state) { | 568 GaimTypingState state) { |
| 595 GaimConversation *conv; | 569 GaimConversation *conv; |
