mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-27 06:22:07 +01:00
SMACK-269 Added storing links by base and full JID so incoming messages with no thread ID can attempt to match full JID, and then try base JID before creating a new chat.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_2_0@12028 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
6d695e4151
commit
1735aa50eb
1 changed files with 32 additions and 8 deletions
|
@ -20,6 +20,13 @@
|
||||||
|
|
||||||
package org.jivesoftware.smack;
|
package org.jivesoftware.smack;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.WeakHashMap;
|
||||||
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.filter.AndFilter;
|
import org.jivesoftware.smack.filter.AndFilter;
|
||||||
import org.jivesoftware.smack.filter.FromContainsFilter;
|
import org.jivesoftware.smack.filter.FromContainsFilter;
|
||||||
import org.jivesoftware.smack.filter.PacketFilter;
|
import org.jivesoftware.smack.filter.PacketFilter;
|
||||||
|
@ -29,9 +36,6 @@ import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
import org.jivesoftware.smack.util.collections.ReferenceMap;
|
import org.jivesoftware.smack.util.collections.ReferenceMap;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The chat manager keeps track of references to all current chats. It will not hold any references
|
* The chat manager keeps track of references to all current chats. It will not hold any references
|
||||||
* in memory on its own so it is neccesary to keep a reference to the chat object itself. To be
|
* in memory on its own so it is neccesary to keep a reference to the chat object itself. To be
|
||||||
|
@ -65,14 +69,20 @@ public class ChatManager {
|
||||||
/**
|
/**
|
||||||
* Maps thread ID to chat.
|
* Maps thread ID to chat.
|
||||||
*/
|
*/
|
||||||
private Map<String, Chat> threadChats = new ReferenceMap<String, Chat>(ReferenceMap.HARD,
|
private Map<String, Chat> threadChats = Collections.synchronizedMap(new ReferenceMap<String, Chat>(ReferenceMap.HARD,
|
||||||
ReferenceMap.WEAK);
|
ReferenceMap.WEAK));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps jids to chats
|
* Maps jids to chats
|
||||||
*/
|
*/
|
||||||
private Map<String, Chat> jidChats = new ReferenceMap<String, Chat>(ReferenceMap.HARD,
|
private Map<String, Chat> jidChats = Collections.synchronizedMap(new ReferenceMap<String, Chat>(ReferenceMap.HARD,
|
||||||
ReferenceMap.WEAK);
|
ReferenceMap.WEAK));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps base jids to chats
|
||||||
|
*/
|
||||||
|
private Map<String, Chat> baseJidChats = Collections.synchronizedMap(new ReferenceMap<String, Chat>(ReferenceMap.HARD,
|
||||||
|
ReferenceMap.WEAK));
|
||||||
|
|
||||||
private Set<ChatManagerListener> chatManagerListeners
|
private Set<ChatManagerListener> chatManagerListeners
|
||||||
= new CopyOnWriteArraySet<ChatManagerListener>();
|
= new CopyOnWriteArraySet<ChatManagerListener>();
|
||||||
|
@ -161,6 +171,7 @@ public class ChatManager {
|
||||||
Chat chat = new Chat(this, userJID, threadID);
|
Chat chat = new Chat(this, userJID, threadID);
|
||||||
threadChats.put(threadID, chat);
|
threadChats.put(threadID, chat);
|
||||||
jidChats.put(userJID, chat);
|
jidChats.put(userJID, chat);
|
||||||
|
baseJidChats.put(StringUtils.parseBareAddress(userJID), chat);
|
||||||
|
|
||||||
for(ChatManagerListener listener : chatManagerListeners) {
|
for(ChatManagerListener listener : chatManagerListeners) {
|
||||||
listener.chatCreated(chat, createdLocally);
|
listener.chatCreated(chat, createdLocally);
|
||||||
|
@ -179,8 +190,21 @@ public class ChatManager {
|
||||||
return createChat(userJID, threadID, false);
|
return createChat(userJID, threadID, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to get a matching chat for the given user JID. Try the full
|
||||||
|
* JID map first, the try to match on the base JID if no match is
|
||||||
|
* found.
|
||||||
|
*
|
||||||
|
* @param userJID
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
private Chat getUserChat(String userJID) {
|
private Chat getUserChat(String userJID) {
|
||||||
return jidChats.get(userJID);
|
Chat match = jidChats.get(userJID);
|
||||||
|
|
||||||
|
if (match == null) {
|
||||||
|
match = baseJidChats.get(StringUtils.parseBareAddress(userJID));
|
||||||
|
}
|
||||||
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chat getThreadChat(String thread) {
|
public Chat getThreadChat(String thread) {
|
||||||
|
|
Loading…
Reference in a new issue