about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-01-10 21:07:40 +0000
committerJames Booth <boothj5@gmail.com>2015-01-10 21:07:40 +0000
commit965e82b35057414f93c75eb038c2402e019a6777 (patch)
tree08226ed7648bdfa5bf6a04eadf4a4e868bc2b8d9 /src
parent7256e49396c4d5f06de591a03c9e455ffa243b2f (diff)
downloadprofani-tty-965e82b35057414f93c75eb038c2402e019a6777.tar.gz
Added resource override for chat sessions
Diffstat (limited to 'src')
-rw-r--r--src/chat_session.c21
-rw-r--r--src/chat_session.h3
-rw-r--r--src/command/commands.c13
-rw-r--r--src/ui/core.c2
4 files changed, 19 insertions, 20 deletions
diff --git a/src/chat_session.c b/src/chat_session.c
index 777621e1..7b80fd7a 100644
--- a/src/chat_session.c
+++ b/src/chat_session.c
@@ -46,7 +46,8 @@
 static GHashTable *sessions;
 
 static void
-_chat_session_new(const char * const barejid, const char * const resource, gboolean send_states)
+_chat_session_new(const char * const barejid, const char * const resource,
+    gboolean resource_override, gboolean send_states)
 {
     assert(barejid != NULL);
     assert(resource != NULL);
@@ -54,9 +55,10 @@ _chat_session_new(const char * const barejid, const char * const resource, gbool
     ChatSession *new_session = malloc(sizeof(struct chat_session_t));
     new_session->barejid = strdup(barejid);
     new_session->resource = strdup(resource);
+    new_session->resource_override = resource_override;
     new_session->send_states = send_states;
 
-    g_hash_table_insert(sessions, strdup(barejid), new_session);
+    g_hash_table_replace(sessions, strdup(barejid), new_session);
 }
 
 static void
@@ -83,6 +85,12 @@ chat_sessions_clear(void)
         g_hash_table_remove_all(sessions);
 }
 
+void
+chat_session_resource_override(const char * const barejid, const char * const resource)
+{
+    _chat_session_new(barejid, resource, TRUE, FALSE);
+}
+
 ChatSession*
 chat_session_get(const char * const barejid)
 {
@@ -100,15 +108,14 @@ chat_session_on_recipient_activity(const char * const barejid, const char * cons
         // session exists with resource, do nothing
         if (g_strcmp0(session->resource, resource) == 0) {
             return;
-        // session exists with differet resource, replace
-        } else {
-            g_hash_table_remove(sessions, barejid);
-            _chat_session_new(barejid, resource, FALSE);
+        // session exists with differet resource and no override, replace
+        } else if (!session->resource_override) {
+            _chat_session_new(barejid, resource, FALSE, FALSE);
         }
 
     // no session, create one
     } else {
-        _chat_session_new(barejid, resource, FALSE);
+        _chat_session_new(barejid, resource, FALSE, FALSE);
     }
 }
 
diff --git a/src/chat_session.h b/src/chat_session.h
index 80c6d55e..2185fa4c 100644
--- a/src/chat_session.h
+++ b/src/chat_session.h
@@ -40,12 +40,15 @@
 typedef struct chat_session_t {
     char *barejid;
     char *resource;
+    gboolean resource_override;
     gboolean send_states;
+
 } ChatSession;
 
 void chat_sessions_init(void);
 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_remove(const char * const barejid);
diff --git a/src/command/commands.c b/src/command/commands.c
index 12c6ba48..08bd31cf 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1203,17 +1203,6 @@ cmd_msg(gchar **args, struct cmd_help_t help)
             barejid = usr;
         }
 
-        // TODO if msg to current recipient, and resource specified, set resource
-//        char *resource = NULL;
-//        ProfWin *current = wins_get_current();
-//        if (current->type == WIN_CHAT) {
-//            ProfChatWin *chatwin = (ProfChatWin*)current;
-//            assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
-//            if ((g_strcmp0(chatwin->barejid, barejid) == 0) && (chatwin->resource)) {
-//                resource = chatwin->resource;
-//            }
-//        }
-
         if (msg != NULL) {
 #ifdef HAVE_LIBOTR
             if (otr_is_secure(barejid)) {
@@ -1635,10 +1624,12 @@ cmd_resource(gchar **args, struct cmd_help_t help)
         }
 
         chatwin->resource_override = strdup(resource);
+        chat_session_resource_override(chatwin->barejid, resource);
         return TRUE;
 
     } else if (g_strcmp0(cmd, "off") == 0) {
         FREE_SET_NULL(chatwin->resource_override);
+        chat_session_remove(chatwin->barejid);
         return TRUE;
     } else {
         cons_show("Usage: %s", help.usage);
diff --git a/src/ui/core.c b/src/ui/core.c
index 4866a8f2..30ec8749 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -931,8 +931,6 @@ ui_gone_secure(const char * const barejid, gboolean trusted)
         chatwin = (ProfChatWin*)window;
     }
 
-    FREE_SET_NULL(chatwin->resource_override);
-
     chatwin->is_otr = TRUE;
     chatwin->is_trusted = trusted;
     if (trusted) {