Merge pull request #826 from jitsi/fix-random-avatar

Fixes random avatar
This commit is contained in:
hristoterezov 2016-08-31 15:46:53 -05:00 committed by GitHub
commit 19362d1904
4 changed files with 60 additions and 8 deletions

View File

@ -48,6 +48,7 @@ const commands = {
CONNECTION_QUALITY: "stats",
EMAIL: "email",
AVATAR_URL: "avatar-url",
AVATAR_ID: "avatar-id",
ETHERPAD: "etherpad",
SHARED_VIDEO: "shared-video",
CUSTOM_ROLE: "custom-role"
@ -758,6 +759,8 @@ export default {
let avatarUrl = APP.settings.getAvatarUrl();
avatarUrl && sendData(this.commands.defaults.AVATAR_URL,
avatarUrl);
!email && sendData(
this.commands.defaults.AVATAR_ID, APP.settings.getAvatarId());
let nick = APP.settings.getDisplayName();
if (config.useNicks && !nick) {
@ -1257,6 +1260,11 @@ export default {
APP.UI.setUserAvatarUrl(from, data.value);
});
room.addCommandListener(this.commands.defaults.AVATAR_ID,
(data, from) => {
APP.UI.setUserAvatarID(from, data.value);
});
APP.UI.addListener(UIEvents.NICKNAME_CHANGED, changeLocalDisplayName);
APP.UI.addListener(UIEvents.START_MUTED_CHANGED,

View File

@ -308,7 +308,12 @@ UI.initConference = function () {
}
// Make sure we configure our avatar id, before creating avatar for us
UI.setUserEmail(id, Settings.getEmail());
let email = Settings.getEmail();
if (email) {
UI.setUserEmail(id, email);
} else {
UI.setUserAvatarID(id, Settings.getAvatarId());
}
Toolbar.checkAutoEnableDesktopSharing();
@ -839,7 +844,7 @@ UI.dockToolbar = function (isDock) {
/**
* Updates the avatar for participant.
* @param {string} id user id
* @param {stirng} avatarUrl the URL for the avatar
* @param {string} avatarUrl the URL for the avatar
*/
function changeAvatar(id, avatarUrl) {
VideoLayout.changeUserAvatar(id, avatarUrl);
@ -852,7 +857,7 @@ function changeAvatar(id, avatarUrl) {
/**
* Update user email.
* @param {string} id user id
* @param {stirng} email user email
* @param {string} email user email
*/
UI.setUserEmail = function (id, email) {
// update avatar
@ -861,11 +866,22 @@ UI.setUserEmail = function (id, email) {
changeAvatar(id, Avatar.getAvatarUrl(id));
};
/**
* Update user avtar id.
* @param {string} id user id
* @param {string} avatarId user's avatar id
*/
UI.setUserAvatarID = function (id, avatarId) {
// update avatar
Avatar.setUserAvatarID(id, avatarId);
changeAvatar(id, Avatar.getAvatarUrl(id));
};
/**
* Update user avatar URL.
* @param {string} id user id
* @param {stirng} url user avatar url
* @param {string} url user avatar url
*/
UI.setUserAvatarUrl = function (id, url) {
// update avatar
@ -1440,8 +1456,6 @@ UI.enableMicrophoneButton = function () {
Toolbar.markAudioIconAsDisabled(false);
};
let bottomToolbarEnabled = null;
UI.showRingOverLay = function () {
RingOverlay.show(APP.tokenData.callee);
FilmStrip.toggleFilmStrip(false);

View File

@ -37,6 +37,15 @@ export default {
this._setUserProp(id, "url", url);
},
/**
* Sets the user's avatar id.
* @param id id of the user
* @param avatarId an id to be used for the avatar
*/
setUserAvatarID: function (id, avatarId) {
this._setUserProp(id, "avatarId", avatarId);
},
/**
* Returns the URL of the image for the avatar of a particular user,
* identified by its id.
@ -55,11 +64,16 @@ export default {
let avatarId = null;
const user = users[userId];
// The priority is url, email and lowest is avatarId
if(user) {
if(user.url)
return users[userId].url;
return user.url;
avatarId = users[userId].email;
if (user.email)
avatarId = user.email;
else {
avatarId = user.avatarId;
}
}
// If the ID looks like an email, we'll use gravatar.

View File

@ -3,6 +3,7 @@
import UIUtil from '../UI/util/UIUtil';
let email = '';
let avatarId = '';
let displayName = '';
let language = null;
let cameraDeviceId = '';
@ -35,6 +36,13 @@ if (supportsLocalStorage()) {
}
email = UIUtil.unescapeHtml(window.localStorage.email || '');
avatarId = UIUtil.unescapeHtml(window.localStorage.avatarId || '');
if (!avatarId) {
// if there is no avatar id, we generate a unique one and use it forever
avatarId = generateUniqueId();
window.localStorage.avatarId = avatarId;
}
localFlipX = JSON.parse(window.localStorage.localFlipX || true);
displayName = UIUtil.unescapeHtml(window.localStorage.displayname || '');
language = window.localStorage.language;
@ -105,6 +113,14 @@ export default {
return email;
},
/**
* Returns avatar id of the local user.
* @returns {string} avatar id
*/
getAvatarId: function () {
return avatarId;
},
/**
* Sets new avatarUrl for local user and saves it to the local storage.
* @param {string} newAvatarUrl new avatarUrl for the local user