Index: protocols/twitter/twitter_lib.c
===================================================================
--- protocols/twitter/twitter_lib.c	(revision bb8d7d1106ce91c54c671a1495420d57b9a57caf)
+++ protocols/twitter/twitter_lib.c	(revision ce81acd6242513c5fcf6cf2224f9b1137701e14e)
@@ -67,5 +67,5 @@
 	char *text;
 	struct twitter_xml_user *user;
-	guint64 id;
+	guint64 id, reply_to;
 };
 
@@ -409,4 +409,8 @@
 		{
 			txs->id = g_ascii_strtoull (child->text, NULL, 10);
+		}
+		else if (g_strcasecmp( "in_reply_to_status_id", child->name ) == 0)
+		{
+			txs->reply_to = g_ascii_strtoull (child->text, NULL, 10);
 		}
 	}
@@ -502,4 +506,39 @@
 }
 
+static char *twitter_msg_add_id(struct im_connection *ic,
+    struct twitter_xml_status *txs, const char *prefix)
+{
+	struct twitter_data *td = ic->proto_data;
+	char *ret = NULL;
+	
+	if (!set_getbool(&ic->acc->set, "show_ids"))
+	{
+		if (*prefix)
+			return g_strconcat(prefix, txs->text, NULL);
+		else
+			return NULL;
+	}
+	
+	td->log[td->log_id].id = txs->id;
+	td->log[td->log_id].bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name);
+	if (txs->reply_to)
+	{
+		int i;
+		for (i = 0; i < TWITTER_LOG_LENGTH; i ++)
+			if (td->log[i].id == txs->reply_to)
+			{
+				ret = g_strdup_printf( "\002[\002%02d->%02d\002]\002 %s%s",
+				                       td->log_id, i, prefix, txs->text);
+				break;
+			}
+	}
+	if (ret == NULL)
+		ret = g_strdup_printf( "\002[\002%02d\002]\002 %s%s",
+		                       td->log_id, prefix, txs->text);
+	td->log_id = (td->log_id + 1) % TWITTER_LOG_LENGTH;
+	
+	return ret;
+}
+
 static void twitter_groupchat_init(struct im_connection *ic)
 {
@@ -543,4 +582,6 @@
 	for ( l = list; l ; l = g_slist_next(l) )
 	{
+		char *msg;
+		
 		status = l->data;
 		if (status->user == NULL || status->text == NULL)
@@ -550,14 +591,18 @@
 		
 		strip_html(status->text);
+		msg = twitter_msg_add_id(ic, status, "");
 		
 		// Say it!
 		if (g_strcasecmp(td->user, status->user->screen_name) == 0)
-			imcb_chat_log (gc, "You: %s", status->text);
+			imcb_chat_log(gc, "You: %s", msg ? msg : status->text);
 		else
-			imcb_chat_msg (gc, status->user->screen_name, status->text, 0, status->created_at );
+			imcb_chat_msg(gc, status->user->screen_name,
+			              msg ? msg : status->text, 0, status->created_at );
+		
+		g_free(msg);
 		
 		// Update the home_timeline_id to hold the highest id, so that by the next request
-		// we won't pick up the updates allready in the list.
-		td->home_timeline_id = td->home_timeline_id < status->id ? status->id : td->home_timeline_id;
+		// we won't pick up the updates already in the list.
+		td->home_timeline_id = MAX(td->home_timeline_id, status->id);
 	}
 }
@@ -584,5 +629,5 @@
 	for ( l = list; l ; l = g_slist_next(l) )
 	{
-		char *text = NULL;
+		char *prefix = NULL, *text = NULL;
 		
 		status = l->data;
@@ -590,19 +635,22 @@
 		strip_html( status->text );
 		if( mode_one )
-			text = g_strdup_printf( "\002<\002%s\002>\002 %s",
-			                        status->user->screen_name, status->text );
+			prefix = g_strdup_printf("\002<\002%s\002>\002 ",
+			                         status->user->screen_name);
 		else
 			twitter_add_buddy(ic, status->user->screen_name, status->user->name);
 		
+		text = twitter_msg_add_id(ic, status, prefix ? prefix : "");
+		
 		imcb_buddy_msg( ic,
 		                mode_one ? from : status->user->screen_name,
-		                mode_one ? text : status->text,
+		                text ? text : status->text,
 		                0, status->created_at );
 		
 		// Update the home_timeline_id to hold the highest id, so that by the next request
-		// we won't pick up the updates allready in the list.
-		td->home_timeline_id = td->home_timeline_id < status->id ? status->id : td->home_timeline_id;
+		// we won't pick up the updates already in the list.
+		td->home_timeline_id = MAX(td->home_timeline_id,  status->id);
 		
 		g_free( text );
+		g_free( prefix );
 	}
 }
