From 23ada0d38b11b263e6634481ed8877b70939a7f1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 2 Nov 2015 00:29:35 +0000 Subject: [PATCH] mucwin_subject takes ProfMucWin --- src/event/server_events.c | 9 ++++--- src/ui/mucwin.c | 50 +++++++++++++++++------------------- src/ui/ui.h | 2 +- tests/unittests/ui/stub_ui.c | 2 +- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index ce0da5b8..8ceb9f22 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -146,8 +146,9 @@ void sv_ev_room_subject(const char *const room, const char *const nick, const char *const subject) { muc_set_subject(room, subject); - if (muc_roster_complete(room)) { - mucwin_subject(room, nick, subject); + ProfMucWin *mucwin = wins_get_muc(room); + if (mucwin && muc_roster_complete(room)) { + mucwin_subject(mucwin, nick, subject); } } @@ -581,8 +582,8 @@ sv_ev_muc_self_online(const char *const room, const char *const nick, gboolean c } char *subject = muc_subject(room); - if (subject) { - mucwin_subject(room, NULL, subject); + if (mucwin && subject) { + mucwin_subject(mucwin, NULL, subject); } GList *pending_broadcasts = muc_pending_broadcasts(room); diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index 9b77cf7d..238db218 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -463,38 +463,36 @@ mucwin_requires_config(ProfMucWin *mucwin) } void -mucwin_subject(const char *const roomjid, const char *const nick, const char *const subject) +mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const subject) { - ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - if (window == NULL) { - log_error("Received room subject, but no window open for %s.", roomjid); + assert(mucwin != NULL); + + ProfWin *window = (ProfWin*)mucwin; + int num = wins_get_num(window); + + if (subject) { + if (nick) { + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "*%s has set the room subject: ", nick); + win_vprint(window, '!', 0, NULL, NO_DATE, 0, "", "%s", subject); + } else { + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "Room subject: "); + win_vprint(window, '!', 0, NULL, NO_DATE, 0, "", "%s", subject); + } } else { - int num = wins_get_num(window); - - if (subject) { - if (nick) { - win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "*%s has set the room subject: ", nick); - win_vprint(window, '!', 0, NULL, NO_DATE, 0, "", "%s", subject); - } else { - win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "Room subject: "); - win_vprint(window, '!', 0, NULL, NO_DATE, 0, "", "%s", subject); - } + if (nick) { + win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "*%s has cleared the room subject.", nick); } else { - if (nick) { - win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "*%s has cleared the room subject.", nick); - } else { - win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Room subject cleared"); - } + win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Room subject cleared"); } + } - // currently in groupchat window - if (wins_is_current(window)) { - status_bar_active(num); + // currently in groupchat window + if (wins_is_current(window)) { + status_bar_active(num); - // not currently on groupchat window - } else { - status_bar_active(num); - } + // not currently on groupchat window + } else { + status_bar_active(num); } } diff --git a/src/ui/ui.h b/src/ui/ui.h index a85e429f..3ce0fea7 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -175,7 +175,7 @@ void mucwin_occupant_role_and_affiliation_change(ProfMucWin *mucwin, const char void mucwin_roster(ProfMucWin *mucwin, GList *occupants, const char *const presence); void mucwin_history(ProfMucWin *mucwin, const char *const nick, GDateTime *timestamp, const char *const message); void mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message); -void mucwin_subject(const char *const roomjid, const char *const nick, const char *const subject); +void mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const subject); void mucwin_requires_config(ProfMucWin *mucwin); void mucwin_info(ProfMucWin *mucwin); void mucwin_show_role_list(ProfMucWin *mucwin, muc_role_t role); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 41d240dc..35ecc824 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -206,7 +206,7 @@ void mucwin_occupant_role_and_affiliation_change(ProfMucWin *mucwin, const char void mucwin_roster(ProfMucWin *mucwin, GList *occupants, const char * const presence) {} void mucwin_history(ProfMucWin *mucwin, const char * const nick, GDateTime *timestamp, const char * const message) {} void mucwin_message(ProfMucWin *mucwin, const char * const nick, const char * const message) {} -void mucwin_subject(const char * const roomjid, const char * const nick, const char * const subject) {} +void mucwin_subject(ProfMucWin *mucwin, const char * const nick, const char * const subject) {} void mucwin_requires_config(ProfMucWin *mucwin) {} void ui_room_destroy(const char * const roomjid) {} void mucwin_info(ProfMucWin *mucwin) {}