Fix empty GPS while friend is coming online

This commit is contained in:
Natsumi
2024-11-02 15:34:25 +13:00
parent e3fa956be5
commit a7c5a59689
3 changed files with 74 additions and 46 deletions
+44 -35
View File
@@ -325,7 +325,7 @@ speechSynthesis.getVoices();
}); });
API.$on('USER', function (args) { API.$on('USER', function (args) {
if (!args?.json?.displayName) { if (!args?.json?.id) {
console.error('API.$on(USER) invalid args', args); console.error('API.$on(USER) invalid args', args);
return; 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) { API.applyUser = function (json) {
var ref = this.cachedUsers.get(json.id); var ref = this.cachedUsers.get(json.id);
if (typeof json.statusDescription !== 'undefined') { if (typeof json.statusDescription !== 'undefined') {
@@ -668,7 +651,7 @@ speechSynthesis.getVoices();
props.location.push(ts - ref.$location_at); props.location.push(ts - ref.$location_at);
ref.$location_at = ts; ref.$location_at = ts;
} }
queueUserUpdate({ API.$emit('USER:UPDATE', {
ref, ref,
props props
}); });
@@ -1383,7 +1366,8 @@ speechSynthesis.getVoices();
if (ref?.state !== state) { if (ref?.state !== state) {
if ($app.debugFriendState) { if ($app.debugFriendState) {
console.log( 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({ this.getUser({
@@ -4232,7 +4216,9 @@ speechSynthesis.getVoices();
API.$on('USER:CURRENT', function (args) { API.$on('USER:CURRENT', function (args) {
// USER:CURRENT에서 처리를 함 // USER:CURRENT에서 처리를 함
if ($app.friendLogInitStatus) {
$app.refreshFriends(args.ref, args.fromGetCurrentUser); $app.refreshFriends(args.ref, args.fromGetCurrentUser);
}
$app.updateOnlineFriendCoutner(); $app.updateOnlineFriendCoutner();
if ($app.randomUserColours) { if ($app.randomUserColours) {
@@ -4346,12 +4332,17 @@ speechSynthesis.getVoices();
} }
var ref = API.cachedUsers.get(id); var ref = API.cachedUsers.get(id);
var isVIP = this.localFavoriteFriends.has(id); var isVIP = this.localFavoriteFriends.has(id);
var name = '';
var friend = this.friendLog.get(id);
if (friend) {
name = friend.displayName;
}
var ctx = { var ctx = {
id, id,
state: state || 'offline', state: state || 'offline',
isVIP, isVIP,
ref, ref,
name: '', name,
no: ++this.friendsNo, no: ++this.friendsNo,
memo: '', memo: '',
pendingOffline: false, pendingOffline: false,
@@ -4574,7 +4565,9 @@ speechSynthesis.getVoices();
return; return;
} }
if (this.debugFriendState) { 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 isVIP = this.localFavoriteFriends.has(id);
var ref = ctx.ref; var ref = ctx.ref;
@@ -5333,6 +5326,7 @@ speechSynthesis.getVoices();
$app.friendLogInitStatus = false; $app.friendLogInitStatus = false;
await database.initUserTables(args.json.id); await database.initUserTables(args.json.id);
$app.$refs.menu.activeIndex = 'feed'; $app.$refs.menu.activeIndex = 'feed';
await $app.updateDatabaseVersion();
// eslint-disable-next-line require-atomic-updates // eslint-disable-next-line require-atomic-updates
$app.gameLogTable.data = await database.lookupGameLogDatabase( $app.gameLogTable.data = await database.lookupGameLogDatabase(
$app.gameLogTable.search, $app.gameLogTable.search,
@@ -5349,14 +5343,13 @@ speechSynthesis.getVoices();
args.json?.presence?.groups args.json?.presence?.groups
); );
await $app.getCurrentUserGroups(); await $app.getCurrentUserGroups();
$app.refreshFriends(args.ref, args.fromGetCurrentUser);
try { try {
if ( if (
await configRepository.getBool(`friendLogInit_${args.json.id}`) await configRepository.getBool(`friendLogInit_${args.json.id}`)
) { ) {
await $app.getFriendLog(); await $app.getFriendLog(args.ref);
} else { } else {
await $app.initFriendLog(args.json.id); await $app.initFriendLog(args.ref);
} }
} catch (err) { } catch (err) {
if (!$app.dontLogMeOut) { if (!$app.dontLogMeOut) {
@@ -5487,6 +5480,7 @@ speechSynthesis.getVoices();
) { ) {
// skip GPS if user is offline or traveling // skip GPS if user is offline or traveling
var previousLocation = props.location[1]; var previousLocation = props.location[1];
var newLocation = props.location[0];
var time = props.location[2]; var time = props.location[2];
if (previousLocation === 'traveling') { if (previousLocation === 'traveling') {
previousLocation = ref.$previousLocation; previousLocation = ref.$previousLocation;
@@ -5496,18 +5490,32 @@ speechSynthesis.getVoices();
time = 0; 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 // location traveled to is the same
ref.$location_at = Date.now() - props.location[2]; ref.$location_at = Date.now() - time;
} else { } else {
var worldName = await $app.getWorldName(props.location[0]); var worldName = await $app.getWorldName(newLocation);
var groupName = await $app.getGroupName(props.location[0]); var groupName = await $app.getGroupName(newLocation);
var feed = { var feed = {
created_at: new Date().toJSON(), created_at: new Date().toJSON(),
type: 'GPS', type: 'GPS',
userId: ref.id, userId: ref.id,
displayName: ref.displayName, displayName: ref.displayName,
location: props.location[0], location: newLocation,
worldName, worldName,
groupName, groupName,
previousLocation, previousLocation,
@@ -6798,8 +6806,8 @@ speechSynthesis.getVoices();
$app.data.friendLogInitStatus = false; $app.data.friendLogInitStatus = false;
$app.methods.initFriendLog = async function (userId) { $app.methods.initFriendLog = async function (currentUser) {
await this.updateDatabaseVersion(); this.refreshFriends(currentUser, true);
var sqlValues = []; var sqlValues = [];
var friends = await API.refreshFriends(); var friends = await API.refreshFriends();
for (var friend of friends) { for (var friend of friends) {
@@ -6813,7 +6821,7 @@ speechSynthesis.getVoices();
sqlValues.unshift(row); sqlValues.unshift(row);
} }
database.setFriendLogCurrentArray(sqlValues); database.setFriendLogCurrentArray(sqlValues);
await configRepository.setBool(`friendLogInit_${userId}`, true); await configRepository.setBool(`friendLogInit_${currentUser.id}`, true);
this.friendLogInitStatus = true; this.friendLogInitStatus = true;
}; };
@@ -6828,14 +6836,14 @@ speechSynthesis.getVoices();
await configRepository.setBool(`friendLogInit_${userId}`, true); await configRepository.setBool(`friendLogInit_${userId}`, true);
}; };
$app.methods.getFriendLog = async function () { $app.methods.getFriendLog = async function (currentUser) {
await this.updateDatabaseVersion();
var friendLogCurrentArray = await database.getFriendLogCurrent(); var friendLogCurrentArray = await database.getFriendLogCurrent();
for (var friend of friendLogCurrentArray) { for (var friend of friendLogCurrentArray) {
this.friendLog.set(friend.userId, friend); this.friendLog.set(friend.userId, friend);
} }
this.friendLogTable.data = []; this.friendLogTable.data = [];
this.friendLogTable.data = await database.getFriendLogHistory(); this.friendLogTable.data = await database.getFriendLogHistory();
this.refreshFriends(currentUser, true);
await API.refreshFriends(); await API.refreshFriends();
this.friendLogInitStatus = true; this.friendLogInitStatus = true;
// check for friend/name/rank change AFTER friendLogInitStatus is set // check for friend/name/rank change AFTER friendLogInitStatus is set
@@ -17790,6 +17798,7 @@ speechSynthesis.getVoices();
if (!API.isLoggedIn) { if (!API.isLoggedIn) {
return; return;
} }
console.log('LaunchCommand:', input);
var args = input.split('/'); var args = input.split('/');
var command = args[0]; var command = args[0];
var commandArg = args[1]; var commandArg = args[1];
+25 -6
View File
@@ -295,9 +295,18 @@ export default class extends baseClass {
} }
}); });
} else { } else {
this.$emit('FRIEND:STATE', { this.$emit('USER', {
json: { json: {
state: 'active' id: content.userId,
platform: content.platform,
state: 'active',
location: 'offline',
worldId: 'offline',
instanceId: 'offline',
travelingToLocation: 'offline',
travelingToWorld: 'offline',
travelingToInstance: 'offline'
}, },
params: { params: {
userId: content.userId userId: content.userId
@@ -307,9 +316,19 @@ export default class extends baseClass {
break; break;
case 'friend-offline': case 'friend-offline':
this.$emit('FRIEND:STATE', { // more JANK, hell yeah
this.$emit('USER', {
json: { json: {
state: 'offline' id: content.userId,
platform: content.platform,
state: 'offline',
location: 'offline',
worldId: 'offline',
instanceId: 'offline',
travelingToLocation: 'offline',
travelingToWorld: 'offline',
travelingToInstance: 'offline'
}, },
params: { params: {
userId: content.userId userId: content.userId
@@ -348,8 +367,8 @@ export default class extends baseClass {
json: { json: {
location: content.location, location: content.location,
travelingToLocation: content.travelingToLocation, travelingToLocation: content.travelingToLocation,
...content.user ...content.user,
// state: 'online' state: 'online' // JANK
}, },
params: { params: {
userId: content.userId userId: content.userId
+4 -4
View File
@@ -49,7 +49,7 @@ mixin friendsListSidebar()
span.name(v-else v-text="friend.ref.displayName" :style="{'color':friend.ref.$userColour}") 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') }} 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") 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") 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-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") .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.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') }} 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") 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") 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-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") .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-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.name(v-else v-text="friend.ref.displayName" :style="{'color':friend.ref.$userColour}")
span.extra(v-text="friend.ref.statusDescription" :link="false") span.extra(v-text="friend.ref.statusDescription" :link="false")
template(v-else-if="friendLogInitStatus") template(v-else)
span(v-text="friend.name || friend.id") 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-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") .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-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.name(v-else v-text="friend.ref.displayName" :style="{'color':friend.ref.$userColour}")
span.extra(v-text="friend.ref.statusDescription") span.extra(v-text="friend.ref.statusDescription")
template(v-else-if="friendLogInitStatus") template(v-else)
span(v-text="friend.name || friend.id") 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-button(type="text" icon="el-icon-close" size="mini" @click.stop="confirmDeleteFriend(friend.id)" style="margin-left:5px")
el-tab-pane el-tab-pane