app/assets/javascripts/presence_XmppClient.js.erb in social_stream-presence-0.13.2 vs app/assets/javascripts/presence_XmppClient.js.erb in social_stream-presence-0.13.3
- old
+ new
@@ -67,10 +67,11 @@
this.occupants=[];
this.joined = false;
this.affiliation = "none";
this.role = "none";
this.nick = getBaseNickFromUserName();
+ this.lastMessageId = null;
}
//IQsIDs
var iqStanzaID = new Array();
@@ -358,11 +359,10 @@
//Manage Message stanzas
///////
//Chat messages handler
var onMessage = function(msg) {
-
var from = msg.getAttribute('from');
var type = msg.getAttribute('type');
var elems = msg.getElementsByTagName('body');
if (type == "chat" && elems.length > 0) {
@@ -893,20 +893,30 @@
////////
//MUC Stanzas
///////
//MUC Messages
- var onRoomMessage = function(msg) {
+ var onRoomMessage = function(roomMsg) {
+
//from=roomSlug@conference.domain/from_slug
- var from = msg.getAttribute('from');
- var type = msg.getAttribute('type');
- var elems = msg.getElementsByTagName('body');
+ var from = roomMsg.getAttribute('from');
+ var type = roomMsg.getAttribute('type');
+ var elems = roomMsg.getElementsByTagName('body');
if (type == "groupchat" && elems.length > 0) {
var body = elems[0];
var user_nick = getNickFromChatRoomJid(from)
var msg = Strophe.getText(body);
- PRESENCE.UIMANAGER.afterReceivedGroupChatMessage(from,msg)
+
+ //Prevent repeated messages
+ var roomSlug = getSlugFromJid(from);
+ var id = roomMsg.getAttribute('id');
+ if((roomSlug in roomsInfo)&&(roomsInfo[roomSlug].lastMessageId != null)&&(roomsInfo[roomSlug].lastMessageId == id)){
+ return true;
+ }
+ roomsInfo[roomSlug].lastMessageId = id;
+
+ PRESENCE.UIMANAGER.afterReceivedGroupChatMessage(from,msg)
}
return true;
}