Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 4b891826b256e4ac8df37711d9e1633dd392d01b Mon Sep 17 00:00:00 2001
- From: Quoc Viet <vietnq@exoplatform.com>
- Date: Mon, 20 Aug 2012 08:59:16 +0700
- Subject: [PATCH] cs-5643 tmp
- ---
- .../exoplatform/services/xmpp/bean/InviteBean.java | 30 ++++++++++++-
- .../services/xmpp/connection/XMPPSession.java | 7 +++-
- .../xmpp/connection/impl/XMPPSessionImpl.java | 31 +++++++++++--
- .../services/xmpp/rest/RESTXMPPService.java | 47 +++++++++++++++++++-
- .../communication/chat/core/XMPPCommunicator.js | 20 ++++++++
- .../eXo/communication/chat/webui/UIChatWindow.js | 36 ---------------
- .../communication/chat/webui/UIMainChatWindow.js | 25 ++++++++++
- 7 files changed, 153 insertions(+), 43 deletions(-)
- diff --git a/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/bean/InviteBean.java b/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/bean/InviteBean.java
- index afdec4b..f4061d9 100644
- --- a/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/bean/InviteBean.java
- +++ b/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/bean/InviteBean.java
- @@ -33,13 +33,23 @@ public class InviteBean {
- *
- */
- private String inviter;
- +
- + private String inviterName;
- /**
- *
- */
- private String reason;
- - /**
- + public String getInviterName() {
- + return inviterName;
- +}
- +
- +public void setInviterName(String inviterName) {
- + this.inviterName = inviterName;
- +}
- +
- +/**
- *
- */
- private String password;
- @@ -70,6 +80,24 @@ public class InviteBean {
- this.reason = reason;
- this.room = room;
- }
- + /**
- + * @since CS-5643
- + * @param inviter
- + * @param inviterName
- + * @param message
- + * @param password
- + * @param reason
- + * @param room
- + */
- + public InviteBean(String inviter, String inviterName, MessageBean message, String password, String reason, String room) {
- + super();
- + this.inviter = inviter;
- + this.inviterName = inviterName;
- + this.message = message;
- + this.password = password;
- + this.reason = reason;
- + this.room = room;
- + }
- /**
- * @return the room
- diff --git a/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/connection/XMPPSession.java b/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/connection/XMPPSession.java
- index a4f1443..3150dd0 100755
- --- a/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/connection/XMPPSession.java
- +++ b/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/connection/XMPPSession.java
- @@ -19,7 +19,8 @@ package org.exoplatform.services.xmpp.connection;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- -
- +import org.exoplatform.services.xmpp.bean.EventsBean;
- +import org.exoplatform.services.xmpp.bean.MessageBean;
- import org.exoplatform.services.xmpp.bean.ConfigRoomBean;
- import org.exoplatform.services.xmpp.bean.FormBean;
- import org.exoplatform.services.xmpp.bean.FullRoomInfoBean;
- @@ -44,6 +45,10 @@ import org.jivesoftware.smackx.muc.RoomInfo;
- * @version $Id: $
- */
- public interface XMPPSession {
- +
- + public Map<String, EventsBean> getMessageMap();
- +
- + public void sendMessageToCometd(EventsBean eventsBean);
- /**
- * Check is <code>Transport</code> supported and add it to <code>List</code>
- diff --git a/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/connection/impl/XMPPSessionImpl.java b/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/connection/impl/XMPPSessionImpl.java
- index 2392fe6..7365f9f 100755
- --- a/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/connection/impl/XMPPSessionImpl.java
- +++ b/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/connection/impl/XMPPSessionImpl.java
- @@ -35,7 +35,7 @@ import java.util.ResourceBundle;
- import java.util.UUID;
- import javax.jcr.RepositoryException;
- -
- +import java.util.LinkedHashMap;
- import org.exoplatform.container.ExoContainer;
- import org.exoplatform.container.ExoContainerContext;
- import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
- @@ -218,6 +218,8 @@ public class XMPPSessionImpl implements XMPPSession, UIStateSession {
- private static ArrayList<OccupantBean> beanList = null;
- private final DateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
- +
- + private Map<String, EventsBean> messageMap;
- /**
- * It's value not from spec. I add it myself for sending real JID of room to UI client.
- @@ -248,7 +250,7 @@ public class XMPPSessionImpl implements XMPPSession, UIStateSession {
- log.info("Client '" + username + "' logged in.");
- multiUserChatManager = new MultiUserChatManager();
- fileTransferManager = new FileTransferManager(connection_);
- -
- + messageMap = Collections.synchronizedMap(new LinkedHashMap<String, EventsBean>());
- fileTransferManager.addFileTransferListener(new FileTransferListener() {
- public void fileTransferRequest(FileTransferRequest request) {
- try {
- @@ -335,7 +337,8 @@ public class XMPPSessionImpl implements XMPPSession, UIStateSession {
- JsonValue json = generatorImpl.createJsonObject(eventsBean);
- - delegate_.sendMessage(username_, CometdChannels.SUBSCRIPTION, json.toString(), null);
- + messageMap.put(packet.getPacketID(), eventsBean);
- + delegate_.sendMessage(username_, CometdChannels.MESSAGE, json.toString(), null);
- } catch (Exception e) {
- if (log.isDebugEnabled()) {
- log.debug("Send subcription fail", e);
- @@ -349,7 +352,9 @@ public class XMPPSessionImpl implements XMPPSession, UIStateSession {
- try {
- MUCPacketBean bean = new MUCPacketBean();
- bean.setAction(MUCConstants.Action.INVITE);
- - bean.setInvite(new InviteBean(inviter, TransformUtils.messageToBean(message), password, reason, room));
- + UserInfo userInfo = getUserInfo(inviter.split("@")[0]);
- + String inviterName = userInfo.getFirstName() + " " + userInfo.getLastName();
- + bean.setInvite(new InviteBean(inviter, inviterName, TransformUtils.messageToBean(message), password, reason, room));
- bean.setIsRoomPasswordProtect(isPasswordRequired(room));
- bean.setRoom(room);
- sendGroupChatEvent(bean);
- @@ -2102,4 +2107,22 @@ public class XMPPSessionImpl implements XMPPSession, UIStateSession {
- }
- }
- }
- +
- + @Override
- + public Map<String, EventsBean> getMessageMap() {
- + return messageMap;
- + }
- +
- + @Override
- + public void sendMessageToCometd(EventsBean eventsBean) {
- + try {
- + JsonGeneratorImpl generatorImpl = new JsonGeneratorImpl();
- + JsonValue json = generatorImpl.createJsonObject(eventsBean);
- + delegate_.sendMessage(username_, CometdChannels.MESSAGE, json.toString(), null);
- + if (log.isDebugEnabled())
- + log.debug(json.toString());
- + } catch (Exception e) {
- + e.printStackTrace();
- + }
- + }
- }
- diff --git a/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/rest/RESTXMPPService.java b/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/rest/RESTXMPPService.java
- index 2d71490..a408ae8 100755
- --- a/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/rest/RESTXMPPService.java
- +++ b/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/rest/RESTXMPPService.java
- @@ -30,7 +30,9 @@ import java.util.Locale;
- import java.util.Map;
- import java.util.ResourceBundle;
- import java.util.UUID;
- -
- +import java.util.Iterator;
- +import java.util.Map.Entry;
- +import org.exoplatform.services.xmpp.bean.EventsBean;
- import javax.jcr.RepositoryException;
- import javax.ws.rs.Consumes;
- import javax.ws.rs.GET;
- @@ -1975,4 +1977,47 @@ public class RESTXMPPService implements ResourceContainer, Startable {
- }
- return Response.ok("server_is_not_available", MediaType.TEXT_PLAIN).cacheControl(cc).build();
- }
- + /**
- + * @since CS-5643
- + * @param username
- + * @param msgid
- + * @return
- + */
- + @GET
- + @Path("/chatconfirm/{username}/{msgid}/")
- + public Response chatConfirm (@PathParam("username") String username,
- + @PathParam("msgid") String msgid) {
- + XMPPSession session = messenger.getSession(username);
- + Map<String, EventsBean> messageMap = session.getMessageMap();
- + messageMap.remove(msgid);
- + return Response.ok().build();
- + }
- +
- +
- + /**
- + * @since CS-5643
- + * @param username
- + * @return
- + */
- + @GET
- + @Path("/delayedmessages/{username}/")
- + public Response loadDelayedMessages (@PathParam("username") String username) {
- + XMPPSession session = messenger.getSession(username);
- + Map<String, EventsBean> messageMap = session.getMessageMap();
- + Iterator<Entry<String, EventsBean>> iter = messageMap.entrySet().iterator();
- + /*synchronized (messageMap) {
- + while(iter.hasNext()) {
- + Map.Entry<String, EventsBean> entry = (Map.Entry<String, EventsBean>)iter.next();
- + EventsBean message = (EventsBean)entry.getValue();
- + session.sendMessageToCometd(message);
- + iter.remove();
- + }
- + }*/
- + while(iter.hasNext()) {
- + Map.Entry<String, EventsBean> entry = (Map.Entry<String, EventsBean>)iter.next();
- + EventsBean message = (EventsBean)entry.getValue();
- + session.sendMessageToCometd(message);
- + }
- + return Response.ok().build();
- + }
- }
- diff --git a/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/core/XMPPCommunicator.js b/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/core/XMPPCommunicator.js
- index 5736d00..4dfb2ea 100755
- --- a/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/core/XMPPCommunicator.js
- +++ b/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/core/XMPPCommunicator.js
- @@ -679,4 +679,24 @@ XMPPCommunicator.prototype.loadJsResourceBundle = function(locale, transportName
- request.process() ;
- };
- +/**
- + * Use to send notification to server that user has received chat message
- + */
- +XMPPCommunicator.prototype.chatConfirm = function(username, msgId, transportName, handler) {
- + var url = this.SERVICE_URL + '/' + transportName + '/chatconfirm/' + username + '/' + msgId;
- + var request = new eXo.portal.AjaxRequest('GET', url, null);
- + this.initRequest(request, handler);
- + request.process();
- +}
- +
- +/**
- + * Call to push all delayed messages from server to cometd
- + */
- +XMPPCommunicator.prototype.loadDelayedMessages = function(username, transportName, handler) {
- + var url = this.SERVICE_URL + '/' + transportName + '/delayedmessages/' + username;
- + var request = new eXo.portal.AjaxRequest('GET', url, null);
- + this.initRequest(request, handler);
- + request.process();
- +}
- +
- eXo.communication.chat.core.XMPPCommunicator = new XMPPCommunicator();
- diff --git a/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/webui/UIChatWindow.js b/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/webui/UIChatWindow.js
- index 5aaac06..5bd3d35 100755
- --- a/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/webui/UIChatWindow.js
- +++ b/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/webui/UIChatWindow.js
- @@ -983,42 +983,6 @@ UIChatWindow.prototype.onReload = function(eventData) {
- } else {
- thys.focusTab(activeTabId, true);
- }
- - }
- - if (visible)
- - {
- - var activeTabControl = thys.getActiveTabControl();
- - if (activeTabControl) {
- - activeTabControl.updateUnreadMessage();
- - var historyStatus = activeTabControl.tabPaneNode.historyStatus;
- - if (!historyStatus) historyStatus = thys.CURRENT_CONVERSATION_MESSAGE;
- - var endDate = new Date();
- - var startDate = new Date(endDate);
- - switch (historyStatus) {
- - case thys.CURRENT_CONVERSATION_MESSAGE:
- - startDate = new Date(activeTabControl.tabPaneNode.startTime);
- - break;
- - case thys.THIS_WEEK_MESSAGE:
- - startDate.setDate(endDate.getDate() - endDate.getDay());
- - break;
- - case thys.LAST_30_DAY_MESSAGE:
- - startDate.setDate(endDate.getDate() - 30);
- - break;
- - case thys.BEGINNING_MESSAGE:
- - startDate = false;
- - break;
- - }
- - if (startDate) {
- - startDate.setHours(0);
- - startDate.setMinutes(0);
- - startDate.setSeconds(0);
- - startDate.setMilliseconds(1);
- - startDate = startDate.getTime();
- - endDate = endDate.getTime();
- - }
- - var targetPerson = activeTabControl.tabId.targetPerson;
- - targetPerson = targetPerson.substr(0, targetPerson.indexOf('@'));
- - thys.UIMainChatWindow.jabberGetMessageHistory(targetPerson, startDate, endDate, activeTabControl.isGroupChat);
- - }
- }
- thys.setVisible(visible, null, true);
- thys._isOnLoading = false;
- diff --git a/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/webui/UIMainChatWindow.js b/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/webui/UIMainChatWindow.js
- index 071d921..d8423ad 100755
- --- a/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/webui/UIMainChatWindow.js
- +++ b/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/webui/UIMainChatWindow.js
- @@ -988,6 +988,10 @@ UIMainChatWindow.prototype.processGroupChat = function(eventId) {
- var roomName = inviteInfo.room;
- roomName = roomName.substr(0, roomName.indexOf('@'));
- var fullName = eXo.communication.chat.webui.UIChatWindow.fullNameMap[inviteInfo.inviter];
- + if (fullName == null) {
- + fullName = inviteInfo.inviterName;
- + eXo.communication.chat.webui.UIChatWindow.fullNameMap[inviteInfo.inviter] = fullName;
- + }
- //var msgBuf = inviteInfo.inviter + ' invite you join to room: "' + roomName + '"';
- var msgBuf = this.ResourceBundle.chat_message_room_invite_to_join.replace('{0}', fullName);
- msgBuf = msgBuf.replace('{1}', roomName);
- @@ -1192,6 +1196,7 @@ UIMainChatWindow.prototype.postChangeStatus = function(status, eventId) {
- //userNameNode.innerHTML = this.userNames[this.XMPPCommunicator.TRANSPORT_XMPP];
- var userStatusIconNode = DOMUtil.findAncestorByTagName(this.statusIconNode, 'div');
- window.jsconsole.warn('User changed status: ' + this.userStatus + ' -> ' + status);
- + var previousStatus = this.userStatus;
- this.userStatus = status;
- var presenceData = {};
- presenceData.from = this.userNames[this.XMPPCommunicator.TRANSPORT_XMPP] + '@' + this.serverInfo.mainServiceName;
- @@ -1225,6 +1230,10 @@ UIMainChatWindow.prototype.postChangeStatus = function(status, eventId) {
- this.AdvancedDOMEvent.addEventListener(window, 'unload', this.destroyAll, false);
- this.preChangeStatus(this.ONLINE_STATUS, true);
- eXo.communication.chat.webui.UIStateManager.init(this.userNames[this.XMPPCommunicator.TRANSPORT_XMPP]);
- + // push delayed messages from xmppsession to cometd
- + if (previousStatus != this.OFFLINE_STATUS) {
- + eXo.communication.chat.webui.UIMainChatWindow.jabberLoadDelayedMessages(this.userNames[this.XMPPCommunicator.TRANSPORT_XMPP]);
- + }
- break;
- case this.OFFLINE_STATUS:
- //this.unsubscribeCometdTopics();
- @@ -1477,6 +1486,8 @@ UIMainChatWindow.prototype.displayMessages = function(messages, cancelIfNotExist
- }
- messages[lastSenderPoint].body = buffer;
- this.UIChatWindow.displayMessage(messages[lastSenderPoint].from, messages[lastSenderPoint], isGroupChat);
- + var username = messages[lastSenderPoint].to.split('@')[0];
- + eXo.communication.chat.webui.UIMainChatWindow.jabberChatConfirm(username, messages[lastSenderPoint].id);
- lastSenderPoint = i;
- lastSender = msgObj.from;
- }
- @@ -1488,6 +1499,8 @@ UIMainChatWindow.prototype.displayMessages = function(messages, cancelIfNotExist
- isGroupChat = true;
- }
- this.UIChatWindow.displayMessage(msgObj.from, msgObj, isGroupChat);
- + var username = msgObj.to.split('@')[0];
- + eXo.communication.chat.webui.UIMainChatWindow.jabberChatConfirm(username, msgObj.id);
- }
- } catch(e) {
- window.jsconsole.error('Look up error! developer');
- @@ -1919,4 +1932,16 @@ UIMainChatWindow.prototype.aimLogin = function(nodeObj) {};
- */
- UIMainChatWindow.prototype.icqLogin = function(nodeObj) {};
- +
- +UIMainChatWindow.prototype.jabberChatConfirm = function(toUser, msgId) {
- + this.activeAction = "Confirm received chat message";
- + this.XMPPCommunicator.chatConfirm(toUser, msgId, this.XMPPCommunicator.TRANSPORT_XMPP, this.getAjaxHandler());
- +};
- +
- +UIMainChatWindow.prototype.jabberLoadDelayedMessages = function(username) {
- + this.activeAction = "Load delayed messages";
- + this.XMPPCommunicator.loadDelayedMessages(username, this.XMPPCommunicator.TRANSPORT_XMPP, this.getAjaxHandler());
- +};
- +
- +
- eXo.communication.chat.webui.UIMainChatWindow = new UIMainChatWindow();
- --
- 1.7.7.3
Add Comment
Please, Sign In to add comment