cleanup code

This commit is contained in:
pypy
2020-01-13 22:45:10 +09:00
parent b861258de9
commit 234995d23e
+40 -36
View File
@@ -3477,27 +3477,28 @@ CefSharp.BindObjectAsync(
return; return;
} }
var ref = API.cachedUsers.get(id); var ref = API.cachedUsers.get(id);
var isVIP = API.cachedFavoritesByObjectId.has(id);
var ctx = { var ctx = {
id, id,
state: state || 'offline', state: state || 'offline',
ref, ref,
vip: API.cachedFavoritesByObjectId.has(id), isVIP,
name: '', name: '',
no: ++this.friendsNo, no: ++this.friendsNo,
memo: this.loadMemo(id) memo: this.loadMemo(id)
}; };
if (ref) { if (ref === undefined) {
ctx.name = ref.name;
} else {
ref = this.friendLog[id]; ref = this.friendLog[id];
if (ref && if (ref !== undefined &&
ref.displayName) { ref.displayName) {
ctx.name = ref.displayName; ctx.name = ref.displayName;
} }
} else {
ctx.name = ref.name;
} }
this.friends.set(id, ctx); this.friends.set(id, ctx);
if (ctx.state === 'online') { if (ctx.state === 'online') {
if (ctx.vip) { if (ctx.isVIP) {
this.sortFriendsGroup0 = true; this.sortFriendsGroup0 = true;
this.friendsGroup0_.push(ctx); this.friendsGroup0_.push(ctx);
this.friendsGroupA_.unshift(ctx); this.friendsGroupA_.unshift(ctx);
@@ -3519,10 +3520,12 @@ CefSharp.BindObjectAsync(
$app.methods.deleteFriend = function (id) { $app.methods.deleteFriend = function (id) {
var ctx = this.friends.get(id); var ctx = this.friends.get(id);
if (ctx) { if (ctx === undefined) {
Vue.delete(this.friend, id); return;
}
this.friends.delete(id);
if (ctx.state === 'online') { if (ctx.state === 'online') {
if (ctx.vip) { if (ctx.isVIP) {
removeFromArray(this.friendsGroup0_, ctx); removeFromArray(this.friendsGroup0_, ctx);
removeFromArray(this.friendsGroupA_, ctx); removeFromArray(this.friendsGroupA_, ctx);
} else { } else {
@@ -3536,23 +3539,25 @@ CefSharp.BindObjectAsync(
removeFromArray(this.friendsGroup3_, ctx); removeFromArray(this.friendsGroup3_, ctx);
removeFromArray(this.friendsGroupD_, ctx); removeFromArray(this.friendsGroupD_, ctx);
} }
}
}; };
$app.methods.updateFriend = function (id, state, origin) { $app.methods.updateFriend = function (id, state, origin) {
var ctx = this.friends.get(id); var ctx = this.friends.get(id);
if (ctx) { if (ctx === undefined) {
return;
}
var ref = API.cachedUsers.get(id); var ref = API.cachedUsers.get(id);
var vip = API.cachedFavoritesByObjectId.has(id); var isVIP = API.cachedFavoritesByObjectId.has(id);
if (state === undefined || if (state === undefined ||
ctx.state === state) { ctx.state === state) {
// this is should be: undefined -> user
if (ctx.ref !== ref) { if (ctx.ref !== ref) {
ctx.ref = ref; ctx.ref = ref;
// NOTE // NOTE
// AddFriend (CurrentUser) 이후, // AddFriend (CurrentUser) 이후,
// 서버에서 오는 순서라고 보면 될 듯. // 서버에서 오는 순서라고 보면 될 듯.
if (ctx.state === 'online') { if (ctx.state === 'online') {
if (ctx.vip) { if (ctx.isVIP) {
removeFromArray(this.friendsGroupA_, ctx); removeFromArray(this.friendsGroupA_, ctx);
this.friendsGroupA_.push(ctx); this.friendsGroupA_.push(ctx);
} else { } else {
@@ -3567,10 +3572,10 @@ CefSharp.BindObjectAsync(
this.friendsGroupD_.push(ctx); this.friendsGroupD_.push(ctx);
} }
} }
if (ctx.vip !== vip) { if (ctx.isVIP !== isVIP) {
ctx.vip = vip; ctx.isVIP = isVIP;
if (ctx.state === 'online') { if (ctx.state === 'online') {
if (ctx.vip) { if (ctx.isVIP) {
removeFromArray(this.friendsGroup1_, ctx); removeFromArray(this.friendsGroup1_, ctx);
removeFromArray(this.friendsGroupB_, ctx); removeFromArray(this.friendsGroupB_, ctx);
this.sortFriendsGroup0 = true; this.sortFriendsGroup0 = true;
@@ -3585,11 +3590,11 @@ CefSharp.BindObjectAsync(
} }
} }
} }
if (ctx.ref && if (ref !== undefined &&
ctx.name !== ctx.ref.displayName) { ctx.name !== ref.displayName) {
ctx.name = ctx.ref.displayName; ctx.name = ref.displayName;
if (ctx.state === 'online') { if (ctx.state === 'online') {
if (ctx.vip) { if (ctx.isVIP) {
this.sortFriendsGroup0 = true; this.sortFriendsGroup0 = true;
} else { } else {
this.sortFriendsGroup1 = true; this.sortFriendsGroup1 = true;
@@ -3603,16 +3608,16 @@ CefSharp.BindObjectAsync(
// FIXME: 도배 가능성 있음 // FIXME: 도배 가능성 있음
if (origin && if (origin &&
ctx.state !== 'online' && ctx.state !== 'online' &&
ctx.ref && ref !== undefined &&
ctx.ref.location !== '' && ref.location !== '' &&
ctx.ref.location !== 'offline') { ref.location !== 'offline') {
API.getUser({ API.getUser({
userId: id userId: id
}); });
} }
} else { } else {
if (ctx.state === 'online') { if (ctx.state === 'online') {
if (ctx.vip) { if (ctx.isVIP) {
removeFromArray(this.friendsGroup0_, ctx); removeFromArray(this.friendsGroup0_, ctx);
removeFromArray(this.friendsGroupA_, ctx); removeFromArray(this.friendsGroupA_, ctx);
} else { } else {
@@ -3627,18 +3632,14 @@ CefSharp.BindObjectAsync(
removeFromArray(this.friendsGroupD_, ctx); removeFromArray(this.friendsGroupD_, ctx);
} }
ctx.state = state; ctx.state = state;
if (ctx.ref !== ref) {
ctx.ref = ref; ctx.ref = ref;
} ctx.isVIP = isVIP;
if (ctx.vip !== vip) { if (ref !== undefined &&
ctx.vip = vip; ctx.name !== ref.displayName) {
} ctx.name = ref.displayName;
if (ctx.ref &&
ctx.name !== ctx.ref.displayName) {
ctx.name = ctx.ref.displayName;
} }
if (ctx.state === 'online') { if (ctx.state === 'online') {
if (ctx.vip) { if (ctx.isVIP) {
this.sortFriendsGroup0 = true; this.sortFriendsGroup0 = true;
this.friendsGroup0_.push(ctx); this.friendsGroup0_.push(ctx);
this.friendsGroupA_.unshift(ctx); this.friendsGroupA_.unshift(ctx);
@@ -3657,10 +3658,9 @@ CefSharp.BindObjectAsync(
this.friendsGroupD_.unshift(ctx); this.friendsGroupD_.unshift(ctx);
} }
} }
}
}; };
var sortFriendByName = (a, b) => { var sortFriendByName = function (a, b) {
var A = String(a.name).toUpperCase(); var A = String(a.name).toUpperCase();
var B = String(b.name).toUpperCase(); var B = String(b.name).toUpperCase();
if (A < B) { if (A < B) {
@@ -3672,6 +3672,7 @@ CefSharp.BindObjectAsync(
return 0; return 0;
}; };
// VIP friends
$app.computed.friendsGroup0 = function () { $app.computed.friendsGroup0 = function () {
if (this.orderFriendsGroup0) { if (this.orderFriendsGroup0) {
return this.friendsGroupA_; return this.friendsGroupA_;
@@ -3683,6 +3684,7 @@ CefSharp.BindObjectAsync(
return this.friendsGroup0_; return this.friendsGroup0_;
}; };
// Online friends
$app.computed.friendsGroup1 = function () { $app.computed.friendsGroup1 = function () {
if (this.orderFriendsGroup1) { if (this.orderFriendsGroup1) {
return this.friendsGroupB_; return this.friendsGroupB_;
@@ -3694,6 +3696,7 @@ CefSharp.BindObjectAsync(
return this.friendsGroup1_; return this.friendsGroup1_;
}; };
// Active friends
$app.computed.friendsGroup2 = function () { $app.computed.friendsGroup2 = function () {
if (this.orderFriendsGroup2) { if (this.orderFriendsGroup2) {
return this.friendsGroupC_; return this.friendsGroupC_;
@@ -3705,6 +3708,7 @@ CefSharp.BindObjectAsync(
return this.friendsGroup2_; return this.friendsGroup2_;
}; };
// Offline friends
$app.computed.friendsGroup3 = function () { $app.computed.friendsGroup3 = function () {
if (this.orderFriendsGroup3) { if (this.orderFriendsGroup3) {
return this.friendsGroupD_; return this.friendsGroupD_;
@@ -3718,7 +3722,7 @@ CefSharp.BindObjectAsync(
$app.methods.userStatusClass = function (user) { $app.methods.userStatusClass = function (user) {
var style = {}; var style = {};
if (user) { if (user !== undefined) {
// due to social status, check if the user isn't currentUser // due to social status, check if the user isn't currentUser
if (user.state === 'active' && if (user.state === 'active' &&
user.id !== API.currentUser.id) { user.id !== API.currentUser.id) {