diff options
author | James Booth <boothj5@gmail.com> | 2014-05-05 20:13:22 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-05-05 20:13:22 +0100 |
commit | f247f367e92cb7da5299c30ab88e6bfc3f6cc7d2 (patch) | |
tree | f9518084439884785f13e8f9bc6a163b02990cdd /src | |
parent | 83966bd4b23cf271a5013f867d59714fac349c87 (diff) | |
download | profani-tty-f247f367e92cb7da5299c30ab88e6bfc3f6cc7d2.tar.gz |
Handle room subject and broadcasts sent before roster received
Issue #341
Diffstat (limited to 'src')
-rw-r--r-- | src/muc.c | 64 | ||||
-rw-r--r-- | src/muc.h | 5 | ||||
-rw-r--r-- | src/server_events.c | 32 |
3 files changed, 96 insertions, 5 deletions
diff --git a/src/muc.c b/src/muc.c index 9db485c0..369d19e1 100644 --- a/src/muc.c +++ b/src/muc.c @@ -34,6 +34,7 @@ typedef struct _muc_room_t { char *nick; // e.g. Some User char *password; char *subject; + GList *pending_broadcasts; gboolean autojoin; gboolean pending_nick_change; GHashTable *roster; @@ -144,6 +145,7 @@ muc_join_room(const char * const room, const char * const nick, new_room->password = NULL; } new_room->subject = NULL; + new_room->pending_broadcasts = NULL; new_room->roster = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)p_contact_free); new_room->nick_ac = autocomplete_new(); @@ -202,6 +204,65 @@ muc_room_is_autojoin(const char * const room) } } +void +muc_set_subject(const char * const room, const char * const subject) +{ + if (rooms != NULL) { + ChatRoom *chat_room = g_hash_table_lookup(rooms, room); + + if (chat_room != NULL) { + if (chat_room->subject != NULL) { + free(chat_room->subject); + } + chat_room->subject = strdup(subject); + } + } +} + +char * +muc_get_subject(const char * const room) +{ + if (rooms != NULL) { + ChatRoom *chat_room = g_hash_table_lookup(rooms, room); + + if (chat_room != NULL) { + return chat_room->subject; + } else { + return NULL; + } + } else { + return NULL; + } +} + +void +muc_add_pending_broadcast(const char * const room, const char * const message) +{ + if (rooms != NULL) { + ChatRoom *chat_room = g_hash_table_lookup(rooms, room); + + if (chat_room != NULL) { + chat_room->pending_broadcasts = g_list_append(chat_room->pending_broadcasts, strdup(message)); + } + } +} + +GList * +muc_get_pending_broadcasts(const char * const room) +{ + if (rooms != NULL) { + ChatRoom *chat_room = g_hash_table_lookup(rooms, room); + + if (chat_room != NULL) { + return chat_room->pending_broadcasts; + } else { + return NULL; + } + } else { + return NULL; + } +} + char * muc_get_old_nick(const char * const room, const char * const new_nick) { @@ -523,6 +584,9 @@ _free_room(ChatRoom *room) g_hash_table_remove_all(room->nick_changes); } free(room); + if (room->pending_broadcasts != NULL) { + g_list_free_full(room->pending_broadcasts, free); + } } } diff --git a/src/muc.h b/src/muc.h index 2dc4aa85..88b87191 100644 --- a/src/muc.h +++ b/src/muc.h @@ -71,4 +71,9 @@ void muc_reset_invites_ac(void); char* muc_find_invite(char *search_str); void muc_clear_invites(void); +void muc_set_subject(const char * const room, const char * const subject); +char * muc_get_subject(const char * const room); +void muc_add_pending_broadcast(const char * const room, const char * const message); +GList * muc_get_pending_broadcasts(const char * const room); + #endif diff --git a/src/server_events.c b/src/server_events.c index d18f1beb..6fb06c74 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -174,15 +174,22 @@ void handle_room_broadcast(const char *const room_jid, const char * const message) { - ui_room_broadcast(room_jid, message); - ui_current_page_off(); + if (muc_get_roster_received(room_jid)) { + ui_room_broadcast(room_jid, message); + ui_current_page_off(); + } else { + muc_add_pending_broadcast(room_jid, message); + } } void handle_room_subject(const char * const room_jid, const char * const subject) { - ui_room_subject(room_jid, subject); - ui_current_page_off(); + muc_set_subject(room_jid, subject); + if (muc_get_roster_received(room_jid)) { + ui_room_subject(room_jid, subject); + ui_current_page_off(); + } } void @@ -451,7 +458,22 @@ handle_room_roster_complete(const char * const room) muc_set_roster_received(room); GList *roster = muc_get_roster(room); ui_room_roster(room, roster, NULL); - ui_current_page_off(); + + char *subject = muc_get_subject(room); + if (subject != NULL) { + ui_room_subject(room, subject); + ui_current_page_off(); + } + + GList *pending_broadcasts = muc_get_pending_broadcasts(room); + if (pending_broadcasts != NULL) { + GList *curr = pending_broadcasts; + while (curr != NULL) { + ui_room_broadcast(room, curr->data); + curr = g_list_next(curr); + } + ui_current_page_off(); + } } void |