diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index 8e81f8f1e3..d18bbcc04e 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,10 +837,16 @@ 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())); @@ -848,9 +858,9 @@ define([ 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'); @@ -870,15 +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 : (user) ? user.get('avatar') : null, + avatar : avatar, date : t.dateToLocaleTimeString(dateReply), reply : data.asc_getReply(i).asc_getText(), userdata : data.asc_getReply(i).asc_getUserData(), @@ -887,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()) })); } @@ -906,6 +919,7 @@ define([ // this.api.asc_showComment(id, true); // } } + arrIds.length && Common.UI.ExternalUsers.get('info', arrIds); } }, onApiLockComment: function (id,userId) { @@ -1323,21 +1337,65 @@ define([ }); }, - readSDKComment: function (id, data) { + 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) { + 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); + }); + } + !hasGroup && this.collection.each(function (comment) { + updateCommentData(comment, true); + }); + }, + + 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 : (user) ? user.get('avatar') : null, + avatar : avatar, date : this.dateToLocaleTimeString(date), quote : data.asc_getQuoteText(), comment : data.asc_getText(), @@ -1353,8 +1411,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, @@ -1376,7 +1434,8 @@ define([ return comment; }, - readSDKReplies: function (data) { + readSDKReplies: function (data, requestObj) { + requestObj && !requestObj.arrIds && (requestObj.arrIds = []); var i = 0, replies = [], date = null; @@ -1386,15 +1445,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.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 : (user) ? user.get('avatar') : null, + avatar : avatar, date : this.dateToLocaleTimeString(date), reply : data.asc_getReply(i).asc_getText(), userdata : data.asc_getReply(i).asc_getUserData(), @@ -1403,8 +1465,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,7 +1497,7 @@ define([ date: this.dateToLocaleTimeString(date), userid: this.currentUserId, username: AscCommon.UserInfoParser.getCurrentName(), - avatar: user ? user.get('avatar') : null, + 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,