changeset 17072:cb4380df3005

In MSN we fake sending messages to yourself. This had a small bug in that the received message would show up *before* the sent message. This fixes that so that when talking to yourself messages appear in the correct order. I was discussing this with Stu and he said it was a rather silly thing to worry about, but I disagree with him.
author Stu Tomlinson <stu@nosnilmot.com>
date Sat, 12 May 2007 17:38:04 +0000
parents f1547260a11e
children 2649c2ffc0d4 522f618a44b4
files libpurple/protocols/msn/msn.c
diffstat 1 files changed, 26 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/msn.c	Sat May 12 14:28:59 2007 +0000
+++ b/libpurple/protocols/msn/msn.c	Sat May 12 17:38:04 2007 +0000
@@ -73,6 +73,15 @@
 
 } MsnGetInfoStepTwoData;
 
+typedef struct
+{
+	PurpleConnection *gc;
+	const char *who;
+	char *msg;
+	PurpleMessageFlags flags;
+	time_t when;
+} MsnIMData;
+
 static const char *
 msn_normalize(const PurpleAccount *account, const char *str)
 {
@@ -727,6 +736,16 @@
 	gc->proto_data = NULL;
 }
 
+static gboolean
+msn_send_me_im(gpointer data)
+{
+	MsnIMData *imdata = data;
+	serv_got_im(imdata->gc, imdata->who, imdata->msg, imdata->flags, imdata->when);
+	g_free(imdata->msg);
+	g_free(imdata);
+	return FALSE;
+}
+
 static int
 msn_send_im(PurpleConnection *gc, const char *who, const char *message,
 			PurpleMessageFlags flags)
@@ -779,6 +798,7 @@
 	{
 		char *body_str, *body_enc, *pre, *post;
 		const char *format;
+		MsnIMData *imdata = g_new0(MsnIMData, 1);
 		/*
 		 * In MSN, you can't send messages to yourself, so
 		 * we'll fake like we received it ;)
@@ -796,8 +816,12 @@
 		g_free(post);
 
 		serv_got_typing_stopped(gc, who);
-		serv_got_im(gc, who, body_str, flags, time(NULL));
-		g_free(body_str);
+		imdata->gc = gc;
+		imdata->who = who;
+		imdata->msg = body_str;
+		imdata->flags = flags;
+		imdata->when = time(NULL);
+		g_idle_add(msn_send_me_im, imdata);
 	}
 
 	msn_message_destroy(msg);