diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index 5c996af31f..43b4d1b199 100644 --- a/apps/api/documents/api.js +++ b/apps/api/documents/api.js @@ -87,6 +87,7 @@ id: 'user id', name: 'user name', group: 'group name' // for customization.reviewPermissions or permissions.reviewGroups or permissions.commentGroups. Can be multiple groups separated by commas (,) : 'Group1' or 'Group1,Group2' + image: 'image url' }, recent: [ { diff --git a/apps/common/Gateway.js b/apps/common/Gateway.js index 03bae36ebb..e2efd153d8 100644 --- a/apps/common/Gateway.js +++ b/apps/common/Gateway.js @@ -334,8 +334,8 @@ if (window.Common === undefined) { _postMessage({event:'onMakeActionLink', data: config}); }, - requestUsers: function (command) { - _postMessage({event:'onRequestUsers', data: {c: command}}); + requestUsers: function (command, id) { + _postMessage({event:'onRequestUsers', data: {c: command, id: id}}); }, requestSendNotify: function (emails) { diff --git a/apps/common/main/lib/collection/Users.js b/apps/common/main/lib/collection/Users.js index bc24e4e65b..d6651af831 100644 --- a/apps/common/main/lib/collection/Users.js +++ b/apps/common/main/lib/collection/Users.js @@ -87,6 +87,10 @@ define([ function(model){ return model.get('idOriginal') == id; }); + }, + + findOriginalUsers: function(id) { + return this.where({idOriginal: id}); } }); diff --git a/apps/common/main/lib/controller/Chat.js b/apps/common/main/lib/controller/Chat.js index 443bfdf286..2f717bcd19 100644 --- a/apps/common/main/lib/controller/Chat.js +++ b/apps/common/main/lib/controller/Chat.js @@ -103,6 +103,7 @@ define([ this.api.asc_registerCallback('asc_onCoAuthoringChatReceiveMessage', _.bind(this.onReceiveMessage, this)); if ( !this.mode.isEditDiagram && !this.mode.isEditMailMerge && !this.mode.isEditOle ) { + Common.NotificationCenter.on('mentions:setusers', _.bind(this.avatarsUpdate, this)); this.api.asc_registerCallback('asc_onAuthParticipantsChanged', _.bind(this.onUsersChanged, this)); this.api.asc_registerCallback('asc_onConnectionStateChanged', _.bind(this.onUserConnection, this)); this.api.asc_coAuthoringGetUsers(); @@ -138,27 +139,33 @@ define([ var usersStore = this.getApplication().getCollection('Common.Collections.Users'); if (usersStore) { - var arrUsers = [], name, user; + var arrUsers = [], name, user, arrIds = []; for (name in users) { if (undefined !== name) { user = users[name]; if (user) { + var avatar = Common.UI.ExternalUsers.getImage(user.asc_getIdOriginal()); var usermodel = new Common.Models.User({ id : user.asc_getId(), idOriginal : user.asc_getIdOriginal(), username : user.asc_getUserName(), + parsedName : AscCommon.UserInfoParser.getParsedName(user.asc_getUserName()), + initials : Common.Utils.getUserInitials(AscCommon.UserInfoParser.getParsedName(user.asc_getUserName())), online : true, color : user.asc_getColor(), + avatar : avatar, view : user.asc_getView(), hidden : !(user.asc_getIdOriginal()===this.currentUserId || AscCommon.UserInfoParser.isUserVisible(user.asc_getUserName())) }); arrUsers[(user.asc_getId() == currentUserId ) ? 'unshift' : 'push'](usermodel); + (avatar===undefined) && arrIds.push(user.asc_getIdOriginal()); } } } usersStore[usersStore.size() > 0 ? 'add' : 'reset'](arrUsers); + arrIds.length && Common.UI.ExternalUsers.get('info', arrIds); } }, @@ -167,23 +174,53 @@ define([ if (usersStore){ var user = usersStore.findUser(change.asc_getId()); + var avatar = Common.UI.ExternalUsers.getImage(change.asc_getIdOriginal()); if (!user) { usersStore.add(new Common.Models.User({ id : change.asc_getId(), idOriginal : change.asc_getIdOriginal(), username : change.asc_getUserName(), + parsedName : AscCommon.UserInfoParser.getParsedName(change.asc_getUserName()), + initials : Common.Utils.getUserInitials(AscCommon.UserInfoParser.getParsedName(change.asc_getUserName())), online : change.asc_getState(), color : change.asc_getColor(), + avatar : avatar, view : change.asc_getView(), hidden : !(change.asc_getIdOriginal()===this.currentUserId || AscCommon.UserInfoParser.isUserVisible(change.asc_getUserName())) })); } else { user.set({online: change.asc_getState()}); user.set({username: change.asc_getUserName()}); + user.set({parsedName: AscCommon.UserInfoParser.getParsedName(change.asc_getUserName())}); + user.set({initials: Common.Utils.getUserInitials(change.asc_getUserName())}); + user.set({avatar: avatar}); } + (avatar===undefined) && Common.UI.ExternalUsers.get('info', [change.asc_getIdOriginal()]); } }, + avatarsUpdate: function(type, users) { + if (type!=='info') return; + + var usersStore = this.getApplication().getCollection('Common.Collections.Users'), + msgStore = this.getApplication().getCollection('Common.Collections.ChatMessages'), + needrender = false; + if (users && users.length>0 ){ + _.each(users, function(item) { + usersStore && usersStore.findOriginalUsers(item.id).forEach(function(user){ + user.set({avatar: item.image}); + }); + msgStore && msgStore.where({userid: item.id}).forEach(function(msg){ + if (item.image!==undefined && item.image !== msg.get('avatar')) { + needrender = true; + msg.set('avatar', item.image, {silent: true}); + } + }); + }); + } + needrender && this.panelChat && this.panelChat.renderMessages(); + }, + onReceiveMessage: function(messages, clear){ var msgStore = this.getApplication().getCollection('Common.Collections.ChatMessages'); @@ -193,7 +230,8 @@ define([ array.push(new Common.Models.ChatMessage({ userid : msg.useridoriginal, message : msg.message, - username : msg.username + username : msg.username, + parsedName : AscCommon.UserInfoParser.getParsedName(msg.username), })); }); diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index d5b1b5c1f8..4d7f7f7f77 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -176,6 +176,7 @@ define([ this.userCollection = this.getApplication().getCollection('Common.Collections.Users'); this.userCollection.on('reset', _.bind(this.onUpdateUsers, this)); this.userCollection.on('add', _.bind(this.onUpdateUsers, this)); + Common.NotificationCenter.on('mentions:setusers', this.avatarsUpdate.bind(this)); this.bindViewEvents(this.view, this.events); }, @@ -743,7 +744,8 @@ define([ // SDK onApiAddComment: function (id, data) { - var comment = this.readSDKComment(id, data); + var requestObj = {}, + comment = this.readSDKComment(id, data, requestObj); if (comment) { if (comment.get('groupName')) { this.addCommentToGroupCollection(comment); @@ -763,15 +765,17 @@ define([ this.showPopover = undefined; this.editPopover = false; } + requestObj.arrIds && requestObj.arrIds.length && Common.UI.ExternalUsers.get('info', requestObj.arrIds); } }, onApiAddComments: function (data) { + var requestObj = {}; for (var i = 0; i < data.length; ++i) { - var comment = this.readSDKComment(data[i].asc_getId(), data[i]); + var comment = this.readSDKComment(data[i].asc_getId(), data[i], requestObj); comment.get('groupName') ? this.addCommentToGroupCollection(comment) : this.collection.push(comment); } - this.updateComments(true, this.getComparator() === 'position-asc' || this.getComparator() === 'position-desc'); + requestObj.arrIds && requestObj.arrIds.length && Common.UI.ExternalUsers.get('info', requestObj.arrIds); }, onApiRemoveComment: function (id, silentUpdate) { for (var name in this.groupCollection) { @@ -833,22 +837,30 @@ define([ date = (data.asc_getOnlyOfficeTime()) ? new Date(this.stringOOToLocalDate(data.asc_getOnlyOfficeTime())) : ((data.asc_getTime() == '') ? new Date() : new Date(this.stringUtcToLocalDate(data.asc_getTime()))); - var user = this.userCollection.findOriginalUser(data.asc_getUserId()); - var needSort = (this.getComparator() == 'author-asc' || this.getComparator() == 'author-desc') && (data.asc_getUserName() !== comment.get('username')); + var userid = data.asc_getUserId(), + user = this.userCollection.findOriginalUser(userid), + avatar = Common.UI.ExternalUsers.getImage(userid), + arrIds = []; + (avatar===undefined) && arrIds.push(userid); + var hideComment = !AscCommon.UserInfoParser.canViewComment(data.asc_getUserName()), + needSort = (this.getComparator() == 'author-asc' || this.getComparator() == 'author-desc') && (data.asc_getUserName() !== comment.get('username')) || + hideComment !== comment.get('hide'); comment.set('comment', data.asc_getText()); - comment.set('userid', data.asc_getUserId()); + comment.set('userid', userid); comment.set('username', data.asc_getUserName()); + comment.set('initials', Common.Utils.getUserInitials(AscCommon.UserInfoParser.getParsedName(data.asc_getUserName()))); comment.set('parsedName', AscCommon.UserInfoParser.getParsedName(data.asc_getUserName())); comment.set('parsedGroups', AscCommon.UserInfoParser.getParsedGroups(data.asc_getUserName())); comment.set('usercolor', (user) ? user.get('color') : null); + comment.set('avatar', avatar); comment.set('resolved', data.asc_getSolved()); comment.set('quote', data.asc_getQuoteText()); comment.set('userdata', data.asc_getUserData()); comment.set('time', date.getTime()); comment.set('date', t.dateToLocaleTimeString(date)); - comment.set('editable', (t.mode.canEditComments || (data.asc_getUserId() == t.currentUserId)) && AscCommon.UserInfoParser.canEditComment(data.asc_getUserName())); - comment.set('removable', (t.mode.canDeleteComments || (data.asc_getUserId() == t.currentUserId)) && AscCommon.UserInfoParser.canDeleteComment(data.asc_getUserName())); - comment.set('hide', !AscCommon.UserInfoParser.canViewComment(data.asc_getUserName())); + comment.set('editable', (t.mode.canEditComments || (userid == t.currentUserId)) && AscCommon.UserInfoParser.canEditComment(data.asc_getUserName())); + comment.set('removable', (t.mode.canDeleteComments || (userid == t.currentUserId)) && AscCommon.UserInfoParser.canDeleteComment(data.asc_getUserName())); + comment.set('hide', hideComment); if (!comment.get('hide')) { var usergroups = comment.get('parsedGroups'); @@ -868,13 +880,18 @@ define([ dateReply = (data.asc_getReply(i).asc_getOnlyOfficeTime()) ? new Date(this.stringOOToLocalDate(data.asc_getReply(i).asc_getOnlyOfficeTime())) : ((data.asc_getReply(i).asc_getTime() == '') ? new Date() : new Date(this.stringUtcToLocalDate(data.asc_getReply(i).asc_getTime()))); - user = this.userCollection.findOriginalUser(data.asc_getReply(i).asc_getUserId()); + userid = data.asc_getReply(i).asc_getUserId(); + user = this.userCollection.findOriginalUser(userid); + avatar = Common.UI.ExternalUsers.getImage(userid); + (avatar===undefined) && arrIds.push(userid); replies.push(new Common.Models.Reply({ id : Common.UI.getId(), - userid : data.asc_getReply(i).asc_getUserId(), + userid : userid, username : data.asc_getReply(i).asc_getUserName(), + initials : Common.Utils.getUserInitials(AscCommon.UserInfoParser.getParsedName(data.asc_getReply(i).asc_getUserName())), parsedName : AscCommon.UserInfoParser.getParsedName(data.asc_getReply(i).asc_getUserName()), usercolor : (user) ? user.get('color') : null, + avatar : avatar, date : t.dateToLocaleTimeString(dateReply), reply : data.asc_getReply(i).asc_getText(), userdata : data.asc_getReply(i).asc_getUserData(), @@ -883,8 +900,8 @@ define([ editTextInPopover : false, showReplyInPopover : false, scope : t.view, - editable : (t.mode.canEditComments || (data.asc_getReply(i).asc_getUserId() == t.currentUserId)) && AscCommon.UserInfoParser.canEditComment(data.asc_getReply(i).asc_getUserName()), - removable : (t.mode.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == t.currentUserId)) && AscCommon.UserInfoParser.canDeleteComment(data.asc_getReply(i).asc_getUserName()) + editable : (t.mode.canEditComments || (userid == t.currentUserId)) && AscCommon.UserInfoParser.canEditComment(data.asc_getReply(i).asc_getUserName()), + removable : (t.mode.canDeleteComments || (userid == t.currentUserId)) && AscCommon.UserInfoParser.canDeleteComment(data.asc_getReply(i).asc_getUserName()) })); } @@ -902,6 +919,7 @@ define([ // this.api.asc_showComment(id, true); // } } + arrIds.length && Common.UI.ExternalUsers.get('info', arrIds); } }, onApiLockComment: function (id,userId) { @@ -1280,66 +1298,105 @@ define([ onUpdateUsers: function() { var users = this.userCollection, - hasGroup = false; - for (var name in this.groupCollection) { - hasGroup = true; - this.groupCollection[name].each(function (model) { - var user = users.findOriginalUser(model.get('userid')), - color = (user) ? user.get('color') : null, + hasGroup = false, + updateCommentData = function(comment, user, isNotReply) { + var color = (user) ? user.get('color') : null, needrender = false; - if (color !== model.get('usercolor')) { + if (color !== comment.get('usercolor')) { needrender = true; - model.set('usercolor', color, {silent: true}); + comment.set('usercolor', color, {silent: true}); } - - model.get('replys').forEach(function (reply) { - user = users.findOriginalUser(reply.get('userid')); - color = (user) ? user.get('color') : null; - if (color !== reply.get('usercolor')) { + if (user && (user.image!==undefined)) { + if (user.image !== comment.get('avatar')) { needrender = true; - reply.set('usercolor', color, {silent: true}); + comment.set('avatar', user.image, {silent: true}); } - }); + } - if (needrender) - model.trigger('change'); + //If a comment and not a reply + if(isNotReply){ + comment.get('replys').forEach(function (reply) { + var needrenderReply = updateCommentData(reply, users.findOriginalUser(reply.get('userid')), false); + needrender = needrenderReply || needrender; + }); + + if (needrender) + comment.trigger('change'); + } + + return needrender; + }; + + for (var name in this.groupCollection) { + hasGroup = true; + this.groupCollection[name].each(function (comment) { + updateCommentData(comment, users.findOriginalUser(comment.get('userid')), true); }); } - !hasGroup && this.collection.each(function (model) { - var user = users.findOriginalUser(model.get('userid')), - color = (user) ? user.get('color') : null, - needrender = false; - if (color !== model.get('usercolor')) { - needrender = true; - model.set('usercolor', color, {silent: true}); - } + !hasGroup && this.collection.each(function (comment) { + updateCommentData(comment, users.findOriginalUser(comment.get('userid')), true); + }); + }, - model.get('replys').forEach(function (reply) { - user = users.findOriginalUser(reply.get('userid')); - color = (user) ? user.get('color') : null; - if (color !== reply.get('usercolor')) { - needrender = true; - reply.set('usercolor', color, {silent: true}); + avatarsUpdate: function(type, users) { + if (type!=='info') return; + + var hasGroup = false, + updateCommentData = function(comment, isNotReply) { + var user = _.findWhere(users, {id: comment.get('userid')}), + needrender = false; + if (user && (user.image!==undefined)) { + var avatar = user.image; + if (avatar !== comment.get('avatar')) { + needrender = true; + comment.set('avatar', avatar, {silent: true}); + } + } + + //If a comment and not a reply + if(isNotReply){ + comment.get('replys').forEach(function (reply) { + var needrenderReply = updateCommentData(reply, false); + needrender = needrenderReply || needrender; + }); + + if (needrender) + comment.trigger('change'); } + + return needrender; + }; + + for (var name in this.groupCollection) { + hasGroup = true; + this.groupCollection[name].each(function (comment) { + updateCommentData(comment, true); }); - if (needrender) - model.trigger('change'); + } + !hasGroup && this.collection.each(function (comment) { + updateCommentData(comment, true); }); }, - readSDKComment: function (id, data) { + readSDKComment: function (id, data, requestObj) { + requestObj && !requestObj.arrIds && (requestObj.arrIds = []); var date = (data.asc_getOnlyOfficeTime()) ? new Date(this.stringOOToLocalDate(data.asc_getOnlyOfficeTime())) : ((data.asc_getTime() == '') ? new Date() : new Date(this.stringUtcToLocalDate(data.asc_getTime()))); - var user = this.userCollection.findOriginalUser(data.asc_getUserId()), - groupname = id.substr(0, id.lastIndexOf('_')+1).match(/^(doc|sheet[0-9_]+)_/); + var userid = data.asc_getUserId(), + user = this.userCollection.findOriginalUser(userid), + groupname = id.substr(0, id.lastIndexOf('_')+1).match(/^(doc|sheet[0-9_]+)_/), + avatar = Common.UI.ExternalUsers.getImage(userid); + (avatar===undefined) && requestObj.arrIds.push(userid); var comment = new Common.Models.Comment({ uid : id, guid : data.asc_getGuid(), - userid : data.asc_getUserId(), + userid : userid, username : data.asc_getUserName(), + initials : Common.Utils.getUserInitials(AscCommon.UserInfoParser.getParsedName(data.asc_getUserName())), parsedName : AscCommon.UserInfoParser.getParsedName(data.asc_getUserName()), parsedGroups : AscCommon.UserInfoParser.getParsedGroups(data.asc_getUserName()), usercolor : (user) ? user.get('color') : null, + avatar : avatar, date : this.dateToLocaleTimeString(date), quote : data.asc_getQuoteText(), comment : data.asc_getText(), @@ -1355,8 +1412,8 @@ define([ showReplyInPopover : false, hideAddReply : !_.isUndefined(this.hidereply) ? this.hidereply : (this.showPopover ? true : false), scope : this.view, - editable : (this.mode.canEditComments || (data.asc_getUserId() == this.currentUserId)) && AscCommon.UserInfoParser.canEditComment(data.asc_getUserName()), - removable : (this.mode.canDeleteComments || (data.asc_getUserId() == this.currentUserId)) && AscCommon.UserInfoParser.canDeleteComment(data.asc_getUserName()), + editable : (this.mode.canEditComments || (userid == this.currentUserId)) && AscCommon.UserInfoParser.canEditComment(data.asc_getUserName()), + removable : (this.mode.canDeleteComments || (userid == this.currentUserId)) && AscCommon.UserInfoParser.canDeleteComment(data.asc_getUserName()), hide : !AscCommon.UserInfoParser.canViewComment(data.asc_getUserName()), hint : !this.mode.canComments, fullInfoInHint : this.fullInfoHintMode, @@ -1370,7 +1427,7 @@ define([ var filter = !!group && (group!==-1) && (!usergroups || usergroups.length<1 || usergroups.indexOf(group)<0); comment.set('filtered', filter); } - var replies = this.readSDKReplies(data); + var replies = this.readSDKReplies(data, requestObj); if (replies.length) { comment.set('replys', replies); } @@ -1378,7 +1435,8 @@ define([ return comment; }, - readSDKReplies: function (data) { + readSDKReplies: function (data, requestObj) { + requestObj && !requestObj.arrIds && (requestObj.arrIds = []); var i = 0, replies = [], date = null; @@ -1388,13 +1446,18 @@ define([ date = (data.asc_getReply(i).asc_getOnlyOfficeTime()) ? new Date(this.stringOOToLocalDate(data.asc_getReply(i).asc_getOnlyOfficeTime())) : ((data.asc_getReply(i).asc_getTime() == '') ? new Date() : new Date(this.stringUtcToLocalDate(data.asc_getReply(i).asc_getTime()))); - var user = this.userCollection.findOriginalUser(data.asc_getReply(i).asc_getUserId()); + var userid = data.asc_getReply(i).asc_getUserId(), + user = this.userCollection.findOriginalUser(userid), + avatar = Common.UI.ExternalUsers.getImage(userid); + (avatar===undefined) && requestObj && requestObj.arrIds.push(userid); replies.push(new Common.Models.Reply({ id : Common.UI.getId(), - userid : data.asc_getReply(i).asc_getUserId(), + userid : userid, username : data.asc_getReply(i).asc_getUserName(), + initials : Common.Utils.getUserInitials(AscCommon.UserInfoParser.getParsedName(data.asc_getReply(i).asc_getUserName())), parsedName : AscCommon.UserInfoParser.getParsedName(data.asc_getReply(i).asc_getUserName()), usercolor : (user) ? user.get('color') : null, + avatar : avatar, date : this.dateToLocaleTimeString(date), reply : data.asc_getReply(i).asc_getText(), userdata : data.asc_getReply(i).asc_getUserData(), @@ -1403,8 +1466,8 @@ define([ editTextInPopover : false, showReplyInPopover : false, scope : this.view, - editable : (this.mode.canEditComments || (data.asc_getReply(i).asc_getUserId() == this.currentUserId)) && AscCommon.UserInfoParser.canEditComment(data.asc_getReply(i).asc_getUserName()), - removable : (this.mode.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == this.currentUserId)) && AscCommon.UserInfoParser.canDeleteComment(data.asc_getReply(i).asc_getUserName()) + editable : (this.mode.canEditComments || (userid == this.currentUserId)) && AscCommon.UserInfoParser.canEditComment(data.asc_getReply(i).asc_getUserName()), + removable : (this.mode.canDeleteComments || (userid == this.currentUserId)) && AscCommon.UserInfoParser.canDeleteComment(data.asc_getReply(i).asc_getUserName()) })); } } @@ -1435,6 +1498,8 @@ define([ date: this.dateToLocaleTimeString(date), userid: this.currentUserId, username: AscCommon.UserInfoParser.getCurrentName(), + avatar: Common.UI.ExternalUsers.getImage(this.currentUserId), + initials: Common.Utils.getUserInitials(AscCommon.UserInfoParser.getParsedName(AscCommon.UserInfoParser.getCurrentName())), parsedName: AscCommon.UserInfoParser.getParsedName(AscCommon.UserInfoParser.getCurrentName()), usercolor: (user) ? user.get('color') : null, editTextInPopover: true, diff --git a/apps/common/main/lib/controller/ExternalUsers.js b/apps/common/main/lib/controller/ExternalUsers.js index 48a1655cdd..317e77a99f 100644 --- a/apps/common/main/lib/controller/ExternalUsers.js +++ b/apps/common/main/lib/controller/ExternalUsers.js @@ -46,24 +46,81 @@ if (Common.UI === undefined) { Common.UI.ExternalUsers = new( function() { var externalUsers = [], - isUsersLoading = false; + isUsersLoading = false, + externalUsersInfo = [], + isUsersInfoLoading = false, + stackUsersInfoResponse = []; - var _get = function(type) { - if (isUsersLoading) return; - - type = type || 'mention'; - if (externalUsers[type]===undefined) { - isUsersLoading = true; - Common.Gateway.requestUsers(type || 'mention'); + var _get = function(type, ids) { + if (type==='info') { + (typeof ids !== 'object') && (ids = [ids]); + ids && (ids = _.uniq(ids)); + if (ids.length>100) { + while (ids.length>0) { + Common.Gateway.requestUsers('info', ids.splice(0, 100)); + } + } else + Common.Gateway.requestUsers('info', ids); } else { - Common.NotificationCenter.trigger('mentions:setusers', type, externalUsers[type]); + if (isUsersLoading) return; + + type = type || 'mention'; + if (externalUsers[type]===undefined) { + isUsersLoading = true; + Common.Gateway.requestUsers(type || 'mention'); + } else { + Common.NotificationCenter.trigger('mentions:setusers', type, externalUsers[type]); + } } }; + var _getImage = function(id, request) { + var image, + user = _.findWhere(externalUsersInfo, {id: id}) + user && (image = user.image); + request && (image===undefined) && _get('info', [id]); + return image; + }; + + var _setImage = function(id, image) { + var user = _.findWhere(externalUsersInfo, {id: id}) + user ? (user.image = image) : externalUsersInfo.push({id: id, image: image}); + }; + + var _onUsersInfo = function(data) { + if (data.c !== 'info') return; + + if (isUsersInfoLoading) { + stackUsersInfoResponse.push(data); + return; + } + + isUsersInfoLoading = true; + + var append = []; + data.users && _.each(data.users, function(item) { + var user = _.findWhere(externalUsersInfo, {id: item.id}); + if (user) { + user.image = item.image; + user.name = item.name; + user.email = item.email; + } else + append.push(item); + }); + externalUsersInfo = externalUsersInfo.concat(append); + Common.NotificationCenter.trigger('mentions:setusers', data.c, data.users); + isUsersInfoLoading = false; + if (stackUsersInfoResponse.length>0) + _onUsersInfo(stackUsersInfoResponse.shift()); + }; + var _init = function(canRequestUsers) { + Common.Gateway.on('setusers', _onUsersInfo); + if (!canRequestUsers) return; Common.Gateway.on('setusers', function(data) { + if (data.c === 'info') return; if (data.users===null) {// clear user lists externalUsers = []; return; @@ -73,13 +130,17 @@ Common.UI.ExternalUsers = new( function() { isUsersLoading = false; Common.NotificationCenter.trigger('mentions:setusers', type, externalUsers[type]); }); - Common.NotificationCenter.on('mentions:clearusers', function() { - externalUsers = []; + + Common.NotificationCenter.on('mentions:clearusers', function(type) { + if (type !== 'info') + externalUsers[type || 'mention'] = undefined; }); }; return { init: _init, - get: _get + get: _get, + getImage: _getImage, + setImage: _setImage } })(); diff --git a/apps/common/main/lib/controller/ReviewChanges.js b/apps/common/main/lib/controller/ReviewChanges.js index 6d77ff929c..03acbff802 100644 --- a/apps/common/main/lib/controller/ReviewChanges.js +++ b/apps/common/main/lib/controller/ReviewChanges.js @@ -122,9 +122,14 @@ define([ Common.NotificationCenter.on('collaboration:sharing', this.changeAccessRights.bind(this)); Common.NotificationCenter.on('collaboration:sharingdeny', this.onLostEditRights.bind(this)); Common.NotificationCenter.on('protect:wslock', _.bind(this.onChangeProtectSheet, this)); + Common.NotificationCenter.on('mentions:setusers', this.avatarsUpdate.bind(this)); + + this.userCollection.on({ + add : _.bind(this.onUpdateUsers, this), + change : _.bind(this.onUpdateUsers, this), + reset : _.bind(this.onUpdateUsers, this) + }); - this.userCollection.on('reset', _.bind(this.onUpdateUsers, this)); - this.userCollection.on('add', _.bind(this.onUpdateUsers, this)); }, setConfig: function (data, api) { this.setApi(api); @@ -322,7 +327,7 @@ define([ // helpers readSDKChange: function (data) { - var me = this, arr = []; + var me = this, arr = [], arrIds = []; _.each(data, function(item) { var changetext = '', proptext = '', value = item.get_Value(), @@ -508,11 +513,14 @@ define([ var date = (item.get_DateTime() == '') ? new Date() : new Date(item.get_DateTime()), user = me.userCollection.findOriginalUser(item.get_UserId()), isProtectedReview = me._state.docProtection.isReviewOnly, + avatar = Common.UI.ExternalUsers.getImage(item.get_UserId()), change = new Common.Models.ReviewChange({ uid : Common.UI.getId(), userid : item.get_UserId(), username : item.get_UserName(), usercolor : (user) ? user.get('color') : null, + initials : Common.Utils.getUserInitials(AscCommon.UserInfoParser.getParsedName(item.get_UserName())), + avatar : avatar, date : me.dateToLocaleTimeString(date), changetext : changetext, id : Common.UI.getId(), @@ -528,7 +536,9 @@ define([ }); arr.push(change); + (avatar===undefined) && arrIds.push(item.get_UserId()); }); + arrIds.length && Common.UI.ExternalUsers.get('info', arrIds); return arr; }, @@ -1054,7 +1064,8 @@ define([ if (data) { this.document.info.sharingSettings = data.sharingSettings; Common.NotificationCenter.trigger('collaboration:sharingupdate', data.sharingSettings); - Common.NotificationCenter.trigger('mentions:clearusers', this); + Common.NotificationCenter.trigger('mentions:clearusers', 'mention'); + Common.NotificationCenter.trigger('mentions:clearusers', 'protect'); } }, @@ -1068,6 +1079,16 @@ define([ this.popoverChanges && this.popoverChanges.each(function (model) { var user = users.findOriginalUser(model.get('userid')); model.set('usercolor', (user) ? user.get('color') : null); + user && user.get('avatar') && model.set('avatar', user.get('avatar')); + }); + }, + + avatarsUpdate: function(type, users) { + if (type!=='info') return; + + this.popoverChanges && this.popoverChanges.each(function (model) { + var user = _.findWhere(users, {id: model.get('userid')}) + user && (user.image!==undefined) && model.set('avatar', user.image); }); }, diff --git a/apps/common/main/lib/template/Comments.template b/apps/common/main/lib/template/Comments.template index 36f249ac81..0c747184ec 100644 --- a/apps/common/main/lib/template/Comments.template +++ b/apps/common/main/lib/template/Comments.template @@ -3,10 +3,19 @@ -