eion/purple-hangouts

Parents 5514b3e6fb63
Children 3540449f4317
Remove conversation from buddy list when archiving/deleting in another client
--- a/hangouts_events.c Fri May 06 00:35:01 2016 +1200
+++ b/hangouts_events.c Sat May 07 11:16:30 2016 +1200
@@ -41,6 +41,8 @@
purple_signal_connect(plugin, "hangouts-received-stateupdate", plugin, PURPLE_CALLBACK(hangouts_received_presence_notification), NULL);
purple_signal_connect(plugin, "hangouts-received-stateupdate", plugin, PURPLE_CALLBACK(hangouts_received_watermark_notification), NULL);
purple_signal_connect(plugin, "hangouts-received-stateupdate", plugin, PURPLE_CALLBACK(hangouts_received_state_update), NULL);
+ purple_signal_connect(plugin, "hangouts-received-stateupdate", plugin, PURPLE_CALLBACK(hangouts_received_view_modification), NULL);
+ purple_signal_connect(plugin, "hangouts-received-stateupdate", plugin, PURPLE_CALLBACK(hangouts_received_delete_notification), NULL);
purple_signal_connect(plugin, "hangouts-received-stateupdate", plugin, PURPLE_CALLBACK(hangouts_received_block_notification), NULL);
purple_signal_connect(plugin, "hangouts-received-stateupdate", plugin, PURPLE_CALLBACK(hangouts_received_other_notification), NULL);
}
@@ -84,6 +86,65 @@
}
}
+static void
+hangouts_remove_conversation(HangoutsAccount *ha, const gchar *conv_id)
+{
+ if (g_hash_table_contains(ha->one_to_ones, conv_id)) {
+ const gchar *buddy_id = g_hash_table_lookup(ha->one_to_ones, conv_id);
+ PurpleBuddy *buddy = purple_blist_find_buddy(ha->account, buddy_id);
+
+ purple_blist_remove_buddy(buddy);
+ g_hash_table_remove(ha->one_to_ones, conv_id);
+ g_hash_table_remove(ha->one_to_ones_rev, buddy_id);
+
+ } else if (g_hash_table_contains(ha->group_chats, conv_id)) {
+ PurpleChat *chat = purple_blist_find_chat(ha->account, conv_id);
+ purple_blist_remove_chat(chat);
+
+ g_hash_table_remove(ha->group_chats, conv_id);
+
+ } else {
+ // Unknown conversation!
+ return;
+ }
+}
+
+void
+hangouts_received_view_modification(PurpleConnection *pc, StateUpdate *state_update)
+{
+ HangoutsAccount *ha;
+ ConversationViewModification *view_modification = state_update->view_modification;
+ const gchar *conv_id;
+
+ if (view_modification == NULL) {
+ return;
+ }
+
+ if (view_modification->new_view == CONVERSATION_VIEW__CONVERSATION_VIEW_ARCHIVED) {
+ ha = purple_connection_get_protocol_data(pc);
+ conv_id = view_modification->conversation_id->id;
+
+ hangouts_remove_conversation(ha, conv_id);
+ }
+}
+
+void
+hangouts_received_delete_notification(PurpleConnection *pc, StateUpdate *state_update)
+{
+ HangoutsAccount *ha;
+ DeleteActionNotification *delete_notification = state_update->delete_notification;
+ const gchar *conv_id;
+
+ if (delete_notification == NULL) {
+ return;
+ }
+
+ ha = purple_connection_get_protocol_data(pc);
+ conv_id = delete_notification->conversation_id->id;
+
+ hangouts_remove_conversation(ha, conv_id);
+}
+
void
hangouts_received_block_notification(PurpleConnection *pc, StateUpdate *state_update)
{
--- a/hangouts_events.h Fri May 06 00:35:01 2016 +1200
+++ b/hangouts_events.h Sat May 07 11:16:30 2016 +1200
@@ -31,6 +31,8 @@
void hangouts_received_typing_notification(PurpleConnection *pc, StateUpdate *state_update);
void hangouts_received_watermark_notification(PurpleConnection *pc, StateUpdate *state_update);
void hangouts_received_block_notification(PurpleConnection *pc, StateUpdate *state_update);
+void hangouts_received_view_modification(PurpleConnection *pc, StateUpdate *state_update);
+void hangouts_received_delete_notification(PurpleConnection *pc, StateUpdate *state_update);
void hangouts_received_state_update(PurpleConnection *pc, StateUpdate *state_update);