Skip to content

Commit

Permalink
Set colors for offline-users
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliaRadzhabova committed Feb 22, 2024
1 parent befe933 commit 6552fae
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 29 deletions.
12 changes: 6 additions & 6 deletions apps/common/main/lib/controller/Comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ define([
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('usercolor', (user) ? user.get('color') : Common.UI.ExternalUsers.getColor(userid || data.asc_getUserName()));
comment.set('avatar', avatar);
comment.set('resolved', data.asc_getSolved());
comment.set('quote', data.asc_getQuoteText());
Expand Down Expand Up @@ -890,7 +890,7 @@ define([
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,
usercolor : (user) ? user.get('color') : Common.UI.ExternalUsers.getColor(userid || data.asc_getReply(i).asc_getUserName()),
avatar : avatar,
date : t.dateToLocaleTimeString(dateReply),
reply : data.asc_getReply(i).asc_getText(),
Expand Down Expand Up @@ -1300,7 +1300,7 @@ define([
var users = this.userCollection,
hasGroup = false,
updateCommentData = function(comment, user, isNotReply) {
var color = (user) ? user.get('color') : null,
var color = (user) ? user.get('color') : Common.UI.ExternalUsers.getColor(comment.get('userid')),
needrender = false;
if (color !== comment.get('usercolor')) {
needrender = true;
Expand Down Expand Up @@ -1395,7 +1395,7 @@ define([
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,
usercolor : (user) ? user.get('color') : Common.UI.ExternalUsers.getColor(userid || data.asc_getUserName()),
avatar : avatar,
date : this.dateToLocaleTimeString(date),
quote : data.asc_getQuoteText(),
Expand Down Expand Up @@ -1456,7 +1456,7 @@ define([
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,
usercolor : (user) ? user.get('color') : Common.UI.ExternalUsers.getColor(userid || data.asc_getReply(i).asc_getUserName()),
avatar : avatar,
date : this.dateToLocaleTimeString(date),
reply : data.asc_getReply(i).asc_getText(),
Expand Down Expand Up @@ -1501,7 +1501,7 @@ define([
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,
usercolor: (user) ? user.get('color') : Common.UI.ExternalUsers.getColor(this.currentUserId),
editTextInPopover: true,
showReplyInPopover: false,
hideAddReply: true,
Expand Down
20 changes: 16 additions & 4 deletions apps/common/main/lib/controller/ExternalUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ Common.UI.ExternalUsers = new( function() {
isUsersLoading = false,
externalUsersInfo = [],
isUsersInfoLoading = false,
stackUsersInfoResponse = [];
stackUsersInfoResponse = [],
api,
userColors = [];

var _get = function(type, ids) {
if (type==='info') {
Expand Down Expand Up @@ -114,9 +116,9 @@ Common.UI.ExternalUsers = new( function() {
_onUsersInfo(stackUsersInfoResponse.shift());
};

var _init = function(canRequestUsers) {
var _init = function(canRequestUsers, _api) {
Common.Gateway.on('setusers', _onUsersInfo);

api = _api;
if (!canRequestUsers) return;

Common.Gateway.on('setusers', function(data) {
Expand All @@ -137,10 +139,20 @@ Common.UI.ExternalUsers = new( function() {
});
};

var _getColor = function(id, intValue) {
if (!userColors[id]) {
var color = api.asc_getUserColorById(id);
userColors[id] = ["#"+("000000"+color.toString(16)).substr(-6), color];
}

return intValue ? userColors[id][1] : userColors[id][0];
};

return {
init: _init,
get: _get,
getImage: _getImage,
setImage: _setImage
setImage: _setImage,
getColor: _getColor
}
})();
4 changes: 2 additions & 2 deletions apps/common/main/lib/controller/ReviewChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ define([
uid : Common.UI.getId(),
userid : item.get_UserId(),
username : item.get_UserName(),
usercolor : (user) ? user.get('color') : null,
usercolor : (user) ? user.get('color') : Common.UI.ExternalUsers.getColor(item.get_UserId() || item.get_UserName()),
initials : Common.Utils.getUserInitials(AscCommon.UserInfoParser.getParsedName(item.get_UserName())),
avatar : avatar,
date : me.dateToLocaleTimeString(date),
Expand Down Expand Up @@ -1091,7 +1091,7 @@ define([
var users = this.userCollection;
this.popoverChanges && this.popoverChanges.each(function (model) {
var user = users.findOriginalUser(model.get('userid'));
model.set('usercolor', (user) ? user.get('color') : null);
model.set('usercolor', (user) ? user.get('color') : Common.UI.ExternalUsers.getColor(model.get('userid')));
user && user.get('avatar') && model.set('avatar', user.get('avatar'));
});
},
Expand Down
2 changes: 1 addition & 1 deletion apps/common/main/lib/view/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ define([
var user = this.storeUsers.findOriginalUser(m.get('userid')),
avatar = Common.UI.ExternalUsers.getImage(m.get('userid'));
m.set({
usercolor : user ? user.get('color') : null,
usercolor : user ? user.get('color') : Common.UI.ExternalUsers.getColor(m.get('userid')),
avatar : avatar,
initials : user ? user.get('initials') : Common.Utils.getUserInitials(m.get('parsedName')),
message : this._pickLink(m.get('message'))
Expand Down
12 changes: 7 additions & 5 deletions apps/documenteditor/main/app/controller/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -718,11 +718,12 @@ define([
docIdPrev = (ver>0 && versions[ver-1]) ? versions[ver-1].key : version.key + '0';
user = usersStore.findUser(version.user.id);
if (!user) {
var color = Common.UI.ExternalUsers.getColor(version.user.id || version.user.name || this.textAnonymous, true);
user = new Common.Models.User({
id : version.user.id,
username : version.user.name || this.textAnonymous,
colorval : Asc.c_oAscArrUserColors[usersCnt],
color : this.generateUserColor(Asc.c_oAscArrUserColors[usersCnt++])
colorval : color,
color : this.generateUserColor(color)
});
usersStore.add(user);
}
Expand Down Expand Up @@ -770,11 +771,12 @@ define([

user = usersStore.findUser(change.user.id);
if (!user) {
var color = Common.UI.ExternalUsers.getColor(change.user.id || change.user.name || this.textAnonymous, true);
user = new Common.Models.User({
id : change.user.id,
username : change.user.name || this.textAnonymous,
colorval : Asc.c_oAscArrUserColors[usersCnt],
color : this.generateUserColor(Asc.c_oAscArrUserColors[usersCnt++])
colorval : color,
color : this.generateUserColor(color)
});
usersStore.add(user);
}
Expand Down Expand Up @@ -1662,7 +1664,7 @@ define([
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions, this.api);
this.editorConfig.customization && Common.UI.LayoutManager.init(this.editorConfig.customization.layout, this.appOptions.canBrandingExt);
this.editorConfig.customization && Common.UI.FeaturesManager.init(this.editorConfig.customization.features, this.appOptions.canBrandingExt);
Common.UI.ExternalUsers.init(this.appOptions.canRequestUsers);
Common.UI.ExternalUsers.init(this.appOptions.canRequestUsers, this.api);
this.appOptions.user.image ? Common.UI.ExternalUsers.setImage(this.appOptions.user.id, this.appOptions.user.image) : Common.UI.ExternalUsers.get('info', this.appOptions.user.id);

if (this.appOptions.canComments)
Expand Down
2 changes: 1 addition & 1 deletion apps/pdfeditor/main/app/controller/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ define([
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions, this.api);
this.editorConfig.customization && Common.UI.LayoutManager.init(this.editorConfig.customization.layout, this.appOptions.canBrandingExt);
this.editorConfig.customization && Common.UI.FeaturesManager.init(this.editorConfig.customization.features, this.appOptions.canBrandingExt);
Common.UI.ExternalUsers.init(this.appOptions.canRequestUsers);
Common.UI.ExternalUsers.init(this.appOptions.canRequestUsers, this.api);
this.appOptions.user.image ? Common.UI.ExternalUsers.setImage(this.appOptions.user.id, this.appOptions.user.image) : Common.UI.ExternalUsers.get('info', this.appOptions.user.id);

if (this.appOptions.canComments)
Expand Down
12 changes: 7 additions & 5 deletions apps/presentationeditor/main/app/controller/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ define([
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions);
this.editorConfig.customization && Common.UI.LayoutManager.init(this.editorConfig.customization.layout, this.appOptions.canBrandingExt);
this.editorConfig.customization && Common.UI.FeaturesManager.init(this.editorConfig.customization.features, this.appOptions.canBrandingExt);
Common.UI.ExternalUsers.init(this.appOptions.canRequestUsers);
Common.UI.ExternalUsers.init(this.appOptions.canRequestUsers, this.api);
this.appOptions.user.image ? Common.UI.ExternalUsers.setImage(this.appOptions.user.id, this.appOptions.user.image) : Common.UI.ExternalUsers.get('info', this.appOptions.user.id);

// change = true by default in editor
Expand Down Expand Up @@ -2649,11 +2649,12 @@ define([
docIdPrev = (ver>0 && versions[ver-1]) ? versions[ver-1].key : version.key + '0';
user = usersStore.findUser(version.user.id);
if (!user) {
var color = Common.UI.ExternalUsers.getColor(version.user.id || version.user.name || this.textAnonymous, true);
user = new Common.Models.User({
id : version.user.id,
username : version.user.name,
colorval : Asc.c_oAscArrUserColors[usersCnt],
color : this.generateUserColor(Asc.c_oAscArrUserColors[usersCnt++])
colorval : color,
color : this.generateUserColor(color)
});
usersStore.add(user);
}
Expand Down Expand Up @@ -2701,11 +2702,12 @@ define([

user = usersStore.findUser(change.user.id);
if (!user) {
var color = Common.UI.ExternalUsers.getColor(change.user.id || change.user.name || this.textAnonymous, true);
user = new Common.Models.User({
id : change.user.id,
username : change.user.name,
colorval : Asc.c_oAscArrUserColors[usersCnt],
color : this.generateUserColor(Asc.c_oAscArrUserColors[usersCnt++])
colorval : color,
color : this.generateUserColor(color)
});
usersStore.add(user);
}
Expand Down
12 changes: 7 additions & 5 deletions apps/spreadsheeteditor/main/app/controller/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ define([
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions);
this.editorConfig.customization && Common.UI.LayoutManager.init(this.editorConfig.customization.layout, this.appOptions.canBrandingExt);
this.editorConfig.customization && Common.UI.FeaturesManager.init(this.editorConfig.customization.features, this.appOptions.canBrandingExt);
Common.UI.ExternalUsers.init(this.appOptions.canRequestUsers);
Common.UI.ExternalUsers.init(this.appOptions.canRequestUsers, this.api);
this.appOptions.user.image ? Common.UI.ExternalUsers.setImage(this.appOptions.user.id, this.appOptions.user.image) : Common.UI.ExternalUsers.get('info', this.appOptions.user.id);
}

Expand Down Expand Up @@ -3297,11 +3297,12 @@ define([
docIdPrev = (ver>0 && versions[ver-1]) ? versions[ver-1].key : version.key + '0';
user = usersStore.findUser(version.user.id);
if (!user) {
var color = Common.UI.ExternalUsers.getColor(version.user.id || version.user.name || this.textAnonymous, true);
user = new Common.Models.User({
id : version.user.id,
username : version.user.name,
colorval : Asc.c_oAscArrUserColors[usersCnt],
color : this.generateUserColor(Asc.c_oAscArrUserColors[usersCnt++])
colorval : color,
color : this.generateUserColor(color)
});
usersStore.add(user);
}
Expand Down Expand Up @@ -3349,11 +3350,12 @@ define([

user = usersStore.findUser(change.user.id);
if (!user) {
var color = Common.UI.ExternalUsers.getColor(change.user.id || change.user.name || this.textAnonymous, true);
user = new Common.Models.User({
id : change.user.id,
username : change.user.name,
colorval : Asc.c_oAscArrUserColors[usersCnt],
color : this.generateUserColor(Asc.c_oAscArrUserColors[usersCnt++])
colorval : color,
color : this.generateUserColor(color)
});
usersStore.add(user);
}
Expand Down

0 comments on commit 6552fae

Please sign in to comment.