1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00

Show message in private windows when user offline

This commit is contained in:
James Booth 2016-02-02 21:52:13 +00:00
parent f0837abf0a
commit 150015fa3d
7 changed files with 60 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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