diff --git a/tgp-chat.c b/tgp-chat.c index 910973e..5ecaa40 100644 --- a/tgp-chat.c +++ b/tgp-chat.c @@ -100,23 +100,26 @@ static void tgp_chat_add_all_users (struct tgl_state *TLS, PurpleConversation *c g_list_free (flags); } -void tgp_chat_users_update (struct tgl_state *TLS, struct tgl_chat *C) { - PurpleConversation *pc = purple_find_chat (tls_get_conn (TLS), tgl_get_peer_id (C->id)); - if (pc) { - purple_conv_chat_clear_users (purple_conversation_get_chat_data (pc)); - tgp_chat_add_all_users (TLS, pc, C); - } -} - PurpleConversation *tgp_chat_show (struct tgl_state *TLS, struct tgl_chat *C) { - PurpleConversation *convo = purple_find_chat (tls_get_conn (TLS), tgl_get_peer_id (C->id)); - PurpleConvChat *chat = purple_conversation_get_chat_data (convo); + PurpleConvChat *chat = NULL; - if (! convo || (chat && purple_conv_chat_has_left (chat))) { - convo = serv_got_joined_chat (tls_get_conn (TLS), tgl_get_peer_id (C->id), C->print_title); - tgp_chat_users_update (TLS, C); + // check if chat is already shown + PurpleConversation *conv = purple_find_chat (tls_get_conn (TLS), tgl_get_peer_id (C->id)); + if (conv) { + chat = purple_conversation_get_chat_data (conv); + if (chat && ! purple_conv_chat_has_left (chat)) { + return conv; + } } - return convo; + + // join the chat now + conv = serv_got_joined_chat (tls_get_conn (TLS), tgl_get_peer_id (C->id), C->print_title); + g_return_val_if_fail(conv, NULL); + + purple_conv_chat_clear_users (purple_conversation_get_chat_data (conv)); + tgp_chat_add_all_users (TLS, conv, C); + + return conv; } GList *tgprpl_chat_join_info (PurpleConnection * gc) { diff --git a/tgp-chat.h b/tgp-chat.h index 4171189..cb9f4d3 100644 --- a/tgp-chat.h +++ b/tgp-chat.h @@ -30,7 +30,6 @@ int tgp_chat_has_id (PurpleChat *C); void tgp_chat_on_loaded_chat_full (struct tgl_state *TLS, struct tgl_chat *C); PurpleConversation *tgp_chat_show (struct tgl_state *TLS, struct tgl_chat *C); -void tgp_chat_users_update (struct tgl_state *TLS, struct tgl_chat *C); char *tgprpl_get_chat_name (GHashTable *data); void tgprpl_chat_join (PurpleConnection *gc, GHashTable *data);