diff options
author | James Booth <boothj5@gmail.com> | 2014-03-08 21:20:26 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-03-08 21:20:26 +0000 |
commit | b177250f47f5599943b6772aed43de49834147e2 (patch) | |
tree | 822ad8a0b4e38c84b1e004922e1a8e0308d809ac | |
parent | dd1ee18c72268839de8af64de5eb07c5a2499ff2 (diff) | |
download | profani-tty-b177250f47f5599943b6772aed43de49834147e2.tar.gz |
Refactored muc_room_is_active to only take room, rather than full jid
-rw-r--r-- | src/command/commands.c | 5 | ||||
-rw-r--r-- | src/muc.c | 4 | ||||
-rw-r--r-- | src/muc.h | 2 | ||||
-rw-r--r-- | src/server_events.c | 4 | ||||
-rw-r--r-- | src/ui/core.c | 4 | ||||
-rw-r--r-- | src/xmpp/bookmark.c | 2 | ||||
-rw-r--r-- | src/xmpp/iq.c | 2 | ||||
-rw-r--r-- | src/xmpp/message.c | 4 | ||||
-rw-r--r-- | src/xmpp/stanza.c | 2 | ||||
-rw-r--r-- | tests/test_muc.c | 15 | ||||
-rw-r--r-- | tests/test_server_events.c | 2 |
11 files changed, 19 insertions, 27 deletions
diff --git a/src/command/commands.c b/src/command/commands.c index e6d575f5..5e594184 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1656,16 +1656,13 @@ cmd_join(gchar **args, struct cmd_help_t help) nick = account->muc_nick; } - Jid *room_jid = jid_create_from_bare_and_resource(room, nick); - - if (!muc_room_is_active(room_jid)) { + if (!muc_room_is_active(room)) { presence_join_room(room, nick, passwd); } ui_room_join(room); muc_remove_invite(room); jid_destroy(room_arg); - jid_destroy(room_jid); g_string_free(room_str, TRUE); account_free(account); diff --git a/src/muc.c b/src/muc.c index 3cc410bf..cb8dd346 100644 --- a/src/muc.c +++ b/src/muc.c @@ -164,10 +164,10 @@ muc_leave_room(const char * const room) * Returns TRUE if the user is currently in the room */ gboolean -muc_room_is_active(Jid *jid) +muc_room_is_active(const char * const room) { if (rooms != NULL) { - ChatRoom *chat_room = g_hash_table_lookup(rooms, jid->barejid); + ChatRoom *chat_room = g_hash_table_lookup(rooms, room); if (chat_room != NULL) { return TRUE; diff --git a/src/muc.h b/src/muc.h index ce5602c4..7c378dd3 100644 --- a/src/muc.h +++ b/src/muc.h @@ -33,7 +33,7 @@ void muc_init(void); void muc_close(void); void muc_join_room(const char * const room, const char * const nick); void muc_leave_room(const char * const room); -gboolean muc_room_is_active(Jid *jid); +gboolean muc_room_is_active(const char * const room); GList* muc_get_active_room_list(void); char * muc_get_room_nick(const char * const room); diff --git a/src/server_events.c b/src/server_events.c index b4919ee3..ae582cc4 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -156,13 +156,11 @@ handle_room_invite(jabber_invite_t invite_type, const char * const invitor, const char * const room, const char * const reason) { - Jid *room_jid = jid_create(room); - if (!muc_room_is_active(room_jid) && !muc_invites_include(room)) { + if (!muc_room_is_active(room) && !muc_invites_include(room)) { cons_show_room_invite(invitor, room, reason); muc_add_invite(room); ui_current_page_off(); } - jid_destroy(room_jid); } void diff --git a/src/ui/core.c b/src/ui/core.c index ef8ace73..8bc17e4e 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -930,7 +930,7 @@ _ui_new_chat_win(const char * const to) if (window == NULL) { Jid *jid = jid_create(to); - if (muc_room_is_active(jid)) { + if (muc_room_is_active(jid->barejid)) { window = wins_new(to, WIN_PRIVATE); } else { window = wins_new(to, WIN_CHAT); @@ -1037,7 +1037,7 @@ _ui_outgoing_msg(const char * const from, const char * const to, if (window == NULL) { Jid *jid = jid_create(to); - if (muc_room_is_active(jid)) { + if (muc_room_is_active(jid->barejid)) { window = wins_new(to, WIN_PRIVATE); } else { window = wins_new(to, WIN_CHAT); diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c index 5c27e2cf..a5fd45e3 100644 --- a/src/xmpp/bookmark.c +++ b/src/xmpp/bookmark.c @@ -300,7 +300,7 @@ _bookmark_handle_result(xmpp_conn_t * const conn, log_debug("Autojoin %s with nick=%s", jid, name); room_jid = jid_create_from_bare_and_resource(jid, name); - if (!muc_room_is_active(room_jid)) { + if (!muc_room_is_active(room_jid->barejid)) { presence_join_room(jid, name, NULL); /* TODO: this should be removed after fixing #195 */ ui_room_join(jid); diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 7c8a61c4..fee1c661 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -247,7 +247,7 @@ _version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, PContact contact; Jid *jidp = jid_create(jid); - if (muc_room_is_active(jidp)) { + if (muc_room_is_active(jidp->barejid)) { contact = muc_get_participant(jidp->barejid, jidp->resourcepart); } else { contact = roster_get_contact(jidp->barejid); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 5a7e9075..65be9b8c 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -386,7 +386,7 @@ _groupchat_handler(xmpp_conn_t * const conn, } // room not active in profanity - if (!muc_room_is_active(jid)) { + if (!muc_room_is_active(jid->barejid)) { log_error("Message recieved for inactive chat room: %s", jid->str); jid_destroy(jid); return 1; @@ -438,7 +438,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, return 1; // private message from chat room use full jid (room/nick) - } else if (muc_room_is_active(jid)) { + } else if (muc_room_is_active(jid->barejid)) { // determine if the notifications happened whilst offline GTimeVal tv_stamp; gboolean delayed = stanza_get_delay(stanza, &tv_stamp); diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 965b1671..65c329a5 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -597,7 +597,7 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza, char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (from != NULL) { Jid *jidp = jid_create(from); - if (muc_room_is_active(jidp)) { + if (muc_room_is_active(jidp->barejid)) { char *nick = muc_get_room_nick(jidp->barejid); if (g_strcmp0(jidp->resourcepart, nick) == 0) { return TRUE; diff --git a/tests/test_muc.c b/tests/test_muc.c index ba4fef1d..3cfb38b4 100644 --- a/tests/test_muc.c +++ b/tests/test_muc.c @@ -59,23 +59,20 @@ void test_muc_invite_count_5(void **state) void test_muc_room_is_not_active(void **state) { - Jid *jidp = jid_create("room@server.org/bob"); + char *room = "room@server.org"; - gboolean room_is_active = muc_room_is_active(jidp); + gboolean room_is_active = muc_room_is_active(room); assert_false(room_is_active); - - jid_destroy(jidp); } void test_muc_room_is_active(void **state) { - Jid *jidp = jid_create("room@server.org/bob"); - muc_join_room(jidp->barejid, jidp->resourcepart); + char *room = "room@server.org"; + char *nick = "bob"; + muc_join_room(room, nick); - gboolean room_is_active = muc_room_is_active(jidp); + gboolean room_is_active = muc_room_is_active(room); assert_true(room_is_active); - - jid_destroy(jidp); } diff --git a/tests/test_server_events.c b/tests/test_server_events.c index ef5620fd..af8f8d1a 100644 --- a/tests/test_server_events.c +++ b/tests/test_server_events.c @@ -216,7 +216,7 @@ void handle_presence_error_when_nick_conflict_does_not_join_room(void **state) handle_presence_error(from, type, err_msg); - gboolean room_is_active = muc_room_is_active(jidp); + gboolean room_is_active = muc_room_is_active(jidp->barejid); assert_false(room_is_active); muc_close(); |