diff --git a/src/chatty-mm-chat.c b/src/chatty-mm-chat.c index 4e0b7b13bba613118014dd9062a35db581ab8e11..f4be53b76ddfacdcaed49aedc2940cb2a7e85ec4 100644 --- a/src/chatty-mm-chat.c +++ b/src/chatty-mm-chat.c @@ -687,3 +687,38 @@ chatty_mm_chat_show_notification (ChattyMmChat *self) if (g_set_object (&self->last_notify_message, message)) chatty_notification_show_message (self->notification, chat, message, NULL); } + +/* + * In the past, we were not storing thread members in db, + * which was fixed in b5d4f448ecdfef3189d794c2c136ed869e48f59f + * but the chats created before the fix had empty members, + * Let's work around by adding the members if that's the case + */ +void +chatty_mm_chat_refresh (ChattyMmChat *self) +{ + g_autoptr(ChattyMmBuddy) buddy = NULL; + g_autofree char *number = NULL; + ChattySettings *settings; + const char *name, *country; + + g_return_if_fail (CHATTY_IS_MM_CHAT (self)); + + if (g_list_model_get_n_items (G_LIST_MODEL (self->chat_users)) > 0) + return; + + settings = chatty_settings_get_default (); + country = chatty_settings_get_country_iso_code (settings); + name = chatty_chat_get_chat_name (CHATTY_CHAT (self)); + + if (country) + number = chatty_utils_check_phonenumber (name, country); + if (!number) + number = g_strdup (name); + + CHATTY_DEBUG (number, "Updating chat member in db, number:"); + + buddy = chatty_mm_buddy_new (number, chatty_item_get_name (CHATTY_ITEM (self))); + chatty_mm_chat_add_user (self, buddy); + chatty_history_update_chat (self->history_db, CHATTY_CHAT (self)); +} diff --git a/src/chatty-mm-chat.h b/src/chatty-mm-chat.h index 549e36e6e5375aa5f5a687b973e77b4d0632fb2f..0f57ab288a6ffa646264fde9daf14be922456331 100644 --- a/src/chatty-mm-chat.h +++ b/src/chatty-mm-chat.h @@ -48,5 +48,6 @@ void chatty_mm_chat_add_users (ChattyMmChat *self, GPtrArray *users); void chatty_mm_chat_delete (ChattyMmChat *self); void chatty_mm_chat_show_notification (ChattyMmChat *self); +void chatty_mm_chat_refresh (ChattyMmChat *self); G_END_DECLS diff --git a/src/users/chatty-mm-account.c b/src/users/chatty-mm-account.c index ea9c1371f29d15b01b8e7aa432d19c0f2bd78c12..0595b64e964655aa50391ef6cb266763844b92ac 100644 --- a/src/users/chatty-mm-account.c +++ b/src/users/chatty-mm-account.c @@ -506,8 +506,10 @@ mm_object_added_cb (ChattyMmAccount *self, { g_autoptr(ChattyMmAccount) account = NULL; g_autoptr(ChattyMmDevice) device = NULL; + GListModel *chat_list; MessagingData *data; MMSim *sim; + guint n_chats; g_assert (CHATTY_IS_MM_ACCOUNT (self)); g_assert (MM_IS_OBJECT (object)); @@ -542,6 +544,15 @@ mm_object_added_cb (ChattyMmAccount *self, chatty_settings_set_country_iso_code (settings, code); } + chat_list = chatty_mm_account_get_chat_list (self); + n_chats = g_list_model_get_n_items (chat_list); + for (guint i = 0; i < n_chats; i++) { + g_autoptr(ChattyMmChat) chat = NULL; + + chat = g_list_model_get_item (chat_list, i); + chatty_mm_chat_refresh (chat); + } + g_signal_connect_swapped (mm_object_peek_modem_messaging (MM_OBJECT (object)), "added", G_CALLBACK (mm_account_sms_recieved_cb), self);