chatmanager.java
来自「开源项目openfire的完整源程序」· Java 代码 · 共 900 行 · 第 1/3 页
JAVA
900 行
chatRoom = getChatContainer().getChatRoom(StringUtils.parseBareAddress(from));
if (chatRoom != null && chatRoom instanceof ChatRoomImpl) {
typingNotificationList.add(chatRoom);
// Notify Decorators
notifySparkTabHandlers(chatRoom);
}
}
catch (ChatRoomNotFoundException e) {
}
contactList.setIconFor(from, SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE));
}
});
}
public void offlineNotification(String from, String packetID) {
}
public void cancelledNotification(final String from, String packetID) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ContactList contactList = SparkManager.getWorkspace().getContactList();
ChatRoom chatRoom = null;
try {
chatRoom = getChatContainer().getChatRoom(StringUtils.parseBareAddress(from));
if (chatRoom != null && chatRoom instanceof ChatRoomImpl) {
typingNotificationList.remove(chatRoom);
// Notify Decorators
notifySparkTabHandlers(chatRoom);
}
}
catch (ChatRoomNotFoundException e) {
}
contactList.useDefaults(from);
}
});
}
/**
* Adds a room where the user is typing.
*
* @param chatRoom the room where the user is typing.
*/
public void addTypingNotification(ChatRoom chatRoom) {
typingNotificationList.add(chatRoom);
}
/**
* Removes a room from the typing notification list.
*
* @param chatRoom the room to remove.
*/
public void removeTypingNotification(ChatRoom chatRoom) {
typingNotificationList.remove(chatRoom);
}
/**
* Returns true if the <code>ChatRoom</code> state is in typing mode.
*
* @param chatRoom the ChatRoom to check.
* @return true if in typing mode.
*/
public boolean containsTypingNotification(ChatRoom chatRoom) {
return typingNotificationList.contains(chatRoom);
}
/**
* Returns true if the room is "stale". A stale room is a room that has
* not been active for a specific amount of time.
*
* @param chatRoom the ChatRoom.
* @return true if the room is stale.
*/
public boolean isStaleRoom(ChatRoom chatRoom) {
// Check if room is stale
return chatContainer.getStaleChatRooms().contains(chatRoom);
}
/**
* Internal implementation of the MessageEventRequestListener.
*/
private class ChatMessageEventRequestListener implements MessageEventRequestListener {
public void deliveredNotificationRequested(String from, String packetID, MessageEventManager messageEventManager) {
}
public void displayedNotificationRequested(String from, String packetID, MessageEventManager messageEventManager) {
}
public void composingNotificationRequested(final String from, String packetID, MessageEventManager messageEventManager) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ChatRoom chatRoom;
try {
chatRoom = getChatContainer().getChatRoom(StringUtils.parseBareAddress(from));
}
catch (ChatRoomNotFoundException e) {
return;
}
if (chatRoom != null && chatRoom instanceof ChatRoomImpl) {
((ChatRoomImpl)chatRoom).setSendTypingNotification(true);
}
}
});
}
public void offlineNotificationRequested(String from, String packetID, MessageEventManager messageEventManager) {
// The XMPP server should take care of this request. Do nothing.
}
}
/**
* Adds a TranscriptWindowInterceptor.
*
* @param interceptor the interceptor.
*/
public void addTranscriptWindowInterceptor(TranscriptWindowInterceptor interceptor) {
interceptors.add(interceptor);
}
/**
* Removes a TranscriptWindowInterceptor.
*
* @param interceptor the interceptor.
*/
public void removeTranscriptWindowInterceptor(TranscriptWindowInterceptor interceptor) {
interceptors.remove(interceptor);
}
/**
* Returns the list of <code>TranscriptWindowInterceptors</code>.
*
* @return the list of interceptors.
*/
public Collection<TranscriptWindowInterceptor> getTranscriptWindowInterceptors() {
return interceptors;
}
/**
* Adds a new <code>ContainerDecorator</code>. The ContainerDecorator will be added to the top of the stack and will therefore
* take priority on notification calls. If all decorators return false, the <code>DefaultChatRoomDecorator</code> will be used.
*
* @param decorator the decorator to add.
*/
public void addSparkTabHandler(SparkTabHandler decorator) {
sparkTabHandlers.add(0, decorator);
}
/**
* Removes a <code>ContainerDecorator</code>
*
* @param decorator the decorator to remove.
*/
public void removeSparkTabHandler(SparkTabHandler decorator) {
sparkTabHandlers.remove(decorator);
}
/**
* Notifies all <code>ContainerDecorator</code>
*
* @param component the component within the tab.
*/
public void notifySparkTabHandlers(Component component) {
final SparkTab tab = chatContainer.getTabContainingComponent(component);
if (tab == null) {
return;
}
boolean isChatFrameInFocus = getChatContainer().getChatFrame().isInFocus();
boolean isSelectedTab = getChatContainer().getSelectedComponent() == component;
for (SparkTabHandler decorator : sparkTabHandlers) {
boolean isHandled = decorator.isTabHandled(tab, component, isSelectedTab, isChatFrameInFocus);
if (isHandled) {
tab.validateTab();
return;
}
}
}
/**
* Returns all selected users in the <code>ContactList</code>.
*
* @return all selected <code>ContactItem</code> in the ContactList.
*/
public Collection<ContactItem> getSelectedContactItems() {
final ContactList contactList = SparkManager.getWorkspace().getContactList();
return contactList.getSelectedUsers();
}
/**
* Handles XMPP URI Mappings.
*
* @param arguments the arguments passed into Spark.
*/
public void handleURIMapping(String arguments) {
if(arguments == null){
return;
}
if (arguments.indexOf("xmpp") == -1) {
return;
}
if (arguments.indexOf("?message") != -1) {
try {
handleJID(arguments);
}
catch (Exception e) {
Log.error(e);
}
}
else if (arguments.indexOf("?join") != -1) {
try {
handleConference(arguments);
}
catch (Exception e) {
Log.error(e);
}
}
else if (arguments.indexOf("?") == -1) {
// Then use the direct jid
int index = arguments.indexOf(":");
if (index != -1) {
String jid = arguments.substring(index + 1);
UserManager userManager = SparkManager.getUserManager();
String nickname = userManager.getUserNicknameFromJID(jid);
if (nickname == null) {
nickname = jid;
}
ChatManager chatManager = SparkManager.getChatManager();
ChatRoom chatRoom = chatManager.createChatRoom(jid, nickname, nickname);
chatManager.getChatContainer().activateChatRoom(chatRoom);
}
}
}
/**
* Factory method to handle different types of URI Mappings.
*
* @param uriMapping the uri mapping string.
*/
private void handleJID(String uriMapping) {
int index = uriMapping.indexOf("xmpp:");
int messageIndex = uriMapping.indexOf("?message");
int bodyIndex = uriMapping.indexOf("body=");
String jid = uriMapping.substring(index + 5, messageIndex);
String body = null;
// Find body
if (bodyIndex != -1) {
body = uriMapping.substring(bodyIndex + 5);
}
body = org.jivesoftware.spark.util.StringUtils.unescapeFromXML(body);
body = org.jivesoftware.spark.util.StringUtils.replace(body, "%20", " ");
UserManager userManager = SparkManager.getUserManager();
String nickname = userManager.getUserNicknameFromJID(jid);
if (nickname == null) {
nickname = jid;
}
ChatManager chatManager = SparkManager.getChatManager();
ChatRoom chatRoom = chatManager.createChatRoom(jid, nickname, nickname);
if (body != null) {
Message message = new Message();
message.setBody(body);
chatRoom.sendMessage(message);
}
chatManager.getChatContainer().activateChatRoom(chatRoom);
}
/**
* Handles the URI Mapping to join a conference room.
*
* @param uriMapping the uri mapping.
* @throws Exception thrown if the conference cannot be joined.
*/
private void handleConference(String uriMapping) {
int index = uriMapping.indexOf("xmpp:");
int join = uriMapping.indexOf("?join");
String conference = uriMapping.substring(index + 5, join);
ConferenceUtils.joinConferenceOnSeperateThread(conference, conference, null);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?