1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Check for chat room window on muc events, log error when doesn't exist

issue #341
This commit is contained in:
James Booth 2014-08-20 21:30:10 +01:00
parent 7bac097d60
commit 9fd45059eb

View File

@ -1471,7 +1471,9 @@ static void
_ui_room_roster(const char * const room, GList *roster, const char * const presence) _ui_room_roster(const char * const room, GList *roster, const char * const presence)
{ {
ProfWin *window = wins_get_by_recipient(room); ProfWin *window = wins_get_by_recipient(room);
if (window == NULL) {
log_error("Received room roster but no window open for %s.", room);
} else {
if ((roster == NULL) || (g_list_length(roster) == 0)) { if ((roster == NULL) || (g_list_length(roster) == 0)) {
if (presence == NULL) { if (presence == NULL) {
win_save_print(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Room is empty."); win_save_print(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Room is empty.");
@ -1510,6 +1512,7 @@ _ui_room_roster(const char * const room, GList *roster, const char * const prese
if (wins_is_current(window)) { if (wins_is_current(window)) {
win_update_virtual(window); win_update_virtual(window);
} }
}
} }
static void static void
@ -1522,12 +1525,14 @@ static void
_ui_room_member_offline(const char * const room, const char * const nick) _ui_room_member_offline(const char * const room, const char * const nick)
{ {
ProfWin *window = wins_get_by_recipient(room); ProfWin *window = wins_get_by_recipient(room);
if (window == NULL) {
log_error("Received offline presence for room participant %s, but no window open for %s.", nick, room);
} else {
win_save_vprint(window, '!', NULL, 0, COLOUR_OFFLINE, "", "<- %s has left the room.", nick); win_save_vprint(window, '!', NULL, 0, COLOUR_OFFLINE, "", "<- %s has left the room.", nick);
if (wins_is_current(window)) { if (wins_is_current(window)) {
win_update_virtual(window); win_update_virtual(window);
} }
}
} }
static void static void
@ -1535,12 +1540,14 @@ _ui_room_member_online(const char * const room, const char * const nick,
const char * const show, const char * const status) const char * const show, const char * const status)
{ {
ProfWin *window = wins_get_by_recipient(room); ProfWin *window = wins_get_by_recipient(room);
if (window == NULL) {
log_error("Received online presence for room participant %s, but no window open for %s.", nick, room);
} else {
win_save_vprint(window, '!', NULL, 0, COLOUR_ONLINE, "", "-> %s has joined the room.", nick); win_save_vprint(window, '!', NULL, 0, COLOUR_ONLINE, "", "-> %s has joined the room.", nick);
if (wins_is_current(window)) { if (wins_is_current(window)) {
win_update_virtual(window); win_update_virtual(window);
} }
}
} }
static void static void
@ -1548,14 +1555,14 @@ _ui_room_member_presence(const char * const room, const char * const nick,
const char * const show, const char * const status) const char * const show, const char * const status)
{ {
ProfWin *window = wins_get_by_recipient(room); ProfWin *window = wins_get_by_recipient(room);
if (window == NULL) {
if (window != NULL) { log_error("Received presence for room participant %s, but no window open for %s.", nick, room);
} else {
win_show_status_string(window, nick, show, status, NULL, "++", "online"); win_show_status_string(window, nick, show, status, NULL, "++", "online");
}
if (wins_is_current(window)) { if (wins_is_current(window)) {
win_update_virtual(window); win_update_virtual(window);
} }
}
} }
static void static void
@ -1563,24 +1570,28 @@ _ui_room_member_nick_change(const char * const room,
const char * const old_nick, const char * const nick) const char * const old_nick, const char * const nick)
{ {
ProfWin *window = wins_get_by_recipient(room); ProfWin *window = wins_get_by_recipient(room);
if (window == NULL) {
log_error("Received nick change for room participant %s, but no window open for %s.", old_nick, room);
} else {
win_save_vprint(window, '!', NULL, 0, COLOUR_THEM, "", "** %s is now known as %s", old_nick, nick); win_save_vprint(window, '!', NULL, 0, COLOUR_THEM, "", "** %s is now known as %s", old_nick, nick);
if (wins_is_current(window)) { if (wins_is_current(window)) {
win_update_virtual(window); win_update_virtual(window);
} }
}
} }
static void static void
_ui_room_nick_change(const char * const room, const char * const nick) _ui_room_nick_change(const char * const room, const char * const nick)
{ {
ProfWin *window = wins_get_by_recipient(room); ProfWin *window = wins_get_by_recipient(room);
if (window == NULL) {
log_error("Received self nick change %s, but no window open for %s.", nick, room);
} else {
win_save_vprint(window, '!', NULL, 0, COLOUR_ME, "", "** You are now known as %s", nick); win_save_vprint(window, '!', NULL, 0, COLOUR_ME, "", "** You are now known as %s", nick);
if (wins_is_current(window)) { if (wins_is_current(window)) {
win_update_virtual(window); win_update_virtual(window);
} }
}
} }
static void static void
@ -1588,7 +1599,9 @@ _ui_room_history(const char * const room_jid, const char * const nick,
GTimeVal tv_stamp, const char * const message) GTimeVal tv_stamp, const char * const message)
{ {
ProfWin *window = wins_get_by_recipient(room_jid); ProfWin *window = wins_get_by_recipient(room_jid);
if (window == NULL) {
log_error("Room history message received from %s, but no window open for %s", nick, room_jid);
} else {
GString *line = g_string_new(""); GString *line = g_string_new("");
GDateTime *time = g_date_time_new_from_timeval_utc(&tv_stamp); GDateTime *time = g_date_time_new_from_timeval_utc(&tv_stamp);
@ -1614,6 +1627,7 @@ _ui_room_history(const char * const room_jid, const char * const nick,
if (wins_is_current(window)) { if (wins_is_current(window)) {
win_update_virtual(window); win_update_virtual(window);
} }
}
} }
static void static void
@ -1621,6 +1635,9 @@ _ui_room_message(const char * const room_jid, const char * const nick,
const char * const message) const char * const message)
{ {
ProfWin *window = wins_get_by_recipient(room_jid); ProfWin *window = wins_get_by_recipient(room_jid);
if (window == NULL) {
log_error("Room message received from %s, but no window open for %s", nick, room_jid);
} else {
int num = wins_get_num(window); int num = wins_get_num(window);
char *my_nick = muc_get_room_nick(room_jid); char *my_nick = muc_get_room_nick(room_jid);
@ -1702,12 +1719,16 @@ _ui_room_message(const char * const room_jid, const char * const nick,
win_move_to_end(current); win_move_to_end(current);
win_update_virtual(current); win_update_virtual(current);
} }
}
} }
static void static void
_ui_room_subject(const char * const room_jid, const char * const subject) _ui_room_subject(const char * const room_jid, const char * const subject)
{ {
ProfWin *window = wins_get_by_recipient(room_jid); ProfWin *window = wins_get_by_recipient(room_jid);
if (window == NULL) {
log_error("Received room subject, but no window open for %s.", room_jid);
} else {
int num = wins_get_num(window); int num = wins_get_num(window);
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "Room subject: "); win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "Room subject: ");
@ -1722,12 +1743,16 @@ _ui_room_subject(const char * const room_jid, const char * const subject)
} else { } else {
status_bar_active(num); status_bar_active(num);
} }
}
} }
static void static void
_ui_room_broadcast(const char * const room_jid, const char * const message) _ui_room_broadcast(const char * const room_jid, const char * const message)
{ {
ProfWin *window = wins_get_by_recipient(room_jid); ProfWin *window = wins_get_by_recipient(room_jid);
if (window == NULL) {
log_error("Received room broadcast, but no window open for %s.", room_jid);
} else {
int num = wins_get_num(window); int num = wins_get_num(window);
win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "Room message: "); win_save_vprint(window, '!', NULL, NO_EOL, COLOUR_ROOMINFO, "", "Room message: ");
@ -1742,6 +1767,7 @@ _ui_room_broadcast(const char * const room_jid, const char * const message)
} else { } else {
status_bar_new(num); status_bar_new(num);
} }
}
} }
static void static void