1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Only show UI events for chat states when in session

This commit is contained in:
James Booth 2015-01-11 23:04:22 +00:00
parent c16871d143
commit 13f0166aa0
8 changed files with 89 additions and 32 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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