using Map instead of object on API.avatar and renaming it to API.cachedAvatars

This commit is contained in:
pypy
2020-01-11 22:23:33 +09:00
parent 22d129a4c3
commit b88f4ffa92

View File

@@ -1408,7 +1408,7 @@ if (window.CefSharp) {
// API: Avatar // API: Avatar
API.avatar = {}; API.cachedAvatars = new Map();
API.$on('AVATAR', function (args) { API.$on('AVATAR', function (args) {
args.ref = this.updateAvatar(args.json); args.ref = this.updateAvatar(args.json);
@@ -1448,7 +1448,7 @@ if (window.CefSharp) {
}; };
API.updateAvatar = function (ref) { API.updateAvatar = function (ref) {
var ctx = this.avatar[ref.id]; var ctx = this.cachedAvatars.get(ref.id);
if (ctx) { if (ctx) {
Object.assign(ctx, ref); Object.assign(ctx, ref);
} else { } else {
@@ -1472,7 +1472,7 @@ if (window.CefSharp) {
updated_at: '', updated_at: '',
...ref ...ref
}; };
this.avatar[ctx.id] = ctx; this.cachedAvatars.set(ctx.id, ctx);
} }
return ctx; return ctx;
}; };
@@ -1484,7 +1484,7 @@ if (window.CefSharp) {
*/ */
API.getCachedAvatar = function (param) { API.getCachedAvatar = function (param) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var ctx = this.avatar[param.avatarId]; var ctx = this.cachedAvatars.get(param.avatarId);
if (ctx) { if (ctx) {
resolve({ resolve({
cache: true, cache: true,
@@ -4949,7 +4949,7 @@ if (window.CefSharp) {
} else if (type === 'avatar') { } else if (type === 'avatar') {
var ctx = this.favoriteAvatar[objectId]; var ctx = this.favoriteAvatar[objectId];
if (favorite) { if (favorite) {
var ref = API.avatar[objectId]; var ref = API.cachedAvatars.get(objectId);
if (ctx) { if (ctx) {
if (ctx.ref !== ref) { if (ctx.ref !== ref) {
ctx.ref = ref; ctx.ref = ref;
@@ -5889,8 +5889,7 @@ if (window.CefSharp) {
D.worlds.push(ref); D.worlds.push(ref);
} }
} }
for (var key in API.avatar) { for (var ref of API.cachedAvatars.values()) {
var ref = API.avatar[key];
if (ref.authorId === D.id) { if (ref.authorId === D.id) {
D.avatars.push(ref); D.avatars.push(ref);
} }