Fix auto-joining chats
This commit is contained in:
parent
ccf28caa8c
commit
b85fc85322
6 changed files with 51 additions and 4 deletions
|
@ -251,6 +251,11 @@ static void on_userpic_loaded (struct tgl_state *TLS, void *extra, int success,
|
||||||
static void on_get_dialog_list_done (struct tgl_state *TLS, void *callback_extra, int success, int size,
|
static void on_get_dialog_list_done (struct tgl_state *TLS, void *callback_extra, int success, int size,
|
||||||
tgl_peer_id_t peers[], tgl_message_id_t *last_msg_id[], int unread_count[]) {
|
tgl_peer_id_t peers[], tgl_message_id_t *last_msg_id[], int unread_count[]) {
|
||||||
info ("Fetched dialogue list of size: %d", size);
|
info ("Fetched dialogue list of size: %d", size);
|
||||||
|
if (tgp_error_if_false (TLS, success, "Fetching dialogue list failed", TLS->error)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add all peers in the dialogue list to the buddy list
|
||||||
int i;
|
int i;
|
||||||
for (i = size - 1; i >= 0; i--) {
|
for (i = size - 1; i >= 0; i--) {
|
||||||
tgl_peer_t *UC = tgl_peer_get (TLS, peers[i]);
|
tgl_peer_t *UC = tgl_peer_get (TLS, peers[i]);
|
||||||
|
@ -288,6 +293,10 @@ static void on_get_dialog_list_done (struct tgl_state *TLS, void *callback_extra
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// now that the dialogue list is loaded, handle all pending chat joins
|
||||||
|
tls_get_data (TLS)->dialogues_ready = TRUE;
|
||||||
|
tgp_chat_join_all_pending (TLS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_user_get_info (struct tgl_state *TLS, void *info_data, int success, struct tgl_user *U) {
|
void on_user_get_info (struct tgl_state *TLS, void *info_data, int success, struct tgl_user *U) {
|
||||||
|
@ -318,7 +327,6 @@ static const char *tgprpl_list_icon (PurpleAccount *acct, PurpleBuddy *buddy) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tgprpl_tooltip_text (PurpleBuddy *buddy, PurpleNotifyUserInfo *info, gboolean full) {
|
static void tgprpl_tooltip_text (PurpleBuddy *buddy, PurpleNotifyUserInfo *info, gboolean full) {
|
||||||
|
|
||||||
// buddy in old format that didn't migrate
|
// buddy in old format that didn't migrate
|
||||||
if (! tgp_blist_buddy_has_id (buddy)) {
|
if (! tgp_blist_buddy_has_id (buddy)) {
|
||||||
return;
|
return;
|
||||||
|
@ -497,7 +505,13 @@ static void update_on_logged_in (struct tgl_state *TLS) {
|
||||||
|
|
||||||
static void update_on_ready (struct tgl_state *TLS) {
|
static void update_on_ready (struct tgl_state *TLS) {
|
||||||
info ("update_on_ready(): The account is done fetching new history");
|
info ("update_on_ready(): The account is done fetching new history");
|
||||||
purple_connection_set_display_name (tls_get_conn (TLS), purple_account_get_username (tls_get_pa (TLS)));
|
|
||||||
|
tgl_peer_t *P = tgl_peer_get (TLS, TLS->our_id);
|
||||||
|
g_warn_if_fail(P);
|
||||||
|
if (P) {
|
||||||
|
purple_connection_set_display_name (tls_get_conn (TLS), P->print_name);
|
||||||
|
}
|
||||||
|
|
||||||
tgl_do_get_dialog_list (TLS, 200, 0, on_get_dialog_list_done, NULL);
|
tgl_do_get_dialog_list (TLS, 200, 0, on_get_dialog_list_done, NULL);
|
||||||
tgl_do_update_contact_list (TLS, 0, 0);
|
tgl_do_update_contact_list (TLS, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
27
tgp-chat.c
27
tgp-chat.c
|
@ -156,6 +156,19 @@ GHashTable *tgprpl_chat_info_defaults (PurpleConnection *gc, const char *chat_na
|
||||||
|
|
||||||
void tgprpl_chat_join (PurpleConnection *gc, GHashTable *data) {
|
void tgprpl_chat_join (PurpleConnection *gc, GHashTable *data) {
|
||||||
debug ("tgprpl_chat_join()");
|
debug ("tgprpl_chat_join()");
|
||||||
|
g_return_if_fail(data);
|
||||||
|
|
||||||
|
// auto joins will cause chat joins at a time when the dialogue list is not ready, remember
|
||||||
|
// those chats and join them once the dialogue list is fetched
|
||||||
|
if (! gc_get_data (gc)->dialogues_ready) {
|
||||||
|
g_return_if_fail (data);
|
||||||
|
const char *id = g_hash_table_lookup (data, "id");
|
||||||
|
if (id) {
|
||||||
|
debug ("attempting to join chat %s while not ready, queue up for later", id);
|
||||||
|
gc_get_data (gc)->pending_joins = g_list_append (gc_get_data (gc)->pending_joins, g_strdup (id));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// join existing chat by id when the user clicks on a chat in the buddy list
|
// join existing chat by id when the user clicks on a chat in the buddy list
|
||||||
void *value = g_hash_table_lookup (data, "id");
|
void *value = g_hash_table_lookup (data, "id");
|
||||||
|
@ -253,3 +266,17 @@ void tgprpl_roomlist_cancel (PurpleRoomlist *list) {
|
||||||
purple_roomlist_unref (list);
|
purple_roomlist_unref (list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tgp_chat_join_all_pending (struct tgl_state *TLS) {
|
||||||
|
GList *pending;
|
||||||
|
for (pending = tls_get_data (TLS)->pending_joins; pending != NULL; pending = g_list_next(pending)) {
|
||||||
|
GHashTable *data = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
|
g_hash_table_insert (data, "id", pending->data);
|
||||||
|
tgprpl_chat_join (tls_get_conn (TLS), data);
|
||||||
|
g_hash_table_destroy (data);
|
||||||
|
}
|
||||||
|
if (tls_get_data (TLS)->pending_joins) {
|
||||||
|
g_list_free (tls_get_data (TLS)->pending_joins);
|
||||||
|
tls_get_data (TLS)->pending_joins = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -38,4 +38,5 @@ GList *tgprpl_chat_join_info (PurpleConnection *gc);
|
||||||
PurpleRoomlist *tgprpl_roomlist_get_list (PurpleConnection *gc);
|
PurpleRoomlist *tgprpl_roomlist_get_list (PurpleConnection *gc);
|
||||||
void tgprpl_roomlist_cancel (PurpleRoomlist *list);
|
void tgprpl_roomlist_cancel (PurpleRoomlist *list);
|
||||||
GHashTable *tgprpl_chat_info_defaults (PurpleConnection *gc, const char *chat_name);
|
GHashTable *tgprpl_chat_info_defaults (PurpleConnection *gc, const char *chat_name);
|
||||||
|
void tgp_chat_join_all_pending (struct tgl_state *TLS);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -114,6 +114,7 @@ void *connection_data_free (connection_data *conn) {
|
||||||
tgp_g_queue_free_full (conn->new_messages, tgp_msg_loading_free);
|
tgp_g_queue_free_full (conn->new_messages, tgp_msg_loading_free);
|
||||||
tgp_g_queue_free_full (conn->out_messages, tgp_msg_sending_free);
|
tgp_g_queue_free_full (conn->out_messages, tgp_msg_sending_free);
|
||||||
tgp_g_list_free_full (conn->used_images, used_image_free);
|
tgp_g_list_free_full (conn->used_images, used_image_free);
|
||||||
|
tgp_g_list_free_full (conn->pending_joins, g_free);
|
||||||
g_hash_table_destroy (conn->pending_reads);
|
g_hash_table_destroy (conn->pending_reads);
|
||||||
g_hash_table_destroy (conn->pending_chat_info);
|
g_hash_table_destroy (conn->pending_chat_info);
|
||||||
g_hash_table_destroy (conn->id_to_purple_name);
|
g_hash_table_destroy (conn->id_to_purple_name);
|
||||||
|
|
|
@ -45,6 +45,8 @@ typedef struct {
|
||||||
PurpleRoomlist *roomlist;
|
PurpleRoomlist *roomlist;
|
||||||
GHashTable *pending_chat_info;
|
GHashTable *pending_chat_info;
|
||||||
GHashTable *id_to_purple_name;
|
GHashTable *id_to_purple_name;
|
||||||
|
GList *pending_joins;
|
||||||
|
int dialogues_ready;
|
||||||
} connection_data;
|
} connection_data;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -93,8 +93,10 @@ void tgp_g_queue_free_full (GQueue *queue, GDestroyNotify free_func) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tgp_g_list_free_full (GList *list, GDestroyNotify free_func) {
|
void tgp_g_list_free_full (GList *list, GDestroyNotify free_func) {
|
||||||
g_list_foreach (list, (GFunc)free_func, NULL);
|
if (list) {
|
||||||
g_list_free (list);
|
g_list_foreach (list, (GFunc)free_func, NULL);
|
||||||
|
g_list_free (list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *tgp_mime_to_filetype (const char *mime) {
|
const char *tgp_mime_to_filetype (const char *mime) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue