Chat: show online users in the left chat panel (don't duplicate users)

This commit is contained in:
Julia Radzhabova 2018-06-05 11:56:35 +03:00
parent 8212070fa3
commit b5df85394b

View file

@ -66,9 +66,9 @@ define([
'</li>'].join(''), '</li>'].join(''),
templateUserList: _.template('<ul>' + templateUserList: _.template('<ul>' +
'<% _.each(users, function(item) { %>' + '<% for (originalId in users) { %>' +
'<%= _.template(usertpl)({user: item, scope: scope}) %>' + '<%= _.template(usertpl)({user: users[originalId][0], scope: scope}) %>' +
'<% }); %>' + '<% } %>' +
'</ul>'), '</ul>'),
tplMsg: ['<li>', tplMsg: ['<li>',
@ -100,8 +100,8 @@ define([
Common.UI.BaseView.prototype.initialize.call(this, arguments); Common.UI.BaseView.prototype.initialize.call(this, arguments);
this.storeUsers.bind({ this.storeUsers.bind({
add : _.bind(this._onAddUser, this), add : _.bind(this._onResetUsers, this),
change : _.bind(this._onUsersChanged, this), change : _.bind(this._onResetUsers, this),
reset : _.bind(this._onResetUsers, this) reset : _.bind(this._onResetUsers, this)
}); });
@ -162,23 +162,10 @@ define([
} }
}, },
_onAddUser: function(m, c, opts) {
if (this.panelUsers) {
this.panelUsers.find('ul').append(_.template(this.tplUser)({user: m, scope: this}));
this.panelUsers.scroller.update({minScrollbarLength : 25, alwaysVisibleY: true});
}
},
_onUsersChanged: function(m) {
if (m.changed.online != undefined && this.panelUsers) {
this.panelUsers.find('#' + m.get('iid'))[m.changed.online?'removeClass':'addClass']('offline');
this.panelUsers.scroller.update({minScrollbarLength : 25, alwaysVisibleY: true});
}
},
_onResetUsers: function(c, opts) { _onResetUsers: function(c, opts) {
if (this.panelUsers) { if (this.panelUsers) {
this.panelUsers.html(this.templateUserList({users: c.models, usertpl: this.tplUser, scope: this})); this.panelUsers.html(this.templateUserList({users: this.storeUsers.chain().filter(function(item){return item.get('online');}).groupBy(function(item) {return item.get('idOriginal');}).value(),
usertpl: this.tplUser, scope: this}));
this.panelUsers.scroller.update({minScrollbarLength : 25, alwaysVisibleY: true}); this.panelUsers.scroller.update({minScrollbarLength : 25, alwaysVisibleY: true});
} }
}, },
@ -219,7 +206,7 @@ define([
}, },
_prepareMessage: function(m) { _prepareMessage: function(m) {
var user = this.storeUsers.findUser(m.get('userid')); var user = this.storeUsers.findOriginalUser(m.get('userid'));
m.set({ m.set({
usercolor : user ? user.get('color') : null, usercolor : user ? user.get('color') : null,
message : this._pickLink(Common.Utils.String.htmlEncode(m.get('message'))) message : this._pickLink(Common.Utils.String.htmlEncode(m.get('message')))