From 79bd1690e882ffffe3fa1a42064cd3eee94da711 Mon Sep 17 00:00:00 2001 From: Konstantin Kireyev Date: Thu, 30 May 2024 09:53:09 +0500 Subject: [PATCH] fix/67904: hide notify dot if user not from docspace; replies nullable date render fix --- apps/common/main/lib/controller/Comments.js | 247 ++++++++---------- .../main/app/controller/LeftMenu.js | 2 +- .../pdfeditor/main/app/controller/LeftMenu.js | 2 +- .../main/app/controller/LeftMenu.js | 2 +- .../main/app/controller/LeftMenu.js | 2 +- 5 files changed, 107 insertions(+), 148 deletions(-) diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index b859c7abcd..5ae7b42716 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -50,7 +50,7 @@ define([ ], function () { 'use strict'; - // NOTE: временное решение + // NOTE: temporary solution function buildCommentData () { if (typeof Asc.asc_CCommentDataWord !== 'undefined') { @@ -305,44 +305,26 @@ define([ }, onResolveComment: function (uid) { - var t = this, - reply = null, - addReply = null, - ascComment = buildCommentData(), // new asc_CCommentData(null), - comment = t.findComment(uid); + var t = this, reply = null, comment = t.findComment(uid); if (_.isUndefined(uid)) { uid = comment.get('uid'); } - if (ascComment && comment) { - ascComment.asc_putText(comment.get('comment')); - ascComment.asc_putQuoteText(comment.get('quote')); - ascComment.asc_putTime(t.utcDateToString(new Date(comment.get('time')))); - ascComment.asc_putOnlyOfficeTime(t.ooDateToString(new Date(comment.get('time')))); - ascComment.asc_putUserId(comment.get('userid')); - ascComment.asc_putUserName(comment.get('username')); - ascComment.asc_putSolved(!comment.get('resolved')); - ascComment.asc_putGuid(comment.get('guid')); - ascComment.asc_putUserData(comment.get('userdata')); - - if (!_.isUndefined(ascComment.asc_putDocumentFlag)) { - ascComment.asc_putDocumentFlag(comment.get('unattached')); + if (comment) { + var ascComment = t.buildComment(comment); + if (!ascComment) { + return false; } + ascComment.asc_putSolved(!comment.get('resolved')); + reply = comment.get('replys'); if (reply && reply.length) { reply.forEach(function (reply) { - addReply = buildCommentData(); // new asc_CCommentData(null); - if (addReply) { - addReply.asc_putText(reply.get('reply')); - addReply.asc_putTime(t.utcDateToString(new Date(reply.get('time')))); - addReply.asc_putOnlyOfficeTime(t.ooDateToString(new Date(reply.get('time')))); - addReply.asc_putUserId(reply.get('userid')); - addReply.asc_putUserName(reply.get('username')); - addReply.asc_putUserData(reply.get('userdata')); - - ascComment.asc_addReply(addReply); + var ascReply = t.buildReplyComment(reply); + if (ascReply) { + ascComment.asc_addReply(ascReply); } }); } @@ -407,23 +389,21 @@ define([ if (commentVal && commentVal.length > 0) { var t = this, comment2 = null, - reply = null, addReply = null, - ascComment = buildCommentData(), // new asc_CCommentData(null), comment = t.findComment(id), oldCommentVal = ''; - if (comment && ascComment) { - oldCommentVal = comment.get('comment'); + if (comment) { + var ascComment = t.buildComment(comment); + if (!ascComment) { + return false; + } + ascComment.asc_putText(commentVal); - ascComment.asc_putQuoteText(comment.get('quote')); - ascComment.asc_putTime(t.utcDateToString(new Date(comment.get('time')))); - ascComment.asc_putOnlyOfficeTime(t.ooDateToString(new Date(comment.get('time')))); ascComment.asc_putUserId(t.currentUserId); ascComment.asc_putUserName(AscCommon.UserInfoParser.getCurrentName()); - ascComment.asc_putSolved(comment.get('resolved')); - ascComment.asc_putGuid(comment.get('guid')); - ascComment.asc_putUserData(comment.get('userdata')); + + oldCommentVal = comment.get('comment'); if (!_.isUndefined(ascComment.asc_putDocumentFlag)) { ascComment.asc_putDocumentFlag(comment.get('unattached')); @@ -439,19 +419,12 @@ define([ if (t.subEditStrings[id]) { delete t.subEditStrings[id]; } if (t.subEditStrings[id + '-R']) { delete t.subEditStrings[id + '-R']; } - reply = comment.get('replys'); - - if (reply && reply.length) { - reply.forEach(function (reply) { - addReply = buildCommentData(); // new asc_CCommentData(null); - if (addReply) { - addReply.asc_putText(reply.get('reply')); - addReply.asc_putTime(t.utcDateToString(new Date(reply.get('time')))); - addReply.asc_putOnlyOfficeTime(t.ooDateToString(new Date(reply.get('time')))); - addReply.asc_putUserId(reply.get('userid')); - addReply.asc_putUserName(reply.get('username')); - addReply.asc_putUserData(reply.get('userdata')); + var replies = comment.get('replys'); + if (replies && replies.length) { + replies.forEach(function (reply) { + var ascReply = t.buildReplyComment(reply); + if (ascReply) { ascComment.asc_addReply(addReply); } }); @@ -469,31 +442,20 @@ define([ onChangeReplyComment: function (id, replyId, replyVal) { if (replyVal && replyVal.length > 0) { var me = this, - reply = null, addReply = null, - ascComment = buildCommentData(), // new asc_CCommentData(null), comment = me.findComment(id), oldReplyVal = ''; - if (ascComment && comment) { - ascComment.asc_putText(comment.get('comment')); - ascComment.asc_putQuoteText(comment.get('quote')); - ascComment.asc_putTime(me.utcDateToString(new Date(comment.get('time')))); - ascComment.asc_putOnlyOfficeTime(me.ooDateToString(new Date(comment.get('time')))); - ascComment.asc_putUserId(comment.get('userid')); - ascComment.asc_putUserName(comment.get('username')); - ascComment.asc_putSolved(comment.get('resolved')); - ascComment.asc_putGuid(comment.get('guid')); - ascComment.asc_putUserData(comment.get('userdata')); - - if (!_.isUndefined(ascComment.asc_putDocumentFlag)) { - ascComment.asc_putDocumentFlag(comment.get('unattached')); + if (comment) { + var ascComment = me.buildComment(comment); + if (!ascComment) { + return false; } - reply = comment.get('replys'); + var replies = comment.get('replys'); - if (reply && reply.length) { - reply.forEach(function (reply) { + if (replies && replies.length) { + replies.forEach(function (reply) { addReply = buildCommentData(); // new asc_CCommentData(); if (addReply) { if (reply.get('id') === replyId && !_.isUndefined(replyVal)) { @@ -507,8 +469,8 @@ define([ addReply.asc_putUserName(reply.get('username')); } - addReply.asc_putTime(me.utcDateToString(new Date(reply.get('time')))); - addReply.asc_putOnlyOfficeTime(me.ooDateToString(new Date(reply.get('time')))); + addReply.asc_putTime(reply.get('time') ? me.utcDateToString(new Date(reply.get('time'))) : ''); + addReply.asc_putOnlyOfficeTime(reply.get('time') ? me.ooDateToString(new Date(reply.get('time'))) : ''); addReply.asc_putUserData(reply.get('userdata')); ascComment.asc_addReply(addReply); @@ -526,15 +488,9 @@ define([ }, onAddReplyComment: function (id, replyVal) { if (replyVal.length > 0) { - var me = this, - uid = null, - reply = null, - addReply = null, - ascComment = buildCommentData(), // new asc_CCommentData(null), - comment = me.findComment(id); - - if (ascComment && comment) { + var me = this, uid = null, comment = me.findComment(id); + if (comment) { uid = comment.get('uid'); if (uid) { if (me.subEditStrings[uid]) { delete me.subEditStrings[uid]; } @@ -542,39 +498,22 @@ define([ comment.set('showReplyInPopover', false); } - ascComment.asc_putText(comment.get('comment')); - ascComment.asc_putQuoteText(comment.get('quote')); - ascComment.asc_putTime(me.utcDateToString(new Date(comment.get('time')))); - ascComment.asc_putOnlyOfficeTime(me.ooDateToString(new Date(comment.get('time')))); - ascComment.asc_putUserId(comment.get('userid')); - ascComment.asc_putUserName(comment.get('username')); - ascComment.asc_putSolved(comment.get('resolved')); - ascComment.asc_putGuid(comment.get('guid')); - ascComment.asc_putUserData(comment.get('userdata')); - - if (!_.isUndefined(ascComment.asc_putDocumentFlag)) { - ascComment.asc_putDocumentFlag(comment.get('unattached')); + var ascComment = me.buildComment(comment); + if (!ascComment) { + return false; } - reply = comment.get('replys'); - if (reply && reply.length) { - reply.forEach(function (reply) { - - addReply = buildCommentData(); // new asc_CCommentData(null); - if (addReply) { - addReply.asc_putText(reply.get('reply')); - addReply.asc_putTime(me.utcDateToString(new Date(reply.get('time')))); - addReply.asc_putOnlyOfficeTime(me.ooDateToString(new Date(reply.get('time')))); - addReply.asc_putUserId(reply.get('userid')); - addReply.asc_putUserName(reply.get('username')); - addReply.asc_putUserData(reply.get('userdata')); - - ascComment.asc_addReply(addReply); + var replies = comment.get('replys'); + if (replies && replies.length) { + replies.forEach(function (reply) { + var ascReply = me.buildReplyComment(reply); + if (ascReply) { + ascComment.asc_addReply(ascReply); } }); } - addReply = buildCommentData(); // new asc_CCommentData(null); + var addReply = buildCommentData(); // new asc_CCommentData(null); if (addReply) { addReply.asc_putText(replyVal); addReply.asc_putTime(me.utcDateToString(new Date())); @@ -596,41 +535,22 @@ define([ }, onRemoveReplyComment: function (id, replyId) { if (!_.isUndefined(id) && !_.isUndefined(replyId)) { - var me = this, - replies = null, - addReply = null, - ascComment = buildCommentData(), // new asc_CCommentData(null), - comment = me.findComment(id); + var me = this, comment = me.findComment(id); - if (ascComment && comment) { - ascComment.asc_putText(comment.get('comment')); - ascComment.asc_putQuoteText(comment.get('quote')); - ascComment.asc_putTime(me.utcDateToString(new Date(comment.get('time')))); - ascComment.asc_putOnlyOfficeTime(me.ooDateToString(new Date(comment.get('time')))); - ascComment.asc_putUserId(comment.get('userid')); - ascComment.asc_putUserName(comment.get('username')); - ascComment.asc_putSolved(comment.get('resolved')); - ascComment.asc_putGuid(comment.get('guid')); - ascComment.asc_putUserData(comment.get('userdata')); - - if (!_.isUndefined(ascComment.asc_putDocumentFlag)) { - ascComment.asc_putDocumentFlag(comment.get('unattached')); + if (comment) { + var ascComment = me.buildComment(comment); + if (!ascComment) { + return false; } - replies = comment.get('replys'); + var replies = comment.get('replys'); + if (replies && replies.length) { replies.forEach(function (reply) { if (reply.get('id') !== replyId) { - addReply = buildCommentData(); // new asc_CCommentData(null); - if (addReply) { - addReply.asc_putText(reply.get('reply')); - addReply.asc_putTime(me.utcDateToString(new Date(reply.get('time')))); - addReply.asc_putOnlyOfficeTime(me.ooDateToString(new Date(reply.get('time')))); - addReply.asc_putUserId(reply.get('userid')); - addReply.asc_putUserName(reply.get('username')); - addReply.asc_putUserData(reply.get('userdata')); - - ascComment.asc_addReply(addReply); + var ascReply = me.buildReplyComment(reply); + if (ascReply) { + ascComment.asc_addReply(ascReply); } } }); @@ -837,7 +757,7 @@ define([ t = this; date = (data.asc_getOnlyOfficeTime()) ? new Date(this.stringOOToLocalDate(data.asc_getOnlyOfficeTime())) : - ((data.asc_getTime() == '') ? new Date() : new Date(this.stringUtcToLocalDate(data.asc_getTime()))); + ((data.asc_getTime() == '') ? null : new Date(this.stringUtcToLocalDate(data.asc_getTime()))); var userid = data.asc_getUserId(), user = this.userCollection.findOriginalUser(userid), @@ -858,8 +778,8 @@ define([ 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('time', date ? date.getTime() : null); + comment.set('date', date ? t.dateToLocaleTimeString(date) : null); 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); @@ -880,7 +800,7 @@ define([ for (i = 0; i < repliesCount; ++i) { 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()))); + ((data.asc_getReply(i).asc_getTime() == '') ? null : new Date(this.stringUtcToLocalDate(data.asc_getReply(i).asc_getTime()))); userid = data.asc_getReply(i).asc_getUserId(); user = this.userCollection.findOriginalUser(userid); @@ -894,10 +814,10 @@ define([ parsedName : AscCommon.UserInfoParser.getParsedName(data.asc_getReply(i).asc_getUserName()), usercolor : (user) ? user.get('color') : Common.UI.ExternalUsers.getColor(userid || data.asc_getReply(i).asc_getUserName()), avatar : avatar, - date : t.dateToLocaleTimeString(dateReply), + date : dateReply ? t.dateToLocaleTimeString(dateReply) : null, reply : data.asc_getReply(i).asc_getText(), userdata : data.asc_getReply(i).asc_getUserData(), - time : dateReply.getTime(), + time : dateReply ? dateReply.getTime() : null, editText : false, editTextInPopover : false, showReplyInPopover : false, @@ -1446,7 +1366,7 @@ define([ if (repliesCount) { for (i = 0; i < repliesCount; ++i) { 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()))); + ((data.asc_getReply(i).asc_getTime() == '') ? null : new Date(this.stringUtcToLocalDate(data.asc_getReply(i).asc_getTime()))); var userid = data.asc_getReply(i).asc_getUserId(), user = this.userCollection.findOriginalUser(userid), @@ -1460,10 +1380,10 @@ define([ parsedName : AscCommon.UserInfoParser.getParsedName(data.asc_getReply(i).asc_getUserName()), usercolor : (user) ? user.get('color') : Common.UI.ExternalUsers.getColor(userid || data.asc_getReply(i).asc_getUserName()), avatar : avatar, - date : this.dateToLocaleTimeString(date), + date : date ? this.dateToLocaleTimeString(date) : null, reply : data.asc_getReply(i).asc_getText(), userdata : data.asc_getReply(i).asc_getUserData(), - time : date.getTime(), + time : date ? date.getTime() : null, editText : false, editTextInPopover : false, showReplyInPopover : false, @@ -1734,6 +1654,45 @@ define([ return (date.getMonth() + 1) + '/' + (date.getDate()) + '/' + date.getFullYear() + ' ' + format(date); }, + buildComment: function(comment) { + var ascComment = buildCommentData(); + if (!ascComment) { + return null; + } + + ascComment.asc_putText(comment.get('comment')); + ascComment.asc_putQuoteText(comment.get('quote')); + ascComment.asc_putTime(comment.get('time') ? this.utcDateToString(new Date(comment.get('time'))) : ''); + ascComment.asc_putOnlyOfficeTime(comment.get('time') ? this.ooDateToString(new Date(comment.get('time'))) : ''); + ascComment.asc_putUserId(comment.get('userid')); + ascComment.asc_putUserName(comment.get('username')); + ascComment.asc_putSolved(comment.get('resolved')); + ascComment.asc_putGuid(comment.get('guid')); + ascComment.asc_putUserData(comment.get('userdata')); + + if (!_.isUndefined(ascComment.asc_putDocumentFlag)) { + ascComment.asc_putDocumentFlag(comment.get('unattached')); + } + + return ascComment + }, + + buildReplyComment: function(reply) { + var ascComment = buildCommentData(); + if (!ascComment) { + return null; + } + + ascComment.asc_putText(reply.get('reply')); + ascComment.asc_putTime(reply.get('time') ? this.utcDateToString(new Date(reply.get('time'))) : ''); + ascComment.asc_putOnlyOfficeTime(reply.get('time') ? this.ooDateToString(new Date(reply.get('time'))) : ''); + ascComment.asc_putUserId(reply.get('userid')); + ascComment.asc_putUserName(reply.get('username')); + ascComment.asc_putUserData(reply.get('userdata')); + + return ascComment; + }, + getView: function(name) { return !name && this.view ? this.view : Backbone.Controller.prototype.getView.call(this, name); diff --git a/apps/documenteditor/main/app/controller/LeftMenu.js b/apps/documenteditor/main/app/controller/LeftMenu.js index c21d7f7f26..017c33ec75 100644 --- a/apps/documenteditor/main/app/controller/LeftMenu.js +++ b/apps/documenteditor/main/app/controller/LeftMenu.js @@ -170,7 +170,7 @@ define([ resolved = Common.Utils.InternalSettings.get("de-settings-resolvedcomment"); for (var i = 0; i < collection.length; ++i) { var comment = collection.at(i); - if (!comment.get('hide') && comment.get('userid') !== this.mode.user.id && (resolved || !comment.get('resolved'))) { + if (!comment.get('hide') && comment.get('userid') !== this.mode.user.id && comment.get('userid') !== '' && (resolved || !comment.get('resolved'))) { this.leftMenu.markCoauthOptions('comments', true); break; } diff --git a/apps/pdfeditor/main/app/controller/LeftMenu.js b/apps/pdfeditor/main/app/controller/LeftMenu.js index c5bd040b14..392a37fe8d 100644 --- a/apps/pdfeditor/main/app/controller/LeftMenu.js +++ b/apps/pdfeditor/main/app/controller/LeftMenu.js @@ -153,7 +153,7 @@ define([ resolved = Common.Utils.InternalSettings.get("pdfe-settings-resolvedcomment"); for (var i = 0; i < collection.length; ++i) { var comment = collection.at(i); - if (!comment.get('hide') && comment.get('userid') !== this.mode.user.id && (resolved || !comment.get('resolved'))) { + if (!comment.get('hide') && comment.get('userid') !== this.mode.user.id && comment.get('userid') !== '' && (resolved || !comment.get('resolved'))) { this.leftMenu.markCoauthOptions('comments', true); break; } diff --git a/apps/presentationeditor/main/app/controller/LeftMenu.js b/apps/presentationeditor/main/app/controller/LeftMenu.js index 09d52a36a9..4db52f889d 100644 --- a/apps/presentationeditor/main/app/controller/LeftMenu.js +++ b/apps/presentationeditor/main/app/controller/LeftMenu.js @@ -157,7 +157,7 @@ define([ var collection = this.getApplication().getCollection('Common.Collections.Comments'); for (var i = 0; i < collection.length; ++i) { var comment = collection.at(i); - if (!comment.get('hide') && comment.get('userid') !== this.mode.user.id) { + if (!comment.get('hide') && comment.get('userid') !== this.mode.user.id && comment.get('userid') !== '') { this.leftMenu.markCoauthOptions('comments', true); break; } diff --git a/apps/spreadsheeteditor/main/app/controller/LeftMenu.js b/apps/spreadsheeteditor/main/app/controller/LeftMenu.js index 512d3aff32..861f0e6082 100644 --- a/apps/spreadsheeteditor/main/app/controller/LeftMenu.js +++ b/apps/spreadsheeteditor/main/app/controller/LeftMenu.js @@ -168,7 +168,7 @@ define([ resolved = Common.Utils.InternalSettings.get("sse-settings-resolvedcomment"); for (var i = 0; i < collection.length; ++i) { var comment = collection.at(i); - if (!comment.get('hide') && comment.get('userid') !== this.mode.user.id && (resolved || !comment.get('resolved'))) { + if (!comment.get('hide') && comment.get('userid') !== this.mode.user.id && comment.get('userid') !== '' && (resolved || !comment.get('resolved'))) { this.leftMenu.markCoauthOptions('comments', true); break; }