diff --git a/html/src/app.js b/html/src/app.js index 6dae9dc6..8c83c347 100644 --- a/html/src/app.js +++ b/html/src/app.js @@ -325,7 +325,7 @@ speechSynthesis.getVoices(); }); API.$on('USER', function (args) { - if (!args?.json?.displayName) { + if (!args?.json?.id) { console.error('API.$on(USER) invalid args', args); return; } @@ -467,23 +467,6 @@ speechSynthesis.getVoices(); } }; - var userUpdateQueue = []; - var userUpdateTimer = null; - var queueUserUpdate = function (ctx) { - userUpdateQueue.push(ctx); - if (userUpdateTimer !== null) { - return; - } - userUpdateTimer = workerTimers.setTimeout(() => { - userUpdateTimer = null; - var { length } = userUpdateQueue; - for (var i = 0; i < length; ++i) { - API.$emit('USER:UPDATE', userUpdateQueue[i]); - } - userUpdateQueue.length = 0; - }, 1); - }; - API.applyUser = function (json) { var ref = this.cachedUsers.get(json.id); if (typeof json.statusDescription !== 'undefined') { @@ -668,7 +651,7 @@ speechSynthesis.getVoices(); props.location.push(ts - ref.$location_at); ref.$location_at = ts; } - queueUserUpdate({ + API.$emit('USER:UPDATE', { ref, props }); @@ -1383,7 +1366,8 @@ speechSynthesis.getVoices(); if (ref?.state !== state) { if ($app.debugFriendState) { console.log( - `Bulk friend fetch, friend state does not match ${json.displayName} from ${ref?.state} to ${state}` + `Bulk friend fetch, friend state does not match ${json.displayName} from ${ref?.state} to ${state}`, + json ); } this.getUser({ @@ -4232,7 +4216,9 @@ speechSynthesis.getVoices(); API.$on('USER:CURRENT', function (args) { // USER:CURRENT에서 처리를 함 - $app.refreshFriends(args.ref, args.fromGetCurrentUser); + if ($app.friendLogInitStatus) { + $app.refreshFriends(args.ref, args.fromGetCurrentUser); + } $app.updateOnlineFriendCoutner(); if ($app.randomUserColours) { @@ -4346,12 +4332,17 @@ speechSynthesis.getVoices(); } var ref = API.cachedUsers.get(id); var isVIP = this.localFavoriteFriends.has(id); + var name = ''; + var friend = this.friendLog.get(id); + if (friend) { + name = friend.displayName; + } var ctx = { id, state: state || 'offline', isVIP, ref, - name: '', + name, no: ++this.friendsNo, memo: '', pendingOffline: false, @@ -4574,7 +4565,9 @@ speechSynthesis.getVoices(); return; } if (this.debugFriendState) { - console.log(ctx.name, 'updateFriendState', newState, ctx.state); + console.log( + `${ctx.name} updateFriendState ${newState} -> ${ctx.state}` + ); } var isVIP = this.localFavoriteFriends.has(id); var ref = ctx.ref; @@ -5333,6 +5326,7 @@ speechSynthesis.getVoices(); $app.friendLogInitStatus = false; await database.initUserTables(args.json.id); $app.$refs.menu.activeIndex = 'feed'; + await $app.updateDatabaseVersion(); // eslint-disable-next-line require-atomic-updates $app.gameLogTable.data = await database.lookupGameLogDatabase( $app.gameLogTable.search, @@ -5349,14 +5343,13 @@ speechSynthesis.getVoices(); args.json?.presence?.groups ); await $app.getCurrentUserGroups(); - $app.refreshFriends(args.ref, args.fromGetCurrentUser); try { if ( await configRepository.getBool(`friendLogInit_${args.json.id}`) ) { - await $app.getFriendLog(); + await $app.getFriendLog(args.ref); } else { - await $app.initFriendLog(args.json.id); + await $app.initFriendLog(args.ref); } } catch (err) { if (!$app.dontLogMeOut) { @@ -5487,6 +5480,7 @@ speechSynthesis.getVoices(); ) { // skip GPS if user is offline or traveling var previousLocation = props.location[1]; + var newLocation = props.location[0]; var time = props.location[2]; if (previousLocation === 'traveling') { previousLocation = ref.$previousLocation; @@ -5496,18 +5490,32 @@ speechSynthesis.getVoices(); time = 0; } } - if (ref.$previousLocation === props.location[0]) { + if ($app.debugFriendState) { + console.log( + `${ref.displayName} ${previousLocation} -> ${newLocation}` + ); + } + if (!previousLocation) { + // no previous location + if ($app.debugFriendState) { + console.log( + ref.displayName, + 'no previous location', + newLocation + ); + } + } else if (ref.$previousLocation === newLocation) { // location traveled to is the same - ref.$location_at = Date.now() - props.location[2]; + ref.$location_at = Date.now() - time; } else { - var worldName = await $app.getWorldName(props.location[0]); - var groupName = await $app.getGroupName(props.location[0]); + var worldName = await $app.getWorldName(newLocation); + var groupName = await $app.getGroupName(newLocation); var feed = { created_at: new Date().toJSON(), type: 'GPS', userId: ref.id, displayName: ref.displayName, - location: props.location[0], + location: newLocation, worldName, groupName, previousLocation, @@ -6798,8 +6806,8 @@ speechSynthesis.getVoices(); $app.data.friendLogInitStatus = false; - $app.methods.initFriendLog = async function (userId) { - await this.updateDatabaseVersion(); + $app.methods.initFriendLog = async function (currentUser) { + this.refreshFriends(currentUser, true); var sqlValues = []; var friends = await API.refreshFriends(); for (var friend of friends) { @@ -6813,7 +6821,7 @@ speechSynthesis.getVoices(); sqlValues.unshift(row); } database.setFriendLogCurrentArray(sqlValues); - await configRepository.setBool(`friendLogInit_${userId}`, true); + await configRepository.setBool(`friendLogInit_${currentUser.id}`, true); this.friendLogInitStatus = true; }; @@ -6828,14 +6836,14 @@ speechSynthesis.getVoices(); await configRepository.setBool(`friendLogInit_${userId}`, true); }; - $app.methods.getFriendLog = async function () { - await this.updateDatabaseVersion(); + $app.methods.getFriendLog = async function (currentUser) { var friendLogCurrentArray = await database.getFriendLogCurrent(); for (var friend of friendLogCurrentArray) { this.friendLog.set(friend.userId, friend); } this.friendLogTable.data = []; this.friendLogTable.data = await database.getFriendLogHistory(); + this.refreshFriends(currentUser, true); await API.refreshFriends(); this.friendLogInitStatus = true; // check for friend/name/rank change AFTER friendLogInitStatus is set @@ -17790,6 +17798,7 @@ speechSynthesis.getVoices(); if (!API.isLoggedIn) { return; } + console.log('LaunchCommand:', input); var args = input.split('/'); var command = args[0]; var commandArg = args[1]; diff --git a/html/src/classes/websocket.js b/html/src/classes/websocket.js index 4cdf50a3..fabe4476 100644 --- a/html/src/classes/websocket.js +++ b/html/src/classes/websocket.js @@ -295,9 +295,18 @@ export default class extends baseClass { } }); } else { - this.$emit('FRIEND:STATE', { + this.$emit('USER', { json: { - state: 'active' + id: content.userId, + platform: content.platform, + state: 'active', + + location: 'offline', + worldId: 'offline', + instanceId: 'offline', + travelingToLocation: 'offline', + travelingToWorld: 'offline', + travelingToInstance: 'offline' }, params: { userId: content.userId @@ -307,9 +316,19 @@ export default class extends baseClass { break; case 'friend-offline': - this.$emit('FRIEND:STATE', { + // more JANK, hell yeah + this.$emit('USER', { json: { - state: 'offline' + id: content.userId, + platform: content.platform, + state: 'offline', + + location: 'offline', + worldId: 'offline', + instanceId: 'offline', + travelingToLocation: 'offline', + travelingToWorld: 'offline', + travelingToInstance: 'offline' }, params: { userId: content.userId @@ -348,8 +367,8 @@ export default class extends baseClass { json: { location: content.location, travelingToLocation: content.travelingToLocation, - ...content.user - // state: 'online' + ...content.user, + state: 'online' // JANK }, params: { userId: content.userId diff --git a/html/src/mixins/friendsListSidebar.pug b/html/src/mixins/friendsListSidebar.pug index b112e193..00d9d454 100644 --- a/html/src/mixins/friendsListSidebar.pug +++ b/html/src/mixins/friendsListSidebar.pug @@ -49,7 +49,7 @@ mixin friendsListSidebar() span.name(v-else v-text="friend.ref.displayName" :style="{'color':friend.ref.$userColour}") span.extra(v-if="friend.pendingOffline") #[i.el-icon-warning-outline] {{ $t('side_panel.pending_offline') }} location.extra(v-else :location="friend.ref.location" :traveling="friend.ref.travelingToLocation" :link="false") - template(v-else-if="friendLogInitStatus") + template(v-else) span(v-text="friend.name || friend.id") el-button(type="text" icon="el-icon-close" size="mini" @click.stop="confirmDeleteFriend(friend.id)" style="margin-left:5px") .x-friend-group.x-link(@click="isOnlineFriends = !isOnlineFriends; saveFriendsGroupStates()" v-show="onlineFriends.length") @@ -65,7 +65,7 @@ mixin friendsListSidebar() span.name(v-else v-text="friend.ref.displayName" :style="{'color':friend.ref.$userColour}") span.extra(v-if="friend.pendingOffline") #[i.el-icon-warning-outline] {{ $t('side_panel.pending_offline') }} location.extra(v-else :location="friend.ref.location" :traveling="friend.ref.travelingToLocation" :link="false") - template(v-else-if="friendLogInitStatus") + template(v-else) span(v-text="friend.name || friend.id") el-button(type="text" icon="el-icon-close" size="mini" @click.stop="confirmDeleteFriend(friend.id)" style="margin-left:5px") .x-friend-group.x-link(@click="isActiveFriends = !isActiveFriends; saveFriendsGroupStates()" v-show="activeFriends.length") @@ -80,7 +80,7 @@ mixin friendsListSidebar() span.name(v-if="!hideNicknames && friend.$nickName" :style="{'color':friend.ref.$userColour}") {{ friend.ref.displayName }} ({{ friend.$nickName }}) span.name(v-else v-text="friend.ref.displayName" :style="{'color':friend.ref.$userColour}") span.extra(v-text="friend.ref.statusDescription" :link="false") - template(v-else-if="friendLogInitStatus") + template(v-else) span(v-text="friend.name || friend.id") el-button(type="text" icon="el-icon-close" size="mini" @click.stop="confirmDeleteFriend(friend.id)" style="margin-left:5px") .x-friend-group.x-link(@click="isOfflineFriends = !isOfflineFriends; saveFriendsGroupStates()" v-show="offlineFriends.length") @@ -95,7 +95,7 @@ mixin friendsListSidebar() span.name(v-if="!hideNicknames && friend.$nickName" :style="{'color':friend.ref.$userColour}") {{ friend.ref.displayName }} ({{ friend.$nickName }}) span.name(v-else v-text="friend.ref.displayName" :style="{'color':friend.ref.$userColour}") span.extra(v-text="friend.ref.statusDescription") - template(v-else-if="friendLogInitStatus") + template(v-else) span(v-text="friend.name || friend.id") el-button(type="text" icon="el-icon-close" size="mini" @click.stop="confirmDeleteFriend(friend.id)" style="margin-left:5px") el-tab-pane