changeset 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 563fb4f1e9fc
children 96cf4e176ff8
files src/server.c
diffstat 1 files changed, 49 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/src/server.c	Thu Jan 19 07:21:18 2006 +0000
+++ b/src/server.c	Thu Jan 19 07:36:38 2006 +0000
@@ -498,96 +498,70 @@
 	 */
 	flags |= GAIM_MESSAGE_RECV;
 
-	/*
-	 * Alright. Two cases for how to handle this. Either we're away or
-	 * we're not. If we're not, then it's easy. If we are, then there
-	 * are three or four different ways of handling it and different
-	 * things we have to do for each.
-	 */
-	if (!gaim_presence_is_available(presence))
-	{
-		time_t t = time(NULL);
-		struct last_auto_response *lar;
-		const gchar *auto_reply_pref;
-		const char *away_msg;
+	if (cnv == NULL)
+		cnv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, name);
+
+	gaim_conv_im_write(GAIM_CONV_IM(cnv), NULL, message, flags, mtime);
+	g_free(message);
 
-		if (cnv == NULL)
-			cnv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, name);
-
-		gaim_conv_im_write(GAIM_CONV_IM(cnv), NULL, message, flags, mtime);
+	/*
+	 * Don't autorespond if:
+	 *
+	 *  - it's not supported on this connection
+	 *  - we are available
+	 *  - or it's disabled
+	 *  - or we're not idle and the 'only auto respond if idle' pref
+	 *    is set
+	 */
+	if (gc->flags & GAIM_CONNECTION_AUTO_RESP)
+	{
+		const gchar *auto_reply_pref;
+		const char *away_msg = NULL;
 
-		/*
-		 * Don't autorespond if:
-		 *
-		 *  - it's not supported on this connection
-		 *  - we are available
-		 *  - or it's disabled
-		 *  - or we're not idle and the 'only auto respond if idle' pref
-		 *    is set
-		 */
 		auto_reply_pref = gaim_prefs_get_string("/core/away/auto_reply");
 
-		if (!(gc->flags & GAIM_CONNECTION_AUTO_RESP) ||
-				gaim_presence_is_available(presence) ||
-				!strcmp(auto_reply_pref, "never") ||
-				(!gaim_presence_is_idle(presence) &&
-				!strcmp(auto_reply_pref, "awayidle"))) {
-
+		if (gaim_presence_is_available(presence) ||
+		    !strcmp(auto_reply_pref, "never") ||
+		    (!gaim_presence_is_idle(presence) &&
+		     !strcmp(auto_reply_pref, "awayidle")))
+		{
 			g_free(name);
-			g_free(message);
 			return;
 		}
 
-		/*
-		 * This used to be based on the conversation window. But um, if
-		 * you went away, and someone sent you a message and got your
-		 * auto-response, and then you closed the window, and then the
-		 * sent you another one, they'd get the auto-response back too
-		 * soon. Besides that, we need to keep track of this even if we've
-		 * got a queue. So the rest of this block is just the auto-response,
-		 * if necessary.
-		 */
-		lar = get_last_auto_response(gc, name);
-		if ((t - lar->sent) < SECS_BEFORE_RESENDING_AUTORESPONSE) {
-			g_free(name);
-			g_free(message);
-			return;
-		}
-		lar->sent = t;
+		status = gaim_presence_get_active_status(presence);
+		if (status != NULL)
+			away_msg = gaim_value_get_string(
+				gaim_status_get_attr_value(status, "message"));
 
-		status = gaim_presence_get_active_status(presence);
-		if (status == NULL)
-			return;
+		if ((away_msg != NULL) && (*away_msg != '\0')) {
+			struct last_auto_response *lar;
+			time_t now = time(NULL);
 
-		away_msg = gaim_value_get_string(
-			gaim_status_get_attr_value(status, "message"));
-
-		if ((away_msg == NULL) || (*away_msg == '\0'))
-			return;
-
-		serv_send_im(gc, name, away_msg, GAIM_MESSAGE_AUTO_RESP);
+			/*
+			 * This used to be based on the conversation window. But um, if
+			 * you went away, and someone sent you a message and got your
+			 * auto-response, and then you closed the window, and then they
+			 * sent you another one, they'd get the auto-response back too
+			 * soon. Besides that, we need to keep track of this even if we've
+			 * got a queue. So the rest of this block is just the auto-response,
+			 * if necessary.
+			 */
+			lar = get_last_auto_response(gc, name);
+			if ((now - lar->sent) >= SECS_BEFORE_RESENDING_AUTORESPONSE)
+			{
+				lar->sent = now;
 
-		gaim_conv_im_write(GAIM_CONV_IM(cnv), NULL, away_msg,
-						   GAIM_MESSAGE_SEND | GAIM_MESSAGE_AUTO_RESP,
-						   mtime);
-	}
-	else
-	{
-		/*
-		 * We're not away. This is easy. If the convo window doesn't
-		 * exist, create and update it (if it does exist it was updated
-		 * earlier), then play a sound indicating we've received it and
-		 * then display it. Easy.
-		 */
+				serv_send_im(gc, name, away_msg, GAIM_MESSAGE_AUTO_RESP);
 
-		if (cnv == NULL)
-			cnv = gaim_conversation_new(GAIM_CONV_TYPE_IM, gc->account, name);
-
-		gaim_conv_im_write(GAIM_CONV_IM(cnv), NULL, message, flags, mtime);
+				gaim_conv_im_write(GAIM_CONV_IM(cnv), NULL, away_msg,
+				                   GAIM_MESSAGE_SEND | GAIM_MESSAGE_AUTO_RESP,
+				                   mtime);
+			}
+		}
 	}
 
 	g_free(name);
-	g_free(message);
 }
 
 void serv_got_typing(GaimConnection *gc, const char *name, int timeout,