diff options
author | James Booth <boothj5@gmail.com> | 2015-01-10 22:03:40 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-01-10 22:03:40 +0000 |
commit | 76bd2ec13f5ffc21ddf91eebf3cb2e6dafe3ad75 (patch) | |
tree | 1cb60e775ca539479e373181910018908a9daa0e | |
parent | 965e82b35057414f93c75eb038c2402e019a6777 (diff) | |
download | profani-tty-76bd2ec13f5ffc21ddf91eebf3cb2e6dafe3ad75.tar.gz |
Send active chat state, handle composing and gone from recipients
-rw-r--r-- | src/chat_session.c | 11 | ||||
-rw-r--r-- | src/chat_session.h | 3 | ||||
-rw-r--r-- | src/chat_state.c | 52 | ||||
-rw-r--r-- | src/chat_state.h | 37 | ||||
-rw-r--r-- | src/server_events.c | 6 | ||||
-rw-r--r-- | src/xmpp/message.c | 46 | ||||
-rw-r--r-- | tests/test_chat_session.c | 8 | ||||
-rw-r--r-- | tests/test_cmd_disconnect.c | 4 | ||||
-rw-r--r-- | tests/test_server_events.c | 8 |
9 files changed, 42 insertions, 133 deletions
diff --git a/src/chat_session.c b/src/chat_session.c index 7b80fd7a..57eef097 100644 --- a/src/chat_session.c +++ b/src/chat_session.c @@ -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); } } diff --git a/src/chat_session.h b/src/chat_session.h index 2185fa4c..1734bdd6 100644 --- a/src/chat_session.h +++ b/src/chat_session.h @@ -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 diff --git a/src/chat_state.c b/src/chat_state.c deleted file mode 100644 index f8bf8a56..00000000 --- a/src/chat_state.c +++ /dev/null @@ -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; - diff --git a/src/chat_state.h b/src/chat_state.h deleted file mode 100644 index a916b796..00000000 --- a/src/chat_state.h +++ /dev/null @@ -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 - diff --git a/src/server_events.c b/src/server_events.c index a70a9a60..b5291ce5 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -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 diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 0d88603a..69c320ea 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -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) { diff --git a/tests/test_chat_session.c b/tests/test_chat_session.c index 6b40f7e3..828be248 100644 --- a/tests/test_chat_session.c +++ b/tests/test_chat_session.c @@ -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); diff --git a/tests/test_cmd_disconnect.c b/tests/test_cmd_disconnect.c index c0310cbf..2a16c805 100644 --- a/tests/test_cmd_disconnect.c +++ b/tests/test_cmd_disconnect.c @@ -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"); diff --git a/tests/test_server_events.c b/tests/test_server_events.c index 03119db0..bbc1026e 100644 --- a/tests/test_server_events.c +++ b/tests/test_server_events.c @@ -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(); |