mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 12:19:41 +00:00
Default avatar support
Fixes #264 Implement the equivalent of java's String.hashCode on the conversation model. Change avatar template and attributes. Use css classes for colors.
This commit is contained in:
@@ -237,11 +237,22 @@
|
||||
}
|
||||
},
|
||||
|
||||
getAvatarUrl: function() {
|
||||
getAvatar: function() {
|
||||
if (this.avatarUrl === undefined) {
|
||||
this.updateAvatarUrl(true);
|
||||
}
|
||||
return this.avatarUrl || '/images/default.png';
|
||||
if (this.avatarUrl) {
|
||||
return { url: this.avatarUrl };
|
||||
} else if (this.isPrivate()) {
|
||||
var title = this.getTitle() || '';
|
||||
var initials = title.trim()[0];
|
||||
return {
|
||||
color: Math.abs(this.hashCode()) % 17,
|
||||
content: initials
|
||||
};
|
||||
} else {
|
||||
return { url: '/images/default.png' };
|
||||
}
|
||||
},
|
||||
|
||||
resolveConflicts: function(number) {
|
||||
@@ -262,6 +273,22 @@
|
||||
}
|
||||
});
|
||||
}.bind(this));
|
||||
},
|
||||
hashCode: function() {
|
||||
if (this.hash === undefined) {
|
||||
var string = this.getTitle() || '';
|
||||
if (string.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
var hash = 0;
|
||||
for (var i = 0; i < string.length; i++) {
|
||||
hash = ((hash<<5)-hash) + string.charCodeAt(i);
|
||||
hash = hash & hash; // Convert to 32bit integer
|
||||
}
|
||||
|
||||
this.hash = hash;
|
||||
}
|
||||
return this.hash;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user