1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Handle self leaving room in private wins

This commit is contained in:
James Booth 2016-02-03 00:11:38 +00:00
parent 292c9cf454
commit 77e819e81a
6 changed files with 154 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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