mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Send active chat state, handle composing and gone from recipients
This commit is contained in:
parent
965e82b350
commit
76bd2ec13f
@ -98,24 +98,25 @@ chat_session_get(const char * const barejid)
|
||||
}
|
||||
|
||||
void
|
||||
chat_session_on_recipient_activity(const char * const barejid, const char * const resource)
|
||||
chat_session_on_recipient_activity(const char * const barejid, const char * const resource,
|
||||
gboolean send_states)
|
||||
{
|
||||
assert(barejid != NULL);
|
||||
assert(resource != NULL);
|
||||
|
||||
ChatSession *session = g_hash_table_lookup(sessions, barejid);
|
||||
if (session) {
|
||||
// session exists with resource, do nothing
|
||||
// session exists with resource, update chat_states
|
||||
if (g_strcmp0(session->resource, resource) == 0) {
|
||||
return;
|
||||
session->send_states = send_states;
|
||||
// session exists with differet resource and no override, replace
|
||||
} else if (!session->resource_override) {
|
||||
_chat_session_new(barejid, resource, FALSE, FALSE);
|
||||
_chat_session_new(barejid, resource, FALSE, send_states);
|
||||
}
|
||||
|
||||
// no session, create one
|
||||
} else {
|
||||
_chat_session_new(barejid, resource, FALSE, FALSE);
|
||||
_chat_session_new(barejid, resource, FALSE, send_states);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,8 @@ 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 resourcepart);
|
||||
void chat_session_on_recipient_activity(const char * const barejid, const char * const resource,
|
||||
gboolean send_states);
|
||||
void chat_session_remove(const char * const barejid);
|
||||
|
||||
#endif
|
||||
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* chat_state.c
|
||||
*
|
||||
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* This file is part of Profanity.
|
||||
*
|
||||
* Profanity is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Profanity is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link the code of portions of this program with the OpenSSL library under
|
||||
* certain conditions as described in each individual source file, and
|
||||
* distribute linked combinations including the two.
|
||||
*
|
||||
* You must obey the GNU General Public License in all respects for all of the
|
||||
* code used other than OpenSSL. If you modify file(s) with this exception, you
|
||||
* may extend this exception to your version of the file(s), but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version. If you delete this exception statement from all
|
||||
* source files in the program, then also delete it here.
|
||||
*
|
||||
*/
|
||||
|
||||
// TODO make preferences
|
||||
#define PAUSED_SECS 30.0
|
||||
#define INACTIVE_SECS 120.0
|
||||
|
||||
typedef enum {
|
||||
CHAT_STATE_ACTIVE,
|
||||
CHAT_STATE_PAUSED,
|
||||
CHAT_STATE_COMPOSING,
|
||||
CHAT_STATE_INACTIVE,
|
||||
CHAT_STATE_GONE
|
||||
} chat_state_type_t;
|
||||
|
||||
typedef struct chat_state_t {
|
||||
chat_state_t state;
|
||||
GTimer *active_timer;
|
||||
gboolean sent;
|
||||
} ChatState;
|
||||
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* chat_state.h
|
||||
*
|
||||
* Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* This file is part of Profanity.
|
||||
*
|
||||
* Profanity is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Profanity is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link the code of portions of this program with the OpenSSL library under
|
||||
* certain conditions as described in each individual source file, and
|
||||
* distribute linked combinations including the two.
|
||||
*
|
||||
* You must obey the GNU General Public License in all respects for all of the
|
||||
* code used other than OpenSSL. If you modify file(s) with this exception, you
|
||||
* may extend this exception to your version of the file(s), but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version. If you delete this exception statement from all
|
||||
* source files in the program, then also delete it here.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CHAT_STATE_H
|
||||
#define CHAT_STATE_H
|
||||
|
@ -392,10 +392,10 @@ handle_typing(char *from)
|
||||
}
|
||||
|
||||
void
|
||||
handle_gone(const char * const from)
|
||||
handle_gone(const char * const barejid)
|
||||
{
|
||||
chat_session_remove(from);
|
||||
ui_recipient_gone(from);
|
||||
chat_session_remove(barejid);
|
||||
ui_recipient_gone(barejid);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -88,11 +88,19 @@ message_send_chat(const char * const barejid, const char * const msg)
|
||||
|
||||
ChatSession *session = chat_session_get(barejid);
|
||||
if (session) {
|
||||
char *state = NULL;
|
||||
if (prefs_get_boolean(PREF_STATES) && session->send_states) {
|
||||
state = STANZA_NAME_ACTIVE;
|
||||
}
|
||||
Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource);
|
||||
message = stanza_create_message(ctx, jidp->fulljid, STANZA_TYPE_CHAT, msg, NULL);
|
||||
message = stanza_create_message(ctx, jidp->fulljid, STANZA_TYPE_CHAT, msg, state);
|
||||
jid_destroy(jidp);
|
||||
} else {
|
||||
message = stanza_create_message(ctx, barejid, STANZA_TYPE_CHAT, msg, NULL);
|
||||
char *state = NULL;
|
||||
if (prefs_get_boolean(PREF_STATES)) {
|
||||
state = STANZA_NAME_ACTIVE;
|
||||
}
|
||||
message = stanza_create_message(ctx, barejid, STANZA_TYPE_CHAT, msg, state);
|
||||
}
|
||||
|
||||
xmpp_send(conn, message);
|
||||
@ -461,36 +469,24 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
GTimeVal tv_stamp;
|
||||
gboolean delayed = stanza_get_delay(stanza, &tv_stamp);
|
||||
|
||||
// handle chat sessions
|
||||
// handle chat sessions and states
|
||||
if (!delayed && jid->resourcepart) {
|
||||
gboolean recipient_gone = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL;
|
||||
if (recipient_gone) {
|
||||
chat_session_remove(jid->barejid);
|
||||
handle_gone(jid->barejid);
|
||||
} else {
|
||||
chat_session_on_recipient_activity(jid->barejid, jid->resourcepart);
|
||||
gboolean send_states = FALSE;
|
||||
if (stanza_contains_chat_state(stanza)) {
|
||||
send_states = TRUE;
|
||||
gboolean typing = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL;
|
||||
if (typing) {
|
||||
handle_typing(jid->barejid);
|
||||
}
|
||||
}
|
||||
chat_session_on_recipient_activity(jid->barejid, jid->resourcepart, send_states);
|
||||
}
|
||||
}
|
||||
|
||||
// // determine chatstate support of recipient
|
||||
// if (stanza_contains_chat_state(stanza)) {
|
||||
// chat_session_on_incoming_message(jid->barejid, jid->resourcepart, TRUE);
|
||||
// } else {
|
||||
// chat_session_on_incoming_message(jid->barejid, jid->resourcepart, FALSE);
|
||||
// }
|
||||
//
|
||||
// if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL) {
|
||||
// handle_typing(jid->barejid);
|
||||
// } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL) {
|
||||
// handle_gone(jid->barejid);
|
||||
// } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL) {
|
||||
// // do something
|
||||
// } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL) {
|
||||
// // do something
|
||||
// } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ACTIVE) != NULL) {
|
||||
// // do something
|
||||
// }
|
||||
// }
|
||||
|
||||
// check for and deal with message
|
||||
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
|
||||
if (body != NULL) {
|
||||
|
@ -18,7 +18,7 @@ void creates_chat_session_on_recipient_activity(void **state)
|
||||
char *barejid = "myjid@server.org";
|
||||
char *resource = "tablet";
|
||||
|
||||
chat_session_on_recipient_activity(barejid, resource);
|
||||
chat_session_on_recipient_activity(barejid, resource, FALSE);
|
||||
ChatSession *session = chat_session_get(barejid);
|
||||
|
||||
assert_non_null(session);
|
||||
@ -31,8 +31,8 @@ void replaces_chat_session_on_recipient_activity_with_different_resource(void **
|
||||
char *resource1 = "tablet";
|
||||
char *resource2 = "mobile";
|
||||
|
||||
chat_session_on_recipient_activity(barejid, resource1);
|
||||
chat_session_on_recipient_activity(barejid, resource2);
|
||||
chat_session_on_recipient_activity(barejid, resource1, FALSE);
|
||||
chat_session_on_recipient_activity(barejid, resource2, FALSE);
|
||||
ChatSession *session = chat_session_get(barejid);
|
||||
|
||||
assert_string_equal(session->resource, resource2);
|
||||
@ -43,7 +43,7 @@ void removes_chat_session(void **state)
|
||||
char *barejid = "myjid@server.org";
|
||||
char *resource1 = "laptop";
|
||||
|
||||
chat_session_on_recipient_activity(barejid, resource1);
|
||||
chat_session_on_recipient_activity(barejid, resource1, FALSE);
|
||||
chat_session_remove(barejid);
|
||||
ChatSession *session = chat_session_get(barejid);
|
||||
|
||||
|
@ -18,8 +18,8 @@ void clears_chat_sessions(void **state)
|
||||
|
||||
chat_sessions_init();
|
||||
roster_init();
|
||||
chat_session_on_recipient_activity("bob@server.org", "laptop");
|
||||
chat_session_on_recipient_activity("mike@server.org", "work");
|
||||
chat_session_on_recipient_activity("bob@server.org", "laptop", FALSE);
|
||||
chat_session_on_recipient_activity("mike@server.org", "work", FALSE);
|
||||
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
will_return(jabber_get_fulljid, "myjid@myserver.com");
|
||||
|
@ -133,7 +133,7 @@ void handle_message_error_when_recipient_cancel_disables_chat_session(void **sta
|
||||
|
||||
prefs_set_boolean(PREF_STATES, TRUE);
|
||||
chat_sessions_init();
|
||||
chat_session_on_recipient_activity(barejid, resource);
|
||||
chat_session_on_recipient_activity(barejid, resource, FALSE);
|
||||
|
||||
handle_message_error(barejid, type, err_msg);
|
||||
ChatSession *session = chat_session_get(barejid);
|
||||
@ -186,7 +186,7 @@ void handle_offline_removes_chat_session(void **state)
|
||||
roster_add(barejid, "bob", NULL, "both", FALSE);
|
||||
Resource *resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10);
|
||||
roster_update_presence(barejid, resourcep, NULL);
|
||||
chat_session_on_recipient_activity(barejid, resource);
|
||||
chat_session_on_recipient_activity(barejid, resource, FALSE);
|
||||
handle_contact_offline(barejid, resource, NULL);
|
||||
ChatSession *session = chat_session_get(barejid);
|
||||
|
||||
@ -199,8 +199,8 @@ void handle_offline_removes_chat_session(void **state)
|
||||
void lost_connection_clears_chat_sessions(void **state)
|
||||
{
|
||||
chat_sessions_init();
|
||||
chat_session_on_recipient_activity("bob@server.org", "laptop");
|
||||
chat_session_on_recipient_activity("steve@server.org", "mobile");
|
||||
chat_session_on_recipient_activity("bob@server.org", "laptop", FALSE);
|
||||
chat_session_on_recipient_activity("steve@server.org", "mobile", FALSE);
|
||||
expect_any_cons_show_error();
|
||||
|
||||
handle_lost_connection();
|
||||
|
Loading…
x
Reference in New Issue
Block a user