1
0
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Refactored muc_room_is_active to only take room, rather than full jid

This commit is contained in:
James Booth 2014-03-08 21:20:26 +00:00
parent dd1ee18c72
commit b177250f47
11 changed files with 19 additions and 27 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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);
}

View File

@ -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();