Guest User

Untitled

a guest
Dec 6th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.02 KB | None | 0 0
  1. From 4b891826b256e4ac8df37711d9e1633dd392d01b Mon Sep 17 00:00:00 2001
  2. From: Quoc Viet <vietnq@exoplatform.com>
  3. Date: Mon, 20 Aug 2012 08:59:16 +0700
  4. Subject: [PATCH] cs-5643 tmp
  5.  
  6. ---
  7. .../exoplatform/services/xmpp/bean/InviteBean.java | 30 ++++++++++++-
  8. .../services/xmpp/connection/XMPPSession.java | 7 +++-
  9. .../xmpp/connection/impl/XMPPSessionImpl.java | 31 +++++++++++--
  10. .../services/xmpp/rest/RESTXMPPService.java | 47 +++++++++++++++++++-
  11. .../communication/chat/core/XMPPCommunicator.js | 20 ++++++++
  12. .../eXo/communication/chat/webui/UIChatWindow.js | 36 ---------------
  13. .../communication/chat/webui/UIMainChatWindow.js | 25 ++++++++++
  14. 7 files changed, 153 insertions(+), 43 deletions(-)
  15.  
  16. 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
  17. index afdec4b..f4061d9 100644
  18. --- a/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/bean/InviteBean.java
  19. +++ b/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/bean/InviteBean.java
  20. @@ -33,13 +33,23 @@ public class InviteBean {
  21. *
  22. */
  23. private String inviter;
  24. +
  25. + private String inviterName;
  26.  
  27. /**
  28. *
  29. */
  30. private String reason;
  31.  
  32. - /**
  33. + public String getInviterName() {
  34. + return inviterName;
  35. +}
  36. +
  37. +public void setInviterName(String inviterName) {
  38. + this.inviterName = inviterName;
  39. +}
  40. +
  41. +/**
  42. *
  43. */
  44. private String password;
  45. @@ -70,6 +80,24 @@ public class InviteBean {
  46. this.reason = reason;
  47. this.room = room;
  48. }
  49. + /**
  50. + * @since CS-5643
  51. + * @param inviter
  52. + * @param inviterName
  53. + * @param message
  54. + * @param password
  55. + * @param reason
  56. + * @param room
  57. + */
  58. + public InviteBean(String inviter, String inviterName, MessageBean message, String password, String reason, String room) {
  59. + super();
  60. + this.inviter = inviter;
  61. + this.inviterName = inviterName;
  62. + this.message = message;
  63. + this.password = password;
  64. + this.reason = reason;
  65. + this.room = room;
  66. + }
  67.  
  68. /**
  69. * @return the room
  70. 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
  71. index a4f1443..3150dd0 100755
  72. --- a/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/connection/XMPPSession.java
  73. +++ b/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/connection/XMPPSession.java
  74. @@ -19,7 +19,8 @@ package org.exoplatform.services.xmpp.connection;
  75. import java.util.Date;
  76. import java.util.List;
  77. import java.util.Map;
  78. -
  79. +import org.exoplatform.services.xmpp.bean.EventsBean;
  80. +import org.exoplatform.services.xmpp.bean.MessageBean;
  81. import org.exoplatform.services.xmpp.bean.ConfigRoomBean;
  82. import org.exoplatform.services.xmpp.bean.FormBean;
  83. import org.exoplatform.services.xmpp.bean.FullRoomInfoBean;
  84. @@ -44,6 +45,10 @@ import org.jivesoftware.smackx.muc.RoomInfo;
  85. * @version $Id: $
  86. */
  87. public interface XMPPSession {
  88. +
  89. + public Map<String, EventsBean> getMessageMap();
  90. +
  91. + public void sendMessageToCometd(EventsBean eventsBean);
  92.  
  93. /**
  94. * Check is <code>Transport</code> supported and add it to <code>List</code>
  95. 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
  96. index 2392fe6..7365f9f 100755
  97. --- a/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/connection/impl/XMPPSessionImpl.java
  98. +++ b/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/connection/impl/XMPPSessionImpl.java
  99. @@ -35,7 +35,7 @@ import java.util.ResourceBundle;
  100. import java.util.UUID;
  101.  
  102. import javax.jcr.RepositoryException;
  103. -
  104. +import java.util.LinkedHashMap;
  105. import org.exoplatform.container.ExoContainer;
  106. import org.exoplatform.container.ExoContainerContext;
  107. import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
  108. @@ -218,6 +218,8 @@ public class XMPPSessionImpl implements XMPPSession, UIStateSession {
  109. private static ArrayList<OccupantBean> beanList = null;
  110.  
  111. private final DateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
  112. +
  113. + private Map<String, EventsBean> messageMap;
  114.  
  115. /**
  116. * It's value not from spec. I add it myself for sending real JID of room to UI client.
  117. @@ -248,7 +250,7 @@ public class XMPPSessionImpl implements XMPPSession, UIStateSession {
  118. log.info("Client '" + username + "' logged in.");
  119. multiUserChatManager = new MultiUserChatManager();
  120. fileTransferManager = new FileTransferManager(connection_);
  121. -
  122. + messageMap = Collections.synchronizedMap(new LinkedHashMap<String, EventsBean>());
  123. fileTransferManager.addFileTransferListener(new FileTransferListener() {
  124. public void fileTransferRequest(FileTransferRequest request) {
  125. try {
  126. @@ -335,7 +337,8 @@ public class XMPPSessionImpl implements XMPPSession, UIStateSession {
  127.  
  128.  
  129. JsonValue json = generatorImpl.createJsonObject(eventsBean);
  130. - delegate_.sendMessage(username_, CometdChannels.SUBSCRIPTION, json.toString(), null);
  131. + messageMap.put(packet.getPacketID(), eventsBean);
  132. + delegate_.sendMessage(username_, CometdChannels.MESSAGE, json.toString(), null);
  133. } catch (Exception e) {
  134. if (log.isDebugEnabled()) {
  135. log.debug("Send subcription fail", e);
  136. @@ -349,7 +352,9 @@ public class XMPPSessionImpl implements XMPPSession, UIStateSession {
  137. try {
  138. MUCPacketBean bean = new MUCPacketBean();
  139. bean.setAction(MUCConstants.Action.INVITE);
  140. - bean.setInvite(new InviteBean(inviter, TransformUtils.messageToBean(message), password, reason, room));
  141. + UserInfo userInfo = getUserInfo(inviter.split("@")[0]);
  142. + String inviterName = userInfo.getFirstName() + " " + userInfo.getLastName();
  143. + bean.setInvite(new InviteBean(inviter, inviterName, TransformUtils.messageToBean(message), password, reason, room));
  144. bean.setIsRoomPasswordProtect(isPasswordRequired(room));
  145. bean.setRoom(room);
  146. sendGroupChatEvent(bean);
  147. @@ -2102,4 +2107,22 @@ public class XMPPSessionImpl implements XMPPSession, UIStateSession {
  148. }
  149. }
  150. }
  151. +
  152. + @Override
  153. + public Map<String, EventsBean> getMessageMap() {
  154. + return messageMap;
  155. + }
  156. +
  157. + @Override
  158. + public void sendMessageToCometd(EventsBean eventsBean) {
  159. + try {
  160. + JsonGeneratorImpl generatorImpl = new JsonGeneratorImpl();
  161. + JsonValue json = generatorImpl.createJsonObject(eventsBean);
  162. + delegate_.sendMessage(username_, CometdChannels.MESSAGE, json.toString(), null);
  163. + if (log.isDebugEnabled())
  164. + log.debug(json.toString());
  165. + } catch (Exception e) {
  166. + e.printStackTrace();
  167. + }
  168. + }
  169. }
  170. 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
  171. index 2d71490..a408ae8 100755
  172. --- a/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/rest/RESTXMPPService.java
  173. +++ b/eXoApplication/chat/service/src/main/java/org/exoplatform/services/xmpp/rest/RESTXMPPService.java
  174. @@ -30,7 +30,9 @@ import java.util.Locale;
  175. import java.util.Map;
  176.  
  177. import java.util.ResourceBundle;
  178.  
  179. import java.util.UUID;
  180.  
  181. -
  182.  
  183. +import java.util.Iterator;
  184.  
  185. +import java.util.Map.Entry;
  186.  
  187. +import org.exoplatform.services.xmpp.bean.EventsBean;
  188.  
  189. import javax.jcr.RepositoryException;
  190.  
  191. import javax.ws.rs.Consumes;
  192.  
  193. import javax.ws.rs.GET;
  194.  
  195. @@ -1975,4 +1977,47 @@ public class RESTXMPPService implements ResourceContainer, Startable {
  196. }
  197.  
  198. return Response.ok("server_is_not_available", MediaType.TEXT_PLAIN).cacheControl(cc).build();
  199.  
  200. }
  201.  
  202. + /**
  203.  
  204. + * @since CS-5643
  205.  
  206. + * @param username
  207.  
  208. + * @param msgid
  209.  
  210. + * @return
  211.  
  212. + */
  213.  
  214. + @GET
  215.  
  216. + @Path("/chatconfirm/{username}/{msgid}/")
  217.  
  218. + public Response chatConfirm (@PathParam("username") String username,
  219.  
  220. + @PathParam("msgid") String msgid) {
  221.  
  222. + XMPPSession session = messenger.getSession(username);
  223.  
  224. + Map<String, EventsBean> messageMap = session.getMessageMap();
  225.  
  226. + messageMap.remove(msgid);
  227.  
  228. + return Response.ok().build();
  229.  
  230. + }
  231.  
  232. +
  233.  
  234. +
  235.  
  236. + /**
  237.  
  238. + * @since CS-5643
  239.  
  240. + * @param username
  241.  
  242. + * @return
  243.  
  244. + */
  245.  
  246. + @GET
  247.  
  248. + @Path("/delayedmessages/{username}/")
  249.  
  250. + public Response loadDelayedMessages (@PathParam("username") String username) {
  251.  
  252. + XMPPSession session = messenger.getSession(username);
  253.  
  254. + Map<String, EventsBean> messageMap = session.getMessageMap();
  255.  
  256. + Iterator<Entry<String, EventsBean>> iter = messageMap.entrySet().iterator();
  257.  
  258. + /*synchronized (messageMap) {
  259.  
  260. + while(iter.hasNext()) {
  261.  
  262. + Map.Entry<String, EventsBean> entry = (Map.Entry<String, EventsBean>)iter.next();
  263.  
  264. + EventsBean message = (EventsBean)entry.getValue();
  265.  
  266. + session.sendMessageToCometd(message);
  267.  
  268. + iter.remove();
  269.  
  270. + }
  271.  
  272. + }*/
  273.  
  274. + while(iter.hasNext()) {
  275.  
  276. + Map.Entry<String, EventsBean> entry = (Map.Entry<String, EventsBean>)iter.next();
  277.  
  278. + EventsBean message = (EventsBean)entry.getValue();
  279.  
  280. + session.sendMessageToCometd(message);
  281.  
  282. + }
  283.  
  284. + return Response.ok().build();
  285.  
  286. + }
  287.  
  288. }
  289.  
  290. 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
  291. index 5736d00..4dfb2ea 100755
  292. --- a/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/core/XMPPCommunicator.js
  293. +++ b/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/core/XMPPCommunicator.js
  294. @@ -679,4 +679,24 @@ XMPPCommunicator.prototype.loadJsResourceBundle = function(locale, transportName
  295. request.process() ;
  296. };
  297.  
  298. +/**
  299. + * Use to send notification to server that user has received chat message
  300. + */
  301. +XMPPCommunicator.prototype.chatConfirm = function(username, msgId, transportName, handler) {
  302. + var url = this.SERVICE_URL + '/' + transportName + '/chatconfirm/' + username + '/' + msgId;
  303. + var request = new eXo.portal.AjaxRequest('GET', url, null);
  304. + this.initRequest(request, handler);
  305. + request.process();
  306. +}
  307. +
  308. +/**
  309. + * Call to push all delayed messages from server to cometd
  310. + */
  311. +XMPPCommunicator.prototype.loadDelayedMessages = function(username, transportName, handler) {
  312. + var url = this.SERVICE_URL + '/' + transportName + '/delayedmessages/' + username;
  313. + var request = new eXo.portal.AjaxRequest('GET', url, null);
  314. + this.initRequest(request, handler);
  315. + request.process();
  316. +}
  317. +
  318. eXo.communication.chat.core.XMPPCommunicator = new XMPPCommunicator();
  319. 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
  320. index 5aaac06..5bd3d35 100755
  321. --- a/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/webui/UIChatWindow.js
  322. +++ b/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/webui/UIChatWindow.js
  323. @@ -983,42 +983,6 @@ UIChatWindow.prototype.onReload = function(eventData) {
  324. } else {
  325. thys.focusTab(activeTabId, true);
  326. }
  327. - }
  328. - if (visible)
  329. - {
  330. - var activeTabControl = thys.getActiveTabControl();
  331. - if (activeTabControl) {
  332. - activeTabControl.updateUnreadMessage();
  333. - var historyStatus = activeTabControl.tabPaneNode.historyStatus;
  334. - if (!historyStatus) historyStatus = thys.CURRENT_CONVERSATION_MESSAGE;
  335. - var endDate = new Date();
  336. - var startDate = new Date(endDate);
  337. - switch (historyStatus) {
  338. - case thys.CURRENT_CONVERSATION_MESSAGE:
  339. - startDate = new Date(activeTabControl.tabPaneNode.startTime);
  340. - break;
  341. - case thys.THIS_WEEK_MESSAGE:
  342. - startDate.setDate(endDate.getDate() - endDate.getDay());
  343. - break;
  344. - case thys.LAST_30_DAY_MESSAGE:
  345. - startDate.setDate(endDate.getDate() - 30);
  346. - break;
  347. - case thys.BEGINNING_MESSAGE:
  348. - startDate = false;
  349. - break;
  350. - }
  351. - if (startDate) {
  352. - startDate.setHours(0);
  353. - startDate.setMinutes(0);
  354. - startDate.setSeconds(0);
  355. - startDate.setMilliseconds(1);
  356. - startDate = startDate.getTime();
  357. - endDate = endDate.getTime();
  358. - }
  359. - var targetPerson = activeTabControl.tabId.targetPerson;
  360. - targetPerson = targetPerson.substr(0, targetPerson.indexOf('@'));
  361. - thys.UIMainChatWindow.jabberGetMessageHistory(targetPerson, startDate, endDate, activeTabControl.isGroupChat);
  362. - }
  363. }
  364. thys.setVisible(visible, null, true);
  365. thys._isOnLoading = false;
  366. 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
  367. index 071d921..d8423ad 100755
  368. --- a/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/webui/UIMainChatWindow.js
  369. +++ b/eXoApplication/chat/webapp/src/main/webapp/javascript/eXo/communication/chat/webui/UIMainChatWindow.js
  370. @@ -988,6 +988,10 @@ UIMainChatWindow.prototype.processGroupChat = function(eventId) {
  371. var roomName = inviteInfo.room;
  372. roomName = roomName.substr(0, roomName.indexOf('@'));
  373. var fullName = eXo.communication.chat.webui.UIChatWindow.fullNameMap[inviteInfo.inviter];
  374. + if (fullName == null) {
  375. + fullName = inviteInfo.inviterName;
  376. + eXo.communication.chat.webui.UIChatWindow.fullNameMap[inviteInfo.inviter] = fullName;
  377. + }
  378. //var msgBuf = inviteInfo.inviter + ' invite you join to room: "' + roomName + '"';
  379. var msgBuf = this.ResourceBundle.chat_message_room_invite_to_join.replace('{0}', fullName);
  380. msgBuf = msgBuf.replace('{1}', roomName);
  381. @@ -1192,6 +1196,7 @@ UIMainChatWindow.prototype.postChangeStatus = function(status, eventId) {
  382. //userNameNode.innerHTML = this.userNames[this.XMPPCommunicator.TRANSPORT_XMPP];
  383. var userStatusIconNode = DOMUtil.findAncestorByTagName(this.statusIconNode, 'div');
  384. window.jsconsole.warn('User changed status: ' + this.userStatus + ' -> ' + status);
  385. + var previousStatus = this.userStatus;
  386. this.userStatus = status;
  387. var presenceData = {};
  388. presenceData.from = this.userNames[this.XMPPCommunicator.TRANSPORT_XMPP] + '@' + this.serverInfo.mainServiceName;
  389. @@ -1225,6 +1230,10 @@ UIMainChatWindow.prototype.postChangeStatus = function(status, eventId) {
  390. this.AdvancedDOMEvent.addEventListener(window, 'unload', this.destroyAll, false);
  391. this.preChangeStatus(this.ONLINE_STATUS, true);
  392. eXo.communication.chat.webui.UIStateManager.init(this.userNames[this.XMPPCommunicator.TRANSPORT_XMPP]);
  393. + // push delayed messages from xmppsession to cometd
  394. + if (previousStatus != this.OFFLINE_STATUS) {
  395. + eXo.communication.chat.webui.UIMainChatWindow.jabberLoadDelayedMessages(this.userNames[this.XMPPCommunicator.TRANSPORT_XMPP]);
  396. + }
  397. break;
  398. case this.OFFLINE_STATUS:
  399. //this.unsubscribeCometdTopics();
  400. @@ -1477,6 +1486,8 @@ UIMainChatWindow.prototype.displayMessages = function(messages, cancelIfNotExist
  401. }
  402. messages[lastSenderPoint].body = buffer;
  403. this.UIChatWindow.displayMessage(messages[lastSenderPoint].from, messages[lastSenderPoint], isGroupChat);
  404. + var username = messages[lastSenderPoint].to.split('@')[0];
  405. + eXo.communication.chat.webui.UIMainChatWindow.jabberChatConfirm(username, messages[lastSenderPoint].id);
  406. lastSenderPoint = i;
  407. lastSender = msgObj.from;
  408. }
  409. @@ -1488,6 +1499,8 @@ UIMainChatWindow.prototype.displayMessages = function(messages, cancelIfNotExist
  410. isGroupChat = true;
  411. }
  412. this.UIChatWindow.displayMessage(msgObj.from, msgObj, isGroupChat);
  413. + var username = msgObj.to.split('@')[0];
  414. + eXo.communication.chat.webui.UIMainChatWindow.jabberChatConfirm(username, msgObj.id);
  415. }
  416. } catch(e) {
  417. window.jsconsole.error('Look up error! developer');
  418. @@ -1919,4 +1932,16 @@ UIMainChatWindow.prototype.aimLogin = function(nodeObj) {};
  419. */
  420. UIMainChatWindow.prototype.icqLogin = function(nodeObj) {};
  421.  
  422. +
  423. +UIMainChatWindow.prototype.jabberChatConfirm = function(toUser, msgId) {
  424. + this.activeAction = "Confirm received chat message";
  425. + this.XMPPCommunicator.chatConfirm(toUser, msgId, this.XMPPCommunicator.TRANSPORT_XMPP, this.getAjaxHandler());
  426. +};
  427. +
  428. +UIMainChatWindow.prototype.jabberLoadDelayedMessages = function(username) {
  429. + this.activeAction = "Load delayed messages";
  430. + this.XMPPCommunicator.loadDelayedMessages(username, this.XMPPCommunicator.TRANSPORT_XMPP, this.getAjaxHandler());
  431. +};
  432. +
  433. +
  434. eXo.communication.chat.webui.UIMainChatWindow = new UIMainChatWindow();
  435. --
  436. 1.7.7.3
Add Comment
Please, Sign In to add comment