diff --git a/telegram-purple.c b/telegram-purple.c index 6539f58..2c36508 100644 --- a/telegram-purple.c +++ b/telegram-purple.c @@ -226,6 +226,9 @@ static void update_chat_handler (struct tgl_state *TLS, struct tgl_chat *chat, u } static void update_user_typing (struct tgl_state *TLS, struct tgl_user *U, enum tgl_typing_status status) { + + g_return_if_fail (tgp_blist_peer_get_purple_name (TLS, U->id)); + if (status == tgl_typing_typing) { serv_got_typing (tg_get_conn(TLS), tgp_blist_peer_get_purple_name (TLS, U->id), 2, PURPLE_TYPING); } diff --git a/tgp-2prpl.c b/tgp-2prpl.c index 6797617..5f96407 100644 --- a/tgp-2prpl.c +++ b/tgp-2prpl.c @@ -163,7 +163,12 @@ tgl_chat_id_t p2tgl_chat_get_id (PurpleChat *PC) { void p2tgl_conv_add_user (struct tgl_state *TLS, PurpleConversation *conv, int user, char *message, int flags, int new_arrival) { - purple_conv_chat_add_user (purple_conversation_get_chat_data (conv), tgp_blist_peer_get_purple_name (TLS, TGL_MK_USER (user)), message, flags, new_arrival); + + const char *name = tgp_blist_peer_get_purple_name (TLS, TGL_MK_USER (user)); + + g_return_if_fail (name); + + purple_conv_chat_add_user (purple_conversation_get_chat_data (conv), name, message, flags, new_arrival); } PurpleNotifyUserInfo *p2tgl_notify_user_info_new (struct tgl_user *U) { diff --git a/tgp-blist.c b/tgp-blist.c index 02acf0d..a8e049a 100644 --- a/tgp-blist.c +++ b/tgp-blist.c @@ -27,16 +27,14 @@ const char *tgp_blist_peer_get_purple_name (struct tgl_state *TLS, tgl_peer_id_t id) { const char *name = g_hash_table_lookup (tg_get_data (TLS)->id_to_purple_name, GINT_TO_POINTER(tgl_get_peer_id (id))); if (! name) { - assert (0); + g_warn_if_reached(); return NULL; } return name; } void tgp_blist_peer_add_purple_name (struct tgl_state *TLS, tgl_peer_id_t id, const char *purple_name) { - assert (g_hash_table_lookup (tg_get_data (TLS)->id_to_purple_name, GINT_TO_POINTER(tgl_get_peer_id (id))) == NULL); - g_hash_table_insert (tg_get_data (TLS)->id_to_purple_name, GINT_TO_POINTER(tgl_get_peer_id (id)), - g_strdup (purple_name)); + g_hash_table_replace (tg_get_data (TLS)->id_to_purple_name, GINT_TO_POINTER(tgl_get_peer_id (id)), g_strdup (purple_name)); } tgl_peer_t *tgp_blist_peer_find (struct tgl_state *TLS, const char *purple_name) { diff --git a/tgp-chat.c b/tgp-chat.c index bd1a245..0073d0a 100644 --- a/tgp-chat.c +++ b/tgp-chat.c @@ -88,7 +88,12 @@ static void tgp_chat_add_all_users (struct tgl_state *TLS, PurpleConversation *c int i = 0; for (; i < C->user_list_size; i++) { struct tgl_chat_user *uid = (C->user_list + i); - users = g_list_append (users, g_strdup (tgp_blist_peer_get_purple_name (TLS, TGL_MK_USER(uid->user_id)))); + const char *name = tgp_blist_peer_get_purple_name (TLS, TGL_MK_USER(uid->user_id)); + if (! name) { + g_warn_if_reached(); + continue; + } + users = g_list_append (users, g_strdup (name)); flags = g_list_append (flags, GINT_TO_POINTER(C->admin_id == uid->user_id ? PURPLE_CBFLAGS_FOUNDER : PURPLE_CBFLAGS_NONE)); } purple_conv_chat_add_users (PURPLE_CONV_CHAT(conv), users, NULL, flags, FALSE); diff --git a/tgp-ft.c b/tgp-ft.c index 05cbfce..8b064f6 100644 --- a/tgp-ft.c +++ b/tgp-ft.c @@ -271,8 +271,11 @@ static PurpleXfer *tgprpl_new_xfer_recv (PurpleConnection * gc, const char *who) return X; } -void tgprpl_recv_file (PurpleConnection * gc, const char *who, struct tgl_message *M) { +void tgprpl_recv_file (PurpleConnection *gc, const char *who, struct tgl_message *M) { debug ("tgprpl_recv_file()"); + + g_return_if_fail (who); + PurpleXfer *X = tgprpl_new_xfer_recv (gc, who); const char *mime_type, *caption; long long access_hash; diff --git a/tgp-msg.c b/tgp-msg.c index 450827a..77ea40a 100644 --- a/tgp-msg.c +++ b/tgp-msg.c @@ -101,10 +101,13 @@ static char *format_service_msg (struct tgl_state *TLS, struct tgl_message *M) { PurpleConversation *conv = tgp_chat_show (TLS, &chatPeer->chat); if (conv) { char *alias = peer->print_name; + const char *aliasLeft = tgp_blist_peer_get_purple_name (TLS, TGL_MK_USER (M->action.user)); + txt = g_strdup_printf (_("%1$s deleted user %2$s."), txt_user, alias); - purple_conv_chat_remove_user (purple_conversation_get_chat_data (conv), - tgp_blist_peer_get_purple_name (TLS, TGL_MK_USER (M->action.user)), txt); + g_return_val_if_fail (aliasLeft, txt); + + purple_conv_chat_remove_user (purple_conversation_get_chat_data (conv), aliasLeft, txt); if (M->action.user == tgl_get_peer_id (TLS->our_id)) { purple_conv_chat_left (purple_conversation_get_chat_data (conv)); } @@ -243,6 +246,9 @@ void tgp_msg_sys_out (struct tgl_state *TLS, const char *msg, tgl_peer_id_t to_i case TGL_PEER_ENCR_CHAT: { const char *name = tgp_blist_peer_get_purple_name (TLS, to_id); PurpleConversation *conv = p2tgl_find_conversation_with_account (TLS, to_id); + + g_return_if_fail (name); + if (! conv) { conv = purple_conversation_new (PURPLE_CONV_TYPE_IM, tg_get_acc (TLS), name); } @@ -357,6 +363,9 @@ static char *tgp_msg_sticker_display (struct tgl_state *TLS, tgl_peer_id_t from, *flags |= PURPLE_MESSAGE_IMAGES; #else const char *txt_user = tgp_blist_peer_get_purple_name (TLS, from); + + g_return_val_if_fail (txt_user, NULL); + text = g_strdup_printf (_("%s sent a sticker."), txt_user); *flags |= PURPLE_MESSAGE_SYSTEM; #endif