diff --git a/src/event/server_events.c b/src/event/server_events.c index 8ceb9f22..a56a54b0 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -136,7 +136,10 @@ void sv_ev_room_broadcast(const char *const room_jid, const char *const message) { if (muc_roster_complete(room_jid)) { - mucwin_broadcast(room_jid, message); + ProfMucWin *mucwin = wins_get_muc(room_jid); + if (mucwin) { + mucwin_broadcast(mucwin, message); + } } else { muc_pending_broadcasts_add(room_jid, message); } @@ -587,10 +590,10 @@ sv_ev_muc_self_online(const char *const room, const char *const nick, gboolean c } GList *pending_broadcasts = muc_pending_broadcasts(room); - if (pending_broadcasts) { + if (mucwin && pending_broadcasts) { GList *curr = pending_broadcasts; while (curr) { - mucwin_broadcast(room, curr->data); + mucwin_broadcast(mucwin, curr->data); curr = g_list_next(curr); } } diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index f4e104ca..a7668479 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -506,25 +506,23 @@ mucwin_kick_error(ProfMucWin *mucwin, const char *const nick, const char *const } void -mucwin_broadcast(const char *const roomjid, const char *const message) +mucwin_broadcast(ProfMucWin *mucwin, const char *const message) { - ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - if (window == NULL) { - log_error("Received room broadcast, but no window open for %s.", roomjid); + assert(mucwin != NULL); + + ProfWin *window = (ProfWin*)mucwin; + int num = wins_get_num(window); + + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "Room message: "); + win_vprint(window, '!', 0, NULL, NO_DATE, 0, "", "%s", message); + + // currently in groupchat window + if (wins_is_current(window)) { + status_bar_active(num); + + // not currently on groupchat window } else { - int num = wins_get_num(window); - - win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "Room message: "); - win_vprint(window, '!', 0, NULL, NO_DATE, 0, "", "%s", message); - - // currently in groupchat window - if (wins_is_current(window)) { - status_bar_active(num); - - // not currently on groupchat window - } else { - status_bar_new(num); - } + status_bar_new(num); } } diff --git a/src/ui/ui.h b/src/ui/ui.h index 5cfa3c8e..38c66a05 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -186,7 +186,7 @@ void mucwin_occupant_kicked(ProfMucWin *mucwin, const char *const nick, const ch const char *const reason); void mucwin_occupant_banned(ProfMucWin *mucwin, const char *const nick, const char *const actor, const char *const reason); -void mucwin_broadcast(const char *const roomjid, const char *const message); +void mucwin_broadcast(ProfMucWin *mucwin, const char *const message); void mucwin_occupant_offline(ProfMucWin *mucwin, const char *const nick); void mucwin_occupant_online(ProfMucWin *mucwin, const char *const nick, const char *const roles, const char *const affiliation, const char *const show, const char *const status); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 25f353b5..9b1be95f 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -223,8 +223,7 @@ void ui_room_banned(const char * const roomjid, const char * const actor, const void mucwin_occupant_banned(ProfMucWin *mucwin, const char * const nick, const char * const actor, const char * const reason) {} void ui_leave_room(const char * const roomjid) {} -void mucwin_broadcast(const char * const roomjid, - const char * const message) {} +void mucwin_broadcast(ProfMucWin *mucwin, const char * const message) {} void mucwin_occupant_offline(ProfMucWin *mucwin, const char * const nick) {} void mucwin_occupant_online(ProfMucWin *mucwin, const char * const nick, const char * const roles, const char * const affiliation, const char * const show, const char * const status) {}