| 8079 /* Compare two PurpleConvMessage's, according to time in ascending order. */ |
8079 /* Compare two PurpleConvMessage's, according to time in ascending order. */ |
| 8080 static int |
8080 static int |
| 8081 message_compare(gconstpointer p1, gconstpointer p2) |
8081 message_compare(gconstpointer p1, gconstpointer p2) |
| 8082 { |
8082 { |
| 8083 const PurpleConvMessage *m1 = p1, *m2 = p2; |
8083 const PurpleConvMessage *m1 = p1, *m2 = p2; |
| 8084 return (m1->when > m2->when); |
8084 return (purple_conversation_message_get_timestamp(m1) > purple_conversation_message_get_timestamp(m2)); |
| 8085 } |
8085 } |
| 8086 |
8086 |
| 8087 /* Adds some message history to the gtkconv. This happens in a idle-callback. */ |
8087 /* Adds some message history to the gtkconv. This happens in a idle-callback. */ |
| 8088 static gboolean |
8088 static gboolean |
| 8089 add_message_history_to_gtkconv(gpointer data) |
8089 add_message_history_to_gtkconv(gpointer data) |
| 8095 gboolean im = (purple_conversation_get_type(gtkconv->active_conv) == PURPLE_CONV_TYPE_IM); |
8095 gboolean im = (purple_conversation_get_type(gtkconv->active_conv) == PURPLE_CONV_TYPE_IM); |
| 8096 |
8096 |
| 8097 gtkconv->attach.timer = 0; |
8097 gtkconv->attach.timer = 0; |
| 8098 while (gtkconv->attach.current && count < 100) { /* XXX: 100 is a random value here */ |
8098 while (gtkconv->attach.current && count < 100) { /* XXX: 100 is a random value here */ |
| 8099 PurpleConvMessage *msg = gtkconv->attach.current->data; |
8099 PurpleConvMessage *msg = gtkconv->attach.current->data; |
| 8100 if (!im && when && when < msg->when) { |
8100 if (!im && when && when < purple_conversation_message_get_timestamp(msg)) { |
| 8101 gtk_webview_append_html(GTK_WEBVIEW(gtkconv->webview), "<BR><HR>"); |
8101 gtk_webview_append_html(GTK_WEBVIEW(gtkconv->webview), "<BR><HR>"); |
| 8102 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL); |
8102 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL); |
| 8103 } |
8103 } |
| 8104 pidgin_conv_write_conv(msg->conv, msg->who, msg->alias, msg->what, msg->flags, msg->when); |
8104 pidgin_conv_write_conv( |
| |
8105 purple_conversation_message_get_conv(msg), |
| |
8106 purple_conversation_message_get_sender(msg), |
| |
8107 purple_conversation_message_get_alias(msg), |
| |
8108 purple_conversation_message_get_message(msg), |
| |
8109 purple_conversation_message_get_flags(msg), |
| |
8110 purple_conversation_message_get_timestamp(msg)); |
| 8105 if (im) { |
8111 if (im) { |
| 8106 gtkconv->attach.current = g_list_delete_link(gtkconv->attach.current, gtkconv->attach.current); |
8112 gtkconv->attach.current = g_list_delete_link(gtkconv->attach.current, gtkconv->attach.current); |
| 8107 } else { |
8113 } else { |
| 8108 gtkconv->attach.current = gtkconv->attach.current->prev; |
8114 gtkconv->attach.current = gtkconv->attach.current->prev; |
| 8109 } |
8115 } |
| 8122 for (; iter; iter = iter->next) { |
8128 for (; iter; iter = iter->next) { |
| 8123 PurpleConversation *conv = iter->data; |
8129 PurpleConversation *conv = iter->data; |
| 8124 GList *history = purple_conversation_get_message_history(conv); |
8130 GList *history = purple_conversation_get_message_history(conv); |
| 8125 for (; history; history = history->next) { |
8131 for (; history; history = history->next) { |
| 8126 PurpleConvMessage *msg = history->data; |
8132 PurpleConvMessage *msg = history->data; |
| 8127 if (msg->when > when) |
8133 if (purple_conversation_message_get_timestamp(msg) > when) |
| 8128 msgs = g_list_prepend(msgs, msg); |
8134 msgs = g_list_prepend(msgs, msg); |
| 8129 } |
8135 } |
| 8130 } |
8136 } |
| 8131 msgs = g_list_sort(msgs, message_compare); |
8137 msgs = g_list_sort(msgs, message_compare); |
| 8132 for (; msgs; msgs = g_list_delete_link(msgs, msgs)) { |
8138 for (; msgs; msgs = g_list_delete_link(msgs, msgs)) { |
| 8133 PurpleConvMessage *msg = msgs->data; |
8139 PurpleConvMessage *msg = msgs->data; |
| 8134 pidgin_conv_write_conv(msg->conv, msg->who, msg->alias, msg->what, msg->flags, msg->when); |
8140 pidgin_conv_write_conv( |
| |
8141 purple_conversation_message_get_conv(msg), |
| |
8142 purple_conversation_message_get_sender(msg), |
| |
8143 purple_conversation_message_get_alias(msg), |
| |
8144 purple_conversation_message_get_message(msg), |
| |
8145 purple_conversation_message_get_flags(msg), |
| |
8146 purple_conversation_message_get_timestamp(msg)); |
| 8135 } |
8147 } |
| 8136 gtk_webview_append_html(GTK_WEBVIEW(gtkconv->webview), "<BR><HR>"); |
8148 gtk_webview_append_html(GTK_WEBVIEW(gtkconv->webview), "<BR><HR>"); |
| 8137 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL); |
8149 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL); |
| 8138 } |
8150 } |
| 8139 |
8151 |
| 8207 break; |
8219 break; |
| 8208 default: |
8220 default: |
| 8209 g_return_val_if_reached(TRUE); |
8221 g_return_val_if_reached(TRUE); |
| 8210 } |
8222 } |
| 8211 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", |
8223 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", |
| 8212 GINT_TO_POINTER(((PurpleConvMessage*)(list->data))->when)); |
8224 GINT_TO_POINTER(purple_conversation_message_get_timestamp((PurpleConvMessage*)(list->data)))); |
| 8213 gtkconv->attach.timer = g_idle_add(add_message_history_to_gtkconv, gtkconv); |
8225 gtkconv->attach.timer = g_idle_add(add_message_history_to_gtkconv, gtkconv); |
| 8214 } else { |
8226 } else { |
| 8215 purple_signal_emit(pidgin_conversations_get_handle(), |
8227 purple_signal_emit(pidgin_conversations_get_handle(), |
| 8216 "conversation-displayed", gtkconv); |
8228 "conversation-displayed", gtkconv); |
| 8217 } |
8229 } |