diff options
author | James Booth <boothj5@gmail.com> | 2015-01-11 23:04:22 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-01-11 23:04:22 +0000 |
commit | 13f0166aa04bce5e64803900d8554c92b6f3c667 (patch) | |
tree | 220f1afb5f143b89886b18c24ec75c918606a9f1 | |
parent | c16871d143a00eeb04d40e7b4ab20590b8ae93c6 (diff) | |
download | profani-tty-13f0166aa04bce5e64803900d8554c92b6f3c667.tar.gz |
Only show UI events for chat states when in session
-rw-r--r-- | src/chat_session.c | 36 | ||||
-rw-r--r-- | src/chat_session.h | 8 | ||||
-rw-r--r-- | src/command/commands.c | 4 | ||||
-rw-r--r-- | src/server_events.c | 20 | ||||
-rw-r--r-- | src/server_events.h | 2 | ||||
-rw-r--r-- | src/ui/core.c | 45 | ||||
-rw-r--r-- | src/ui/ui.h | 4 | ||||
-rw-r--r-- | src/xmpp/message.c | 2 |
8 files changed, 89 insertions, 32 deletions
diff --git a/src/chat_session.c b/src/chat_session.c index 57eef097..fbe06f76 100644 --- a/src/chat_session.c +++ b/src/chat_session.c @@ -88,7 +88,7 @@ chat_sessions_clear(void) void chat_session_resource_override(const char * const barejid, const char * const resource) { - _chat_session_new(barejid, resource, TRUE, FALSE); + _chat_session_new(barejid, resource, TRUE, TRUE); } ChatSession* @@ -98,7 +98,39 @@ chat_session_get(const char * const barejid) } void -chat_session_on_recipient_activity(const char * const barejid, const char * const resource, +chat_session_recipient_gone(const char * const barejid, const char * const resource) +{ + assert(barejid != NULL); + assert(resource != NULL); + + ChatSession *session = g_hash_table_lookup(sessions, barejid); + if (session && g_strcmp0(session->resource, resource) == 0) { + if (!session->resource_override) { + chat_session_remove(barejid); + } + } +} + +void +chat_session_recipient_typing(const char * const barejid, const char * const resource) +{ + chat_session_recipient_active(barejid, resource, TRUE); +} + +void +chat_session_recipient_paused(const char * const barejid, const char * const resource) +{ + chat_session_recipient_active(barejid, resource, TRUE); +} + +void +chat_session_recipient_inactive(const char * const barejid, const char * const resource) +{ + chat_session_recipient_active(barejid, resource, TRUE); +} + +void +chat_session_recipient_active(const char * const barejid, const char * const resource, gboolean send_states) { assert(barejid != NULL); diff --git a/src/chat_session.h b/src/chat_session.h index 1734bdd6..585a523b 100644 --- a/src/chat_session.h +++ b/src/chat_session.h @@ -50,8 +50,14 @@ void chat_sessions_clear(void); void chat_session_resource_override(const char * const barejid, const char * const resource); ChatSession* chat_session_get(const char * const barejid); -void chat_session_on_recipient_activity(const char * const barejid, const char * const resource, + +void chat_session_recipient_active(const char * const barejid, const char * const resource, gboolean send_states); +void chat_session_recipient_typing(const char * const barejid, const char * const resource); +void chat_session_recipient_paused(const char * const barejid, const char * const resource); +void chat_session_recipient_gone(const char * const barejid, const char * const resource); +void chat_session_recipient_inactive(const char * const barejid, const char * const resource); + void chat_session_remove(const char * const barejid); #endif diff --git a/src/command/commands.c b/src/command/commands.c index 08bd31cf..21b3a567 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1624,11 +1624,15 @@ cmd_resource(gchar **args, struct cmd_help_t help) } chatwin->resource_override = strdup(resource); + chat_state_free(chatwin->state); + chatwin->state = chat_state_new(); chat_session_resource_override(chatwin->barejid, resource); return TRUE; } else if (g_strcmp0(cmd, "off") == 0) { FREE_SET_NULL(chatwin->resource_override); + chat_state_free(chatwin->state); + chatwin->state = chat_state_new(); chat_session_remove(chatwin->barejid); return TRUE; } else { diff --git a/src/server_events.c b/src/server_events.c index 1caa0f1f..fbf534ac 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -388,17 +388,17 @@ handle_delayed_message(char *barejid, char *message, GTimeVal tv_stamp) void handle_typing(char *barejid, char *resource) { + ui_contact_typing(barejid, resource); if (ui_chat_win_exists(barejid)) { - chat_session_on_recipient_activity(barejid, resource, TRUE); + chat_session_recipient_typing(barejid, resource); } - ui_contact_typing(barejid); } void handle_paused(char *barejid, char *resource) { if (ui_chat_win_exists(barejid)) { - chat_session_on_recipient_activity(barejid, resource, TRUE); + chat_session_recipient_paused(barejid, resource); } } @@ -406,21 +406,25 @@ void handle_inactive(char *barejid, char *resource) { if (ui_chat_win_exists(barejid)) { - chat_session_on_recipient_activity(barejid, resource, TRUE); + chat_session_recipient_inactive(barejid, resource); } } void -handle_gone(const char * const barejid) +handle_gone(const char * const barejid, const char * const resource) { - chat_session_remove(barejid); - ui_recipient_gone(barejid); + ui_recipient_gone(barejid, resource); + if (ui_chat_win_exists(barejid)) { + chat_session_recipient_gone(barejid, resource); + } } void handle_activity(const char * const barejid, const char * const resource, gboolean send_states) { - chat_session_on_recipient_activity(barejid, resource, send_states); + if (ui_chat_win_exists(barejid)) { + chat_session_recipient_active(barejid, resource, send_states); + } } void diff --git a/src/server_events.h b/src/server_events.h index a4776721..6a12dc6e 100644 --- a/src/server_events.h +++ b/src/server_events.h @@ -77,7 +77,7 @@ void handle_typing(char *barejid, char *resource); void handle_paused(char *barejid, char *resource); void handle_inactive(char *barejid, char *resource); void handle_activity(char *barejid, char *resource, gboolean send_states); -void handle_gone(const char * const barejid); +void handle_gone(const char * const barejid, const char * const resource); void handle_subscription(const char *from, jabber_subscr_t type); void handle_contact_offline(char *contact, char *resource, char *status); void handle_contact_online(char *contact, Resource *resource, diff --git a/src/ui/core.c b/src/ui/core.c index d9cb2d8e..cc3dc167 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -280,10 +280,11 @@ ui_chat_win_exists(const char * const barejid) } void -ui_contact_typing(const char * const barejid) +ui_contact_typing(const char * const barejid, const char * const resource) { ProfChatWin *chatwin = wins_get_chat(barejid); ProfWin *window = (ProfWin*) chatwin; + ChatSession *session = chat_session_get(barejid); if (prefs_get_boolean(PREF_INTYPE)) { // no chat window for user @@ -294,8 +295,8 @@ ui_contact_typing(const char * const barejid) } else if (!wins_is_current(window)) { cons_show_typing(barejid); - // in chat window with user - } else { + // in chat window with user, no session or session with resource + } else if (!session || (session && g_strcmp0(session->resource, resource) == 0)) { title_bar_set_typing(TRUE); int num = wins_get_num(window); @@ -1272,26 +1273,36 @@ ui_print_system_msg_from_recipient(const char * const barejid, const char *messa } void -ui_recipient_gone(const char * const barejid) +ui_recipient_gone(const char * const barejid, const char * const resource) { if (barejid == NULL) return; + if (resource == NULL) + return; - const char * display_usr = NULL; - PContact contact = roster_get_contact(barejid); - if (contact != NULL) { - if (p_contact_name(contact) != NULL) { - display_usr = p_contact_name(contact); - } else { - display_usr = barejid; + gboolean show_message = TRUE; + + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + ChatSession *session = chat_session_get(barejid); + if (session && g_strcmp0(session->resource, resource) != 0) { + show_message = FALSE; } - } else { - display_usr = barejid; - } + if (show_message) { + const char * display_usr = NULL; + PContact contact = roster_get_contact(barejid); + if (contact != NULL) { + if (p_contact_name(contact) != NULL) { + display_usr = p_contact_name(contact); + } else { + display_usr = barejid; + } + } else { + display_usr = barejid; + } - ProfWin *window = (ProfWin*)wins_get_chat(barejid); - if (window != NULL) { - win_save_vprint(window, '!', NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr); + win_save_vprint((ProfWin*)chatwin, '!', NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr); + } } } diff --git a/src/ui/ui.h b/src/ui/ui.h index 0971f4f5..4d64342a 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -115,12 +115,12 @@ char * ui_ask_password(void); void ui_handle_stanza(const char * const msg); // ui events -void ui_contact_typing(const char * const from); +void ui_contact_typing(const char * const barejid, const char * const resource); void ui_incoming_msg(const char * const from, const char * const resource, const char * const message, GTimeVal *tv_stamp); void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp); void ui_disconnected(void); -void ui_recipient_gone(const char * const barejid); +void ui_recipient_gone(const char * const barejid, const char * const resource); void ui_outgoing_chat_msg(const char * const from, const char * const barejid, const char * const message); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 3b962a90..e96c1a74 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -486,7 +486,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, gboolean paused = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL; gboolean inactive = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL; if (gone) { - handle_gone(jid->barejid); + handle_gone(jid->barejid, jid->resourcepart); } else if (typing) { handle_typing(jid->barejid, jid->resourcepart); } else if (paused) { |