Quantcast
Channel: Ignite Realtime: Message List
Viewing all articles
Browse latest Browse all 11412

Force ChatManager to obey threads in Messages

$
0
0

Quick background: I'm working on a bot with a strophe frontend. The bot can be interacted with directly, but the strophe client also uses it to manage a dashboard. In the strophe client, I am specifically setting a thread value on my messages as well as a unique resource when logging in. I log in with the same account Adium uses for my normal chat behavior. Every so often, I'd get bot responses in my Adium window while doing development on the dashboard. I tracked the reason down to Smack's internal chat management. If it can't find a chat that matches the thread, it uses one from the user or bare user cache (in order). Anyway, I wanted to be able to turn this behavior off. I made the following change in the ChatManager source for 3.3.1 (context provided), I'd be interested if this could become a core feature so I don't have to patch future versions:

 

***************

*** 91,96 ****

--- 91,98 ----

              = new WeakHashMap<PacketInterceptor, PacketFilter>();

 

      private Connection connection;

+    

+     private boolean strictThreadsResources = false;

 

      ChatManager(Connection connection) {

          this.connection = connection;

***************

*** 116,122 ****

                  }

                  else {

                      chat = getThreadChat(message.getThread());

!                     if (chat == null) {

                          // Try to locate the chat based on the sender of the message

                                chat = getUserChat(message.getFrom());

                      }

--- 118,124 ----

                  }

                  else {

                      chat = getThreadChat(message.getThread());

!                     if (chat == null && !strictThreadsResources) {

                          // Try to locate the chat based on the sender of the message

                                chat = getUserChat(message.getFrom());

                      }

***************

*** 129,134 ****

--- 131,148 ----

              }

          }, filter);

      }

+    

+     /**

+      * Force smack to not fall back to user chat matching when looking up a matching

+      * chat for messages with a thread. If the thread don't match, create a new chat

+      */

+     public void setStrictThreadsResources(boolean strict) {

+         strictThreadsResources = strict;

+     }

+    

+     public boolean getStrictThreadsResources() {

+         return strictThreadsResources;

+     }

 

      /**

       * Creates a new chat and returns it.


Viewing all articles
Browse latest Browse all 11412

Trending Articles