2
0
mirror of https://github.com/ars3niy/tdlib-purple synced 2025-08-31 05:55:08 +00:00

Set correct conversation title when receiving group message at login

This commit is contained in:
Arseniy Lartsev
2020-05-16 19:25:01 +02:00
parent 44fd083947
commit b76dab25f4
7 changed files with 63 additions and 13 deletions

View File

@@ -90,16 +90,23 @@ PurpleConvChat *getChatConversation(PurpleAccount *account, const td::td_api::ch
if (chatPurpleId != 0) {
purple_debug_misc(config::pluginId, "Creating conversation for chat %s (purple id %d)\n",
chat.title_.c_str(), chatPurpleId);
// TODO: when a message arrives during login, libpurple won't find the chat in contact
// when a message arrives during login, libpurple won't find the chat in contact
// list because even it has been in the contact list since before, the chat lookup
// doesn't work when account is not connected. Therefore, it won't know chat title and
// will show chatXXXXXXXXXXX name in the conversation window instead. How to fix this?
// would show chatXXXXXXXXXXX name in the conversation window instead.
serv_got_joined_chat(purple_account_get_connection(account), chatPurpleId, chatName.c_str());
conv = purple_find_chat(purple_account_get_connection(account), chatPurpleId);
if (conv == NULL)
purple_debug_warning(config::pluginId, "Did not create conversation for chat %s\n", chat.title_.c_str());
else
else {
//... so, fix conversation title if we can't find chat in contact list
PurpleChat *purpleChat = purple_blist_find_chat(account, chatName.c_str());
if (!purpleChat) {
purple_debug_misc(config::pluginId, "Setting conversation title to '%s'\n", chat.title_.c_str());
purple_conversation_set_title(conv, chat.title_.c_str());
}
newChatCreated = true;
}
} else
purple_debug_warning(config::pluginId, "No internal ID for chat %s\n", chat.title_.c_str());
@@ -121,6 +128,23 @@ PurpleConvChat *getChatConversation(PurpleAccount *account, const td::td_api::ch
return NULL;
}
PurpleConvChat *findChatConversation(PurpleAccount *account, const td::td_api::chat &chat)
{
std::string name = getChatName(chat);
PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT,
name.c_str(), account);
if (conv)
return purple_conversation_get_chat_data(conv);
return NULL;
}
void updateChatConversationTitle(PurpleAccount *account, const td::td_api::chat &chat)
{
PurpleConvChat *purpleChat = findChatConversation(account, chat);
if (purpleChat)
purple_conversation_set_title(purple_conv_chat_get_conversation(purpleChat), chat.title_.c_str());
}
static void showMessageTextIm(PurpleAccount *account, const char *purpleUserName, const char *text,
const char *notification, time_t timestamp, PurpleMessageFlags flags)
{