pidgin/gtkconv.c

changeset 21339
10db406f5522
parent 20995
a39ea4da4567
parent 21204
93f18311e16a
equal deleted inserted replaced
20996:1a6e2dd87657 21339:10db406f5522
7406 update_chat_topic(PurpleConversation *conv, const char *old, const char *new) 7406 update_chat_topic(PurpleConversation *conv, const char *old, const char *new)
7407 { 7407 {
7408 pidgin_conv_update_fields(conv, PIDGIN_CONV_TOPIC); 7408 pidgin_conv_update_fields(conv, PIDGIN_CONV_TOPIC);
7409 } 7409 }
7410 7410
7411 /* Message history stuff */
7412
7413 /* Compare two PurpleConvMessage's, according to time in ascending order. */
7414 static int
7415 message_compare(gconstpointer p1, gconstpointer p2)
7416 {
7417 const PurpleConvMessage *m1 = p1, *m2 = p2;
7418 return (m1->when > m2->when);
7419 }
7420
7421 /* Adds some message history to the gtkconv. This happens in a idle-callback. */
7411 static gboolean 7422 static gboolean
7412 add_message_history_to_gtkconv(gpointer data) 7423 add_message_history_to_gtkconv(gpointer data)
7413 { 7424 {
7414 PidginConversation *gtkconv = data; 7425 PidginConversation *gtkconv = data;
7415 int count = 0; 7426 int count = 0;
7416 int timer = gtkconv->attach.timer; 7427 int timer = gtkconv->attach.timer;
7417 time_t when = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(gtkconv->entry), "attach-start-time")); 7428 time_t when = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(gtkconv->entry), "attach-start-time"));
7429 gboolean im = (gtkconv->active_conv->type == PURPLE_CONV_TYPE_IM);
7418 7430
7419 gtkconv->attach.timer = 0; 7431 gtkconv->attach.timer = 0;
7420 while (gtkconv->attach.current && count < 100) { /* XXX: 100 is a random value here */ 7432 while (gtkconv->attach.current && count < 100) { /* XXX: 100 is a random value here */
7421 PurpleConvMessage *msg = gtkconv->attach.current->data; 7433 PurpleConvMessage *msg = gtkconv->attach.current->data;
7422 if (when && when < msg->when) { 7434 if (!im && when && when < msg->when) {
7423 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR><HR>", 0); 7435 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR><HR>", 0);
7424 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL); 7436 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL);
7425 } 7437 }
7426 pidgin_conv_write_conv(gtkconv->active_conv, msg->who, msg->who, msg->what, msg->flags, msg->when); 7438 pidgin_conv_write_conv(msg->conv, msg->who, msg->who, msg->what, msg->flags, msg->when);
7427 gtkconv->attach.current = gtkconv->attach.current->prev; 7439 if (im) {
7440 gtkconv->attach.current = g_list_delete_link(gtkconv->attach.current, gtkconv->attach.current);
7441 } else {
7442 gtkconv->attach.current = gtkconv->attach.current->prev;
7443 }
7428 count++; 7444 count++;
7429 } 7445 }
7430 gtkconv->attach.timer = timer; 7446 gtkconv->attach.timer = timer;
7431 if (gtkconv->attach.current) 7447 if (gtkconv->attach.current)
7432 return TRUE; 7448 return TRUE;
7433 7449
7450 g_source_remove(gtkconv->attach.timer);
7451 gtkconv->attach.timer = 0;
7452 if (im) {
7453 /* Print any message that was sent while the old history was being added back. */
7454 GList *msgs = NULL;
7455 GList *iter = gtkconv->convs;
7456 for (; iter; iter = iter->next) {
7457 PurpleConversation *conv = iter->data;
7458 GList *history = purple_conversation_get_message_history(conv);
7459 for (; history; history = history->next) {
7460 PurpleConvMessage *msg = history->data;
7461 if (msg->when > when)
7462 msgs = g_list_prepend(msgs, msg);
7463 }
7464 }
7465 msgs = g_list_sort(msgs, message_compare);
7466 for (; msgs; msgs = g_list_delete_link(msgs, msgs)) {
7467 PurpleConvMessage *msg = msgs->data;
7468 pidgin_conv_write_conv(msg->conv, msg->who, msg->who, msg->what, msg->flags, msg->when);
7469 }
7470 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR><HR>", 0);
7471 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL);
7472 }
7473
7434 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL); 7474 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL);
7435 purple_signal_emit(pidgin_conversations_get_handle(), 7475 purple_signal_emit(pidgin_conversations_get_handle(),
7436 "conversation-displayed", gtkconv); 7476 "conversation-displayed", gtkconv);
7437 g_source_remove(gtkconv->attach.timer);
7438 gtkconv->attach.timer = 0;
7439 return FALSE; 7477 return FALSE;
7440 } 7478 }
7441 7479
7442 gboolean pidgin_conv_attach_to_conversation(PurpleConversation *conv) 7480 static void
7443 { 7481 pidgin_conv_attach(PurpleConversation *conv)
7444 GList *list; 7482 {
7445 PidginConversation *gtkconv;
7446 int timer; 7483 int timer;
7447
7448 if (PIDGIN_IS_PIDGIN_CONVERSATION(conv))
7449 return FALSE;
7450
7451 purple_conversation_set_data(conv, "unseen-count", NULL); 7484 purple_conversation_set_data(conv, "unseen-count", NULL);
7452 purple_conversation_set_ui_ops(conv, pidgin_conversations_get_conv_ui_ops()); 7485 purple_conversation_set_ui_ops(conv, pidgin_conversations_get_conv_ui_ops());
7453 private_gtkconv_new(conv, FALSE); 7486 private_gtkconv_new(conv, FALSE);
7487 timer = GPOINTER_TO_INT(purple_conversation_get_data(conv, "close-timer"));
7488 if (timer)
7489 purple_timeout_remove(timer);
7490 }
7491
7492 gboolean pidgin_conv_attach_to_conversation(PurpleConversation *conv)
7493 {
7494 GList *list;
7495 PidginConversation *gtkconv;
7496
7497 if (PIDGIN_IS_PIDGIN_CONVERSATION(conv))
7498 return FALSE;
7499
7500 pidgin_conv_attach(conv);
7454 gtkconv = PIDGIN_CONVERSATION(conv); 7501 gtkconv = PIDGIN_CONVERSATION(conv);
7455 7502
7456 list = purple_conversation_get_message_history(conv); 7503 list = purple_conversation_get_message_history(conv);
7457 if (list) { 7504 if (list) {
7505 switch (purple_conversation_get_type(conv)) {
7506 case PURPLE_CONV_TYPE_IM:
7507 {
7508 GList *convs;
7509 list = g_list_copy(list);
7510 for (convs = purple_get_ims(); convs; convs = convs->next)
7511 if (convs->data != conv &&
7512 pidgin_conv_find_gtkconv(convs->data) == gtkconv) {
7513 pidgin_conv_attach(convs->data);
7514 list = g_list_concat(list, g_list_copy(purple_conversation_get_message_history(convs->data)));
7515 }
7516 list = g_list_sort(list, message_compare);
7517 gtkconv->attach.current = list;
7518 list = g_list_last(list);
7519 break;
7520 }
7521 case PURPLE_CONV_TYPE_CHAT:
7522 gtkconv->attach.current = g_list_last(list);
7523 break;
7524 default:
7525 g_return_val_if_reached(TRUE);
7526 }
7458 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", 7527 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time",
7459 GINT_TO_POINTER(((PurpleConvMessage*)(list->data))->when)); 7528 GINT_TO_POINTER(((PurpleConvMessage*)(list->data))->when));
7460 gtkconv->attach.current = g_list_last(list);
7461 gtkconv->attach.timer = g_idle_add(add_message_history_to_gtkconv, gtkconv); 7529 gtkconv->attach.timer = g_idle_add(add_message_history_to_gtkconv, gtkconv);
7462 } else { 7530 } else {
7463 purple_signal_emit(pidgin_conversations_get_handle(), 7531 purple_signal_emit(pidgin_conversations_get_handle(),
7464 "conversation-displayed", gtkconv); 7532 "conversation-displayed", gtkconv);
7465 } 7533 }
7467 if (conv->type == PURPLE_CONV_TYPE_CHAT) { 7535 if (conv->type == PURPLE_CONV_TYPE_CHAT) {
7468 pidgin_conv_update_fields(conv, PIDGIN_CONV_TOPIC); 7536 pidgin_conv_update_fields(conv, PIDGIN_CONV_TOPIC);
7469 pidgin_conv_chat_add_users(conv, PURPLE_CONV_CHAT(conv)->in_room, TRUE); 7537 pidgin_conv_chat_add_users(conv, PURPLE_CONV_CHAT(conv)->in_room, TRUE);
7470 } 7538 }
7471 7539
7472 timer = GPOINTER_TO_INT(purple_conversation_get_data(conv, "close-timer"));
7473 if (timer)
7474 purple_timeout_remove(timer);
7475 return TRUE; 7540 return TRUE;
7476 } 7541 }
7477 7542
7478 void * 7543 void *
7479 pidgin_conversations_get_handle(void) 7544 pidgin_conversations_get_handle(void)
9800 } 9865 }
9801 9866
9802 return colors; 9867 return colors;
9803 } 9868 }
9804 9869
9870

mercurial