From 150015fa3dd0238671d11f2c6c3ba677e7aab81f Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 2 Feb 2016 21:52:13 +0000 Subject: [PATCH 1/3] Show message in private windows when user offline --- src/event/client_events.c | 8 ++++++-- src/event/server_events.c | 16 ++++++++++++++++ src/ui/buffer.c | 2 +- src/ui/privwin.c | 30 ++++++++++++++++++++++++++++++ src/ui/ui.h | 4 ++++ src/ui/win_types.h | 1 + src/ui/window.c | 3 ++- 7 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/event/client_events.c b/src/event/client_events.c index 2f227d9f..5413dea7 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -183,6 +183,10 @@ cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg) void cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char *const msg) { - message_send_private(privwin->fulljid, msg); - privwin_outgoing_msg(privwin, msg); + if (privwin->occupant_offline) { + privwin_message_occupant_offline(privwin); + } else { + message_send_private(privwin->fulljid, msg); + privwin_outgoing_msg(privwin, msg); + } } diff --git a/src/event/server_events.c b/src/event/server_events.c index 105c7d72..e6738833 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -665,6 +665,14 @@ sv_ev_room_occupant_offline(const char *const room, const char *const nick, mucwin_occupant_offline(mucwin, nick); } prefs_free_string(muc_status_pref); + + Jid *jidp = jid_create_from_bare_and_resource(room, nick); + ProfPrivateWin *privwin = wins_get_private(jidp->fulljid); + jid_destroy(jidp); + if (privwin != NULL) { + privwin_occupant_offline(privwin); + } + occupantswin_occupants(room); rosterwin_roster(); } @@ -840,6 +848,14 @@ sv_ev_muc_occupant_online(const char *const room, const char *const nick, const mucwin_occupant_online(mucwin, nick, role, affiliation, show, status); } prefs_free_string(muc_status_pref); + + Jid *jidp = jid_create_from_bare_and_resource(mucwin->roomjid, nick); + ProfPrivateWin *privwin = wins_get_private(jidp->fulljid); + jid_destroy(jidp); + if (privwin) { + privwin_occupant_online(privwin); + } + occupantswin_occupants(room); rosterwin_roster(); return; diff --git a/src/ui/buffer.c b/src/ui/buffer.c index 629aa9e7..0b9da448 100644 --- a/src/ui/buffer.c +++ b/src/ui/buffer.c @@ -88,7 +88,7 @@ buffer_push(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *ti e->flags = flags; e->theme_item = theme_item; e->time = g_date_time_ref(time); - e->from = strdup(from); + e->from = from ? strdup(from) : NULL; e->message = strdup(message); e->receipt = receipt; diff --git a/src/ui/privwin.c b/src/ui/privwin.c index b6f1a04d..4b8217e2 100644 --- a/src/ui/privwin.c +++ b/src/ui/privwin.c @@ -111,6 +111,36 @@ privwin_outgoing_msg(ProfPrivateWin *privwin, const char *const message) win_print((ProfWin*)privwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message); } +void +privwin_message_occupant_offline(ProfPrivateWin *privwin) +{ + assert(privwin != NULL); + + win_print((ProfWin*)privwin, '-', 0, NULL, 0, THEME_ERROR, NULL, "Unable to send message, occupant no longer present in room."); +} + +void +privwin_occupant_offline(ProfPrivateWin *privwin) +{ + assert(privwin != NULL); + + privwin->occupant_offline = TRUE; + Jid *jidp = jid_create(privwin->fulljid); + win_vprint((ProfWin*)privwin, '-', 0, NULL, 0, THEME_OFFLINE, NULL, "-- %s has left the room.", jidp->resourcepart); + jid_destroy(jidp); +} + +void +privwin_occupant_online(ProfPrivateWin *privwin) +{ + assert(privwin != NULL); + + privwin->occupant_offline = FALSE; + Jid *jidp = jid_create(privwin->fulljid); + win_vprint((ProfWin*)privwin, '-', 0, NULL, 0, THEME_ONLINE, NULL, "-- %s has joined the room.", jidp->resourcepart); + jid_destroy(jidp); +} + char* privwin_get_string(ProfPrivateWin *privwin) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 835fd890..028eaa25 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -194,7 +194,11 @@ char* mucwin_get_string(ProfMucWin *mucwin); // MUC private chat window void privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDateTime *timestamp); void privwin_outgoing_msg(ProfPrivateWin *privwin, const char *const message); +void privwin_message_occupant_offline(ProfPrivateWin *privwin); + char* privwin_get_string(ProfPrivateWin *privwin); +void privwin_occupant_offline(ProfPrivateWin *privwin); +void privwin_occupant_online(ProfPrivateWin *privwin); // MUC room config window void mucconfwin_handle_configuration(ProfMucConfWin *confwin, DataForm *form); diff --git a/src/ui/win_types.h b/src/ui/win_types.h index 53b5f49a..0e9f81d7 100644 --- a/src/ui/win_types.h +++ b/src/ui/win_types.h @@ -137,6 +137,7 @@ typedef struct prof_private_win_t { int unread; gboolean notify; unsigned long memcheck; + gboolean occupant_offline; } ProfPrivateWin; typedef struct prof_xml_win_t { diff --git a/src/ui/window.c b/src/ui/window.c index 33ea86e0..8ae04499 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -220,6 +220,7 @@ win_create_private(const char *const fulljid) new_win->fulljid = strdup(fulljid); new_win->unread = 0; new_win->notify = FALSE; + new_win->occupant_offline = FALSE; new_win->memcheck = PROFPRIVATEWIN_MEMCHECK; @@ -1098,7 +1099,7 @@ _win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *tim } } - if (strlen(from) > 0) { + if (from && strlen(from) > 0) { if (flags & NO_ME) { colour = theme_attrs(THEME_THEM); } From 3ddef99dfe7948a9ba657dc6d34f5213ed0f00c5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 2 Feb 2016 22:25:55 +0000 Subject: [PATCH 2/3] Handle occupant kicked/banned in private chat wins --- src/event/server_events.c | 16 ++++++++++++ src/ui/privwin.c | 48 +++++++++++++++++++++++++++++++++++- src/ui/ui.h | 2 ++ tests/unittests/ui/stub_ui.c | 6 +++++ 4 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index e6738833..17754272 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -686,6 +686,14 @@ sv_ev_room_occupent_kicked(const char *const room, const char *const nick, const if (mucwin) { mucwin_occupant_kicked(mucwin, nick, actor, reason); } + + Jid *jidp = jid_create_from_bare_and_resource(room, nick); + ProfPrivateWin *privwin = wins_get_private(jidp->fulljid); + jid_destroy(jidp); + if (privwin != NULL) { + privwin_occupant_kicked(privwin, actor, reason); + } + occupantswin_occupants(room); rosterwin_roster(); } @@ -699,6 +707,14 @@ sv_ev_room_occupent_banned(const char *const room, const char *const nick, const if (mucwin) { mucwin_occupant_banned(mucwin, nick, actor, reason); } + + Jid *jidp = jid_create_from_bare_and_resource(room, nick); + ProfPrivateWin *privwin = wins_get_private(jidp->fulljid); + jid_destroy(jidp); + if (privwin != NULL) { + privwin_occupant_banned(privwin, actor, reason); + } + occupantswin_occupants(room); rosterwin_roster(); } diff --git a/src/ui/privwin.c b/src/ui/privwin.c index 4b8217e2..6a249091 100644 --- a/src/ui/privwin.c +++ b/src/ui/privwin.c @@ -126,10 +126,56 @@ privwin_occupant_offline(ProfPrivateWin *privwin) privwin->occupant_offline = TRUE; Jid *jidp = jid_create(privwin->fulljid); - win_vprint((ProfWin*)privwin, '-', 0, NULL, 0, THEME_OFFLINE, NULL, "-- %s has left the room.", jidp->resourcepart); + win_vprint((ProfWin*)privwin, '-', 0, NULL, 0, THEME_OFFLINE, NULL, "<- %s has left the room.", jidp->resourcepart); jid_destroy(jidp); } +void +privwin_occupant_kicked(ProfPrivateWin *privwin, const char *const actor, const char *const reason) +{ + assert(privwin != NULL); + + privwin->occupant_offline = TRUE; + Jid *jidp = jid_create(privwin->fulljid); + GString *message = g_string_new(jidp->resourcepart); + jid_destroy(jidp); + g_string_append(message, " has been kicked from the room"); + 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, NULL, "<- %s", message->str); + g_string_free(message, TRUE); +} + +void +privwin_occupant_banned(ProfPrivateWin *privwin, const char *const actor, const char *const reason) +{ + assert(privwin != NULL); + + privwin->occupant_offline = TRUE; + Jid *jidp = jid_create(privwin->fulljid); + GString *message = g_string_new(jidp->resourcepart); + jid_destroy(jidp); + g_string_append(message, " has been banned from the room"); + 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, NULL, "<- %s", message->str); + g_string_free(message, TRUE); +} + void privwin_occupant_online(ProfPrivateWin *privwin) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 028eaa25..91ee4d37 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -198,6 +198,8 @@ void privwin_message_occupant_offline(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); // MUC room config window diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 015e0024..2e7ec7b1 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -168,6 +168,12 @@ void chatwin_outgoing_msg(ProfChatWin *chatwin, const char * const message, char void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char * const message) {} void privwin_outgoing_msg(ProfPrivateWin *privwin, const char * const message) {} +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_message_occupant_offline(ProfPrivateWin *privwin) {} + void ui_room_join(const char * const roomjid, gboolean focus) {} void ui_switch_to_room(const char * const roomjid) {} From 292c9cf4540dd1c3010cda128ce47d67b8011755 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 2 Feb 2016 23:25:26 +0000 Subject: [PATCH 3/3] Handle occupant nick change in private wins --- src/event/server_events.c | 2 ++ src/window_list.c | 24 ++++++++++++++++++++++++ src/window_list.h | 1 + 3 files changed, 27 insertions(+) diff --git a/src/event/server_events.c b/src/event/server_events.c index 17754272..35466be3 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -850,7 +850,9 @@ sv_ev_muc_occupant_online(const char *const room, const char *const nick, const if (mucwin) { mucwin_occupant_nick_change(mucwin, old_nick, nick); } + wins_private_nick_change(mucwin->roomjid, old_nick, nick); free(old_nick); + occupantswin_occupants(room); rosterwin_roster(); return; diff --git a/src/window_list.c b/src/window_list.c index 2acfd0fb..e4ef8a64 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -197,6 +197,30 @@ wins_get_private_chats(const char *const roomjid) return result; } +void +wins_private_nick_change(const char *const roomjid, const char *const oldnick, const char *const newnick) +{ + Jid *oldjid = jid_create_from_bare_and_resource(roomjid, oldnick); + + ProfPrivateWin *privwin = wins_get_private(oldjid->fulljid); + if (privwin) { + free(privwin->fulljid); + + Jid *newjid = jid_create_from_bare_and_resource(roomjid, newnick); + privwin->fulljid = strdup(newjid->fulljid); + win_vprint((ProfWin*)privwin, '!', 0, NULL, 0, THEME_THEM, NULL, "** %s is now known as %s.", oldjid->resourcepart, newjid->resourcepart); + + autocomplete_remove(wins_ac, oldjid->fulljid); + autocomplete_remove(wins_close_ac, oldjid->fulljid); + autocomplete_add(wins_ac, newjid->fulljid); + autocomplete_add(wins_close_ac, newjid->fulljid); + + jid_destroy(newjid); + } + + jid_destroy(oldjid); +} + ProfWin* wins_get_current(void) { diff --git a/src/window_list.h b/src/window_list.h index 0d20d714..3c4c29fe 100644 --- a/src/window_list.h +++ b/src/window_list.h @@ -47,6 +47,7 @@ ProfWin* wins_new_private(const char *const fulljid); gboolean wins_chat_exists(const char *const barejid); GList* wins_get_private_chats(const char *const roomjid); +void wins_private_nick_change(const char *const roomjid, const char *const oldnick, const char *const newnick); ProfWin* wins_get_console(void); ProfChatWin* wins_get_chat(const char *const barejid);