Better support for infinite scrolling with MAM for MUC.

updates #306
This commit is contained in:
JC Brand 2015-07-21 20:42:14 +02:00
parent 5eea22f245
commit 44abbeadf3

View File

@ -2980,11 +2980,12 @@
handleMUCStanza: function (stanza) { handleMUCStanza: function (stanza) {
var xmlns, xquery, i; var xmlns, xquery, i;
var from = stanza.getAttribute('from'); var from = stanza.getAttribute('from');
if (!from || (this.model.get('id') !== from.split("/")[0])) { var is_mam = $(stanza).find('[xmlns="'+Strophe.NS.MAM+'"]').length > 0;
if (!from || (this.model.get('id') !== from.split("/")[0]) || is_mam) {
return true; return true;
} }
if (stanza.nodeName === "message") { if (stanza.nodeName === "message") {
this.onChatRoomMessage(stanza); _.compose(this.onChatRoomMessage.bind(this), this.showStatusMessages.bind(this))(stanza);
} else if (stanza.nodeName === "presence") { } else if (stanza.nodeName === "presence") {
xquery = stanza.getElementsByTagName("x"); xquery = stanza.getElementsByTagName("x");
if (xquery.length > 0) { if (xquery.length > 0) {
@ -3233,12 +3234,13 @@
303: ___('Your nickname has been changed to: <strong>%1$s</strong>') 303: ___('Your nickname has been changed to: <strong>%1$s</strong>')
}, },
showStatusMessages: function ($el, is_self) { showStatusMessages: function (el, is_self) {
/* Check for status codes and communicate their purpose to the user. /* Check for status codes and communicate their purpose to the user.
* Allow user to configure chat room if they are the owner. * Allow user to configure chat room if they are the owner.
* See: http://xmpp.org/registrar/mucstatus.html * See: http://xmpp.org/registrar/mucstatus.html
*/ */
var disconnect_msgs = [], var $el = $(el),
disconnect_msgs = [],
msgs = [], msgs = [],
reasons = []; reasons = [];
$el.find('x[xmlns="'+Strophe.NS.MUC_USER+'"]').each(function (idx, x) { $el.find('x[xmlns="'+Strophe.NS.MUC_USER+'"]').each(function (idx, x) {
@ -3288,7 +3290,8 @@
for (i=0; i<reasons.length; i++) { for (i=0; i<reasons.length; i++) {
this.showStatusNotification(__('The reason given is: "'+reasons[i]+'"'), true); this.showStatusNotification(__('The reason given is: "'+reasons[i]+'"'), true);
} }
return this.scrollDown(); this.scrollDown();
return el;
}, },
showErrorMessage: function ($error) { showErrorMessage: function ($error) {
@ -3337,7 +3340,7 @@
this.$('span.centered.spinner').remove(); this.$('span.centered.spinner').remove();
this.$el.find('.chat-body').children().show(); this.$el.find('.chat-body').children().show();
} }
this.showStatusMessages($presence, is_self); this.showStatusMessages(pres, is_self);
} }
this.occupantsview.updateOccupantsOnPresence(pres); this.occupantsview.updateOccupantsOnPresence(pres);
}, },
@ -3364,7 +3367,6 @@
if (msgid && this.model.messages.findWhere({msgid: msgid})) { if (msgid && this.model.messages.findWhere({msgid: msgid})) {
return true; // We already have this message stored. return true; // We already have this message stored.
} }
this.showStatusMessages($message);
if (subject) { if (subject) {
this.$el.find('.chatroom-topic').text(subject).attr('title', subject); this.$el.find('.chatroom-topic').text(subject).attr('title', subject);
// # For translators: the %1$s and %2$s parts will get replaced by the user and topic text respectively // # For translators: the %1$s and %2$s parts will get replaced by the user and topic text respectively