From 5608f0a9820090b7031a964cb388dcd24823df3a Mon Sep 17 00:00:00 2001 From: SergeyEzhin Date: Thu, 4 Apr 2024 11:32:54 +0300 Subject: [PATCH] [common] Set colors for offline-users --- .../mobile/lib/controller/VersionHistory.jsx | 13 +++++-- .../lib/controller/collaboration/Comments.jsx | 37 +++++++++++-------- apps/common/mobile/utils/getUserColor.js | 7 ++++ 3 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 apps/common/mobile/utils/getUserColor.js diff --git a/apps/common/mobile/lib/controller/VersionHistory.jsx b/apps/common/mobile/lib/controller/VersionHistory.jsx index b8a03326e7..56ef2993ed 100644 --- a/apps/common/mobile/lib/controller/VersionHistory.jsx +++ b/apps/common/mobile/lib/controller/VersionHistory.jsx @@ -4,6 +4,7 @@ import VersionHistoryView from '../view/VersionHistory'; import { f7, Sheet, Popover, View } from 'framework7-react'; import { useTranslation } from 'react-i18next'; import { Device } from '../../../../common/mobile/utils/device'; +import { getUserColor } from '../../utils/getUserColor'; const VersionHistoryController = inject('storeAppOptions', 'storeVersionHistory')(observer(props => { const api = Common.EditorApi.get(); @@ -131,11 +132,13 @@ const VersionHistoryController = inject('storeAppOptions', 'storeVersionHistory' user = historyStore.findUserById(version.user.id); if (!user) { + const color = getUserColor(version.user.id || version.user.name || t('Common.VersionHistory.textAnonymous'), true); + user = { id: version.user.id, username: version.user.name || t('Common.VersionHistory.textAnonymous'), - colorval: Asc.c_oAscArrUserColors[usersCnt], - color: generateUserColor(Asc.c_oAscArrUserColors[usersCnt++]), + colorval: color, + color: generateUserColor(color), }; @@ -192,11 +195,13 @@ const VersionHistoryController = inject('storeAppOptions', 'storeVersionHistory' user = historyStore.findUserById(change.user.id); if (!user) { + const color = getUserColor(change.user.id || change.user.name || t('Common.VersionHistory.textAnonymous'), true); + user = { id: change.user.id, username: change.user.name || t('Common.VersionHistory.textAnonymous'), - colorval: Asc.c_oAscArrUserColors[usersCnt], - color: generateUserColor(Asc.c_oAscArrUserColors[usersCnt++]), + colorval: color, + color: generateUserColor(color), }; historyStore.addUser(user); diff --git a/apps/common/mobile/lib/controller/collaboration/Comments.jsx b/apps/common/mobile/lib/controller/collaboration/Comments.jsx index 8d24165603..f3891c3d6a 100644 --- a/apps/common/mobile/lib/controller/collaboration/Comments.jsx +++ b/apps/common/mobile/lib/controller/collaboration/Comments.jsx @@ -6,6 +6,7 @@ import { withTranslation} from 'react-i18next'; import { LocalStorage } from '../../../utils/LocalStorage.mjs'; import {AddComment, EditComment, AddReply, EditReply, ViewComments, ViewCurrentComments} from '../../view/collaboration/Comments'; +import { getUserColor } from '../../../utils/getUserColor'; // utils const timeZoneOffsetInMs = (new Date()).getTimezoneOffset() * 60000; @@ -135,16 +136,17 @@ class CommentsController extends Component { const date = (data.asc_getOnlyOfficeTime()) ? new Date(stringOOToLocalDate(data.asc_getOnlyOfficeTime())) : ((data.asc_getTime() === '') ? new Date() : new Date(stringUtcToLocalDate(data.asc_getTime()))); - let user = this.usersStore.searchUserById(data.asc_getUserId()); + const userId = data.asc_getUserId() + const user = this.usersStore.searchUserById(userId); const name = data.asc_getUserName(); const parsedName = parseUserName(name); changeComment.comment = data.asc_getText(); - changeComment.userId = data.asc_getUserId(); + changeComment.userId = userId; changeComment.userName = name; changeComment.parsedName = Common.Utils.String.htmlEncode(parsedName); changeComment.userInitials = this.usersStore.getInitials(parsedName); - changeComment.userColor = (user) ? user.asc_getColor() : null; + changeComment.userColor = (user) ? user.asc_getColor() : getUserColor(userId || name); changeComment.resolved = data.asc_getSolved(); changeComment.quote = data.asc_getQuoteText(); changeComment.time = date.getTime(); @@ -162,15 +164,17 @@ class CommentsController extends Component { dateReply = (data.asc_getReply(i).asc_getOnlyOfficeTime()) ? new Date(stringOOToLocalDate(data.asc_getReply(i).asc_getOnlyOfficeTime())) : ((data.asc_getReply(i).asc_getTime() === '') ? new Date() : new Date(stringUtcToLocalDate(data.asc_getReply(i).asc_getTime()))); - user = this.usersStore.searchUserById(data.asc_getReply(i).asc_getUserId()); + const userId = data.asc_getReply(i).asc_getUserId(); + const user = this.usersStore.searchUserById(userId); const userName = data.asc_getReply(i).asc_getUserName(); const parsedName = parseUserName(userName); + replies.push({ ind: i, - userId: data.asc_getReply(i).asc_getUserId(), - userName: userName, + userId, + userName, parsedName: Common.Utils.String.htmlEncode(parsedName), - userColor: (user) ? user.asc_getColor() : null, + userColor: (user) ? user.asc_getColor() : getUserColor(userId || userName), date: dateToLocaleTimeString(dateReply, this.appOptions.lang), reply: data.asc_getReply(i).asc_getText(), time: dateReply.getTime(), @@ -189,16 +193,17 @@ class CommentsController extends Component { readSDKComment (id, data) { const date = (data.asc_getOnlyOfficeTime()) ? new Date(stringOOToLocalDate(data.asc_getOnlyOfficeTime())) : ((data.asc_getTime() === '') ? new Date() : new Date(stringUtcToLocalDate(data.asc_getTime()))); - const user = this.usersStore.searchUserById(data.asc_getUserId()); + const userId = data.asc_getUserId(); + const user = this.usersStore.searchUserById(userId); const groupName = id.substr(0, id.lastIndexOf('_')+1).match(/^(doc|sheet[0-9_]+)_/); const userName = data.asc_getUserName(); const parsedName = parseUserName(userName); const comment = { uid : id, - userId : data.asc_getUserId(), - userName : userName, + userId, + userName, parsedName, - userColor : (user) ? user.asc_getColor() : null, + userColor : (user) ? user.asc_getColor() : getUserColor(userId || userName), date : dateToLocaleTimeString(date, this.appOptions.lang), quote : data.asc_getQuoteText(), comment : data.asc_getText(), @@ -229,15 +234,17 @@ class CommentsController extends Component { for (i = 0; i < repliesCount; ++i) { date = (data.asc_getReply(i).asc_getOnlyOfficeTime()) ? new Date(stringOOToLocalDate(data.asc_getReply(i).asc_getOnlyOfficeTime())) : ((data.asc_getReply(i).asc_getTime() === '') ? new Date() : new Date(stringUtcToLocalDate(data.asc_getReply(i).asc_getTime()))); - const user = this.usersStore.searchUserById(data.asc_getReply(i).asc_getUserId()); + const userId = data.asc_getReply(i).asc_getUserId(); + const user = this.usersStore.searchUserById(userId); const userName = data.asc_getReply(i).asc_getUserName(); const parsedName = parseUserName(userName); + replies.push({ ind : i, - userId : data.asc_getReply(i).asc_getUserId(), - userName : userName, + userId, + userName, parsedName : Common.Utils.String.htmlEncode(parsedName), - userColor : (user) ? user.asc_getColor() : null, + userColor : (user) ? user.asc_getColor() : getUserColor(userId || userName), date : dateToLocaleTimeString(date, this.appOptions.lang), reply : data.asc_getReply(i).asc_getText(), time : date.getTime(), diff --git a/apps/common/mobile/utils/getUserColor.js b/apps/common/mobile/utils/getUserColor.js new file mode 100644 index 0000000000..5db962a649 --- /dev/null +++ b/apps/common/mobile/utils/getUserColor.js @@ -0,0 +1,7 @@ +export const getUserColor = (id, intValue) => { + const api = Common.EditorApi.get(); + const color = api.asc_getUserColorById(id); + const userColors = ["#" + ("000000" + color.toString(16)).slice(-6), color]; + + return intValue ? userColors[1] : userColors[0]; +} \ No newline at end of file