diff --git a/src/event/client_events.c b/src/event/client_events.c index 5413dea7..0df4468e 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -185,6 +185,8 @@ cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char *const msg) { if (privwin->occupant_offline) { privwin_message_occupant_offline(privwin); + } else if (privwin->room_left) { + privwin_message_left_room(privwin); } else { message_send_private(privwin->fulljid, msg); privwin_outgoing_msg(privwin, msg); diff --git a/src/ui/core.c b/src/ui/core.c index 78a992d9..735dc03a 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -821,6 +821,15 @@ ui_room_join(const char *const roomjid, gboolean focus) char *nick = muc_nick(roomjid); win_vprint(console, '!', 0, NULL, 0, THEME_TYPING, "", "-> Autojoined %s as %s (%d).", roomjid, nick, num); } + + GList *privwins = wins_get_private_chats(roomjid); + GList *curr = privwins; + while (curr) { + ProfPrivateWin *privwin = curr->data; + privwin_room_joined(privwin); + curr = g_list_next(curr); + } + g_list_free(privwins); } void @@ -841,6 +850,15 @@ ui_room_destroy(const char *const roomjid) ui_close_win(num); cons_show("Room destroyed: %s", roomjid); } + + GList *privwins = wins_get_private_chats(roomjid); + GList *curr = privwins; + while (curr) { + ProfPrivateWin *privwin = curr->data; + privwin_room_destroyed(privwin); + curr = g_list_next(curr); + } + g_list_free(privwins); } void @@ -851,6 +869,16 @@ ui_leave_room(const char *const roomjid) int num = wins_get_num(window); ui_close_win(num); } + + GList *privwins = wins_get_private_chats(roomjid); + GList *curr = privwins; + while (curr) { + ProfPrivateWin *privwin = curr->data; + privwin_room_left(privwin); + curr = g_list_next(curr); + } + g_list_free(privwins); + } void @@ -879,6 +907,15 @@ ui_room_destroyed(const char *const roomjid, const char *const reason, const cha } } } + + GList *privwins = wins_get_private_chats(roomjid); + GList *curr = privwins; + while (curr) { + ProfPrivateWin *privwin = curr->data; + privwin_room_destroyed(privwin); + curr = g_list_next(curr); + } + g_list_free(privwins); } void @@ -906,6 +943,15 @@ ui_room_kicked(const char *const roomjid, const char *const actor, const char *c win_vprint(console, '!', 0, NULL, 0, THEME_TYPING, "", "<- %s", message->str); g_string_free(message, TRUE); } + + GList *privwins = wins_get_private_chats(roomjid); + GList *curr = privwins; + while (curr) { + ProfPrivateWin *privwin = curr->data; + privwin_room_kicked(privwin, actor, reason); + curr = g_list_next(curr); + } + g_list_free(privwins); } void @@ -933,6 +979,15 @@ ui_room_banned(const char *const roomjid, const char *const actor, const char *c win_vprint(console, '!', 0, NULL, 0, THEME_TYPING, "", "<- %s", message->str); g_string_free(message, TRUE); } + + GList *privwins = wins_get_private_chats(roomjid); + GList *curr = privwins; + while (curr) { + ProfPrivateWin *privwin = curr->data; + privwin_room_banned(privwin, actor, reason); + curr = g_list_next(curr); + } + g_list_free(privwins); } int diff --git a/src/ui/privwin.c b/src/ui/privwin.c index 6a249091..be84a69c 100644 --- a/src/ui/privwin.c +++ b/src/ui/privwin.c @@ -119,6 +119,14 @@ privwin_message_occupant_offline(ProfPrivateWin *privwin) win_print((ProfWin*)privwin, '-', 0, NULL, 0, THEME_ERROR, NULL, "Unable to send message, occupant no longer present in room."); } +void +privwin_message_left_room(ProfPrivateWin *privwin) +{ + assert(privwin != NULL); + + win_print((ProfWin*)privwin, '-', 0, NULL, 0, THEME_ERROR, NULL, "Unable to send message, you are no longer present in room."); +} + void privwin_occupant_offline(ProfPrivateWin *privwin) { @@ -187,6 +195,85 @@ privwin_occupant_online(ProfPrivateWin *privwin) jid_destroy(jidp); } +void +privwin_room_destroyed(ProfPrivateWin *privwin) +{ + assert(privwin != NULL); + + privwin->room_left = TRUE; + Jid *jidp = jid_create(privwin->fulljid); + win_vprint((ProfWin*)privwin, '!', 0, NULL, 0, THEME_OFFLINE, NULL, "-- %s has been destroyed.", jidp->barejid); + jid_destroy(jidp); +} + +void +privwin_room_joined(ProfPrivateWin *privwin) +{ + assert(privwin != NULL); + + privwin->room_left = FALSE; + Jid *jidp = jid_create(privwin->fulljid); + win_vprint((ProfWin*)privwin, '!', 0, NULL, 0, THEME_OFFLINE, NULL, "-- You have joined %s.", jidp->barejid); + jid_destroy(jidp); +} + +void +privwin_room_left(ProfPrivateWin *privwin) +{ + assert(privwin != NULL); + + privwin->room_left = TRUE; + Jid *jidp = jid_create(privwin->fulljid); + win_vprint((ProfWin*)privwin, '!', 0, NULL, 0, THEME_OFFLINE, NULL, "-- You have left %s.", jidp->barejid); + jid_destroy(jidp); +} + +void +privwin_room_kicked(ProfPrivateWin *privwin, const char *const actor, const char *const reason) +{ + assert(privwin != NULL); + + privwin->room_left = TRUE; + GString *message = g_string_new("Kicked from "); + Jid *jidp = jid_create(privwin->fulljid); + g_string_append(message, jidp->barejid); + jid_destroy(jidp); + if (actor) { + g_string_append(message, " by "); + g_string_append(message, actor); + } + if (reason) { + g_string_append(message, ", reason: "); + g_string_append(message, reason); + } + + win_vprint((ProfWin*)privwin, '!', 0, NULL, 0, THEME_OFFLINE, "", "<- %s", message->str); + g_string_free(message, TRUE); +} + +void +privwin_room_banned(ProfPrivateWin *privwin, const char *const actor, const char *const reason) +{ + assert(privwin != NULL); + + privwin->room_left = TRUE; + GString *message = g_string_new("Banned from "); + Jid *jidp = jid_create(privwin->fulljid); + g_string_append(message, jidp->barejid); + jid_destroy(jidp); + if (actor) { + g_string_append(message, " by "); + g_string_append(message, actor); + } + if (reason) { + g_string_append(message, ", reason: "); + g_string_append(message, reason); + } + + win_vprint((ProfWin*)privwin, '!', 0, NULL, 0, THEME_OFFLINE, "", "<- %s", message->str); + g_string_free(message, TRUE); +} + char* privwin_get_string(ProfPrivateWin *privwin) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 91ee4d37..a20e30dc 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -196,12 +196,20 @@ void privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, void privwin_outgoing_msg(ProfPrivateWin *privwin, const char *const message); void privwin_message_occupant_offline(ProfPrivateWin *privwin); +void privwin_message_left_room(ProfPrivateWin *privwin); + char* privwin_get_string(ProfPrivateWin *privwin); void privwin_occupant_offline(ProfPrivateWin *privwin); void privwin_occupant_kicked(ProfPrivateWin *privwin, const char *const actor, const char *const reason); void privwin_occupant_banned(ProfPrivateWin *privwin, const char *const actor, const char *const reason); void privwin_occupant_online(ProfPrivateWin *privwin); +void privwin_room_destroyed(ProfPrivateWin *privwin); +void privwin_room_left(ProfPrivateWin *privwin); +void privwin_room_kicked(ProfPrivateWin *privwin, const char *const actor, const char *const reason); +void privwin_room_banned(ProfPrivateWin *privwin, const char *const actor, const char *const reason); +void privwin_room_joined(ProfPrivateWin *privwin); + // MUC room config window void mucconfwin_handle_configuration(ProfMucConfWin *confwin, DataForm *form); void mucconfwin_show_form(ProfMucConfWin *confwin); diff --git a/src/ui/win_types.h b/src/ui/win_types.h index 0e9f81d7..558359a2 100644 --- a/src/ui/win_types.h +++ b/src/ui/win_types.h @@ -138,6 +138,7 @@ typedef struct prof_private_win_t { gboolean notify; unsigned long memcheck; gboolean occupant_offline; + gboolean room_left; } ProfPrivateWin; typedef struct prof_xml_win_t { diff --git a/src/ui/window.c b/src/ui/window.c index 8ae04499..d8499ad3 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -221,6 +221,7 @@ win_create_private(const char *const fulljid) new_win->unread = 0; new_win->notify = FALSE; new_win->occupant_offline = FALSE; + new_win->room_left = FALSE; new_win->memcheck = PROFPRIVATEWIN_MEMCHECK; diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 2e7ec7b1..0f4510c1 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -174,6 +174,8 @@ void privwin_occupant_banned(ProfPrivateWin *privwin, const char *const actor, c void privwin_occupant_online(ProfPrivateWin *privwin) {} void privwin_message_occupant_offline(ProfPrivateWin *privwin) {} +void privwin_message_left_room(ProfPrivateWin *privwin) {} + void ui_room_join(const char * const roomjid, gboolean focus) {} void ui_switch_to_room(const char * const roomjid) {}