1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

jabber: wait until full room roster received before showing

This commit is contained in:
James Booth 2012-11-07 22:24:50 +00:00
parent 5fe12bbd15
commit 54e591fea3
5 changed files with 58 additions and 11 deletions

View File

@ -655,13 +655,27 @@ _presence_handler(xmpp_conn_t * const conn,
char *from = xmpp_stanza_get_attribute(stanza, "from"); char *from = xmpp_stanza_get_attribute(stanza, "from");
// handle chat room presence
if (room_is_active(from)) { if (room_is_active(from)) {
char **tokens = g_strsplit(from, "/", 0); char *room = NULL;
char *room_jid = tokens[0]; char *nick = NULL;
char *nick = tokens[1];
if (strcmp(room_get_nick_for_room(room_jid), nick) != 0) { if (!room_parse_room_jid(from, &room, &nick)) {
prof_handle_chat_room_member(room_jid, nick); log_error("Could not parse room jid: %s", room);
g_free(room);
g_free(nick);
return 1;
} }
// handle self presence (means room roster has been sent)
if (strcmp(room_get_nick_for_room(room), nick) == 0) {
prof_handle_room_roster_complete(room);
} else {
room_add_to_roster(room, nick);
}
// handle regular presence
} else { } else {
char *short_from = strtok(from, "/"); char *short_from = strtok(from, "/");
char *type = xmpp_stanza_get_attribute(stanza, "type"); char *type = xmpp_stanza_get_attribute(stanza, "type");

View File

@ -35,6 +35,7 @@
#include "log.h" #include "log.h"
#include "preferences.h" #include "preferences.h"
#include "profanity.h" #include "profanity.h"
#include "room_chat.h"
#include "jabber.h" #include "jabber.h"
#include "ui.h" #include "ui.h"
@ -186,10 +187,14 @@ prof_handle_room_message(const char * const room_jid, const char * const nick,
} }
void void
prof_handle_chat_room_member(const char * const room_jid, prof_handle_room_roster_complete(const char * const room)
const char * const nick)
{ {
win_show_chat_room_member(room_jid, nick); GSList *roster = room_get_roster(room);
while (roster != NULL) {
win_show_chat_room_member(room, roster->data);
roster = g_slist_next(roster);
}
} }
void void

View File

@ -39,8 +39,6 @@ void prof_handle_room_history(const char * const room_jid,
const char * const nick, GTimeVal tv_stamp, const char * const message); const char * const nick, GTimeVal tv_stamp, const char * const message);
void prof_handle_room_message(const char * const room_jid, const char * const nick, void prof_handle_room_message(const char * const room_jid, const char * const nick,
const char * const message); const char * const message);
void void prof_handle_room_roster_complete(const char * const room);
prof_handle_chat_room_member(const char * const room_jid,
const char * const nick);
#endif #endif

View File

@ -28,6 +28,7 @@
typedef struct _muc_room_t { typedef struct _muc_room_t {
char *jid; char *jid;
char *nick; char *nick;
GSList *roster;
} muc_room; } muc_room;
GHashTable *rooms = NULL; GHashTable *rooms = NULL;
@ -45,6 +46,7 @@ room_join(const char * const jid, const char * const nick)
muc_room *new_room = malloc(sizeof(muc_room)); muc_room *new_room = malloc(sizeof(muc_room));
new_room->jid = strdup(jid); new_room->jid = strdup(jid);
new_room->nick = strdup(nick); new_room->nick = strdup(nick);
new_room->roster = NULL;
g_hash_table_insert(rooms, strdup(jid), new_room); g_hash_table_insert(rooms, strdup(jid), new_room);
} }
@ -107,6 +109,28 @@ room_parse_room_jid(const char * const room_jid, char **room, char **nick)
} }
} }
void
room_add_to_roster(const char * const jid, const char * const nick)
{
muc_room *room = g_hash_table_lookup(rooms, jid);
if (room != NULL) {
room->roster = g_slist_append(room->roster, strdup(nick));
}
}
GSList *
room_get_roster(const char * const jid)
{
muc_room *room = g_hash_table_lookup(rooms, jid);
if (room != NULL) {
return room->roster;
} else {
return NULL;
}
}
static void static void
_room_free(muc_room *room) _room_free(muc_room *room)
{ {
@ -119,6 +143,10 @@ _room_free(muc_room *room)
g_free(room->nick); g_free(room->nick);
room->nick = NULL; room->nick = NULL;
} }
if (room->roster != NULL) {
g_slist_free_full(room->roster, g_free);
room->roster = NULL;
}
g_free(room); g_free(room);
} }
room = NULL; room = NULL;

View File

@ -28,3 +28,5 @@ gboolean room_is_active(const char * const jid);
char * room_get_nick_for_room(const char * const jid); char * room_get_nick_for_room(const char * const jid);
gboolean room_parse_room_jid(const char * const room_jid, char **room, gboolean room_parse_room_jid(const char * const room_jid, char **room,
char **nick); char **nick);
void room_add_to_roster(const char * const jid, const char * const nick);
GSList * room_get_roster(const char * const jid);