mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-06 14:46:04 +02:00
Another update to friend state handling
This commit is contained in:
+80
-100
@@ -329,8 +329,8 @@ speechSynthesis.getVoices();
|
|||||||
console.error('API.$on(USER) invalid args', args);
|
console.error('API.$on(USER) invalid args', args);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$app.updateFriend({ id: args.json.id, state: args.json.state });
|
$app.updateFriend({ id: args.json.id, state: args.json.state }); // online/offline
|
||||||
args.ref = this.applyUser(args.json);
|
args.ref = this.applyUser(args.json); // GPS
|
||||||
});
|
});
|
||||||
|
|
||||||
API.$on('USER:LIST', function (args) {
|
API.$on('USER:LIST', function (args) {
|
||||||
@@ -1355,47 +1355,6 @@ speechSynthesis.getVoices();
|
|||||||
userId: json.id
|
userId: json.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// we don't update friend state here, it's not reliable
|
|
||||||
var state = 'offline';
|
|
||||||
if (json.platform === 'web') {
|
|
||||||
state = 'active';
|
|
||||||
} else if (json.platform) {
|
|
||||||
state = 'online';
|
|
||||||
}
|
|
||||||
var ref = $app.friends.get(json.id);
|
|
||||||
if (ref?.state !== state) {
|
|
||||||
if ($app.debugFriendState) {
|
|
||||||
console.log(
|
|
||||||
`Bulk friend fetch, friend state does not match ${json.displayName} from ${ref?.state} to ${state}`,
|
|
||||||
json
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.getUser({
|
|
||||||
userId: json.id
|
|
||||||
});
|
|
||||||
} else if (json.location === 'traveling') {
|
|
||||||
if ($app.debugFriendState) {
|
|
||||||
console.log(
|
|
||||||
'Bulk friend fetch, fetching traveling user',
|
|
||||||
json
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.getUser({
|
|
||||||
userId: json.id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (
|
|
||||||
// !args.params.offline &&
|
|
||||||
// json.platform !== 'web' &&
|
|
||||||
// json.location === 'offline'
|
|
||||||
// ) {
|
|
||||||
// console.log('Fetching offline user', json);
|
|
||||||
// this.getUser({
|
|
||||||
// userId: json.id
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1404,29 +1363,34 @@ speechSynthesis.getVoices();
|
|||||||
API.refreshFriends = async function () {
|
API.refreshFriends = async function () {
|
||||||
this.isRefreshFriendsLoading = true;
|
this.isRefreshFriendsLoading = true;
|
||||||
try {
|
try {
|
||||||
var onlineFriends = await this.refreshOnlineFriends();
|
var onlineFriends = await this.bulkRefreshFriends({
|
||||||
var offlineFriends = await this.refreshOfflineFriends();
|
|
||||||
var friends = onlineFriends.concat(offlineFriends);
|
|
||||||
this.isRefreshFriendsLoading = false;
|
|
||||||
return friends;
|
|
||||||
} catch (err) {
|
|
||||||
this.isRefreshFriendsLoading = false;
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
API.refreshOnlineFriends = async function () {
|
|
||||||
var friends = [];
|
|
||||||
var params = {
|
|
||||||
n: 50,
|
|
||||||
offset: 0,
|
|
||||||
offline: false
|
offline: false
|
||||||
|
});
|
||||||
|
var offlineFriends = await this.bulkRefreshFriends({
|
||||||
|
offline: true
|
||||||
|
});
|
||||||
|
var friends = onlineFriends.concat(offlineFriends);
|
||||||
|
friends = await this.refetchBrokenFriends(friends);
|
||||||
|
if (!$app.friendLogInitStatus) {
|
||||||
|
friends = await this.refreshRemainingFriends(friends);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isRefreshFriendsLoading = false;
|
||||||
|
return friends;
|
||||||
|
} catch (err) {
|
||||||
|
this.isRefreshFriendsLoading = false;
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
var N =
|
|
||||||
this.currentUser.onlineFriends.length +
|
API.bulkRefreshFriends = async function (params) {
|
||||||
this.currentUser.activeFriends.length;
|
var friends = [];
|
||||||
var count = Math.trunc(N / 50);
|
var params = {
|
||||||
mainLoop: for (var i = count; i > -1; i--) {
|
...params,
|
||||||
|
n: 50,
|
||||||
|
offset: 0
|
||||||
|
};
|
||||||
|
mainLoop: for (var i = 100; i > -1; i--) {
|
||||||
if (params.offset > 5000) {
|
if (params.offset > 5000) {
|
||||||
// API offset limit is 5000
|
// API offset limit is 5000
|
||||||
break;
|
break;
|
||||||
@@ -1436,6 +1400,9 @@ speechSynthesis.getVoices();
|
|||||||
try {
|
try {
|
||||||
var args = await this.getFriends(params);
|
var args = await this.getFriends(params);
|
||||||
friends = friends.concat(args.json);
|
friends = friends.concat(args.json);
|
||||||
|
if (!args.json || args.json.length < 50) {
|
||||||
|
break mainLoop;
|
||||||
|
}
|
||||||
break retryLoop;
|
break retryLoop;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@@ -1460,48 +1427,60 @@ speechSynthesis.getVoices();
|
|||||||
return friends;
|
return friends;
|
||||||
};
|
};
|
||||||
|
|
||||||
API.refreshOfflineFriends = async function () {
|
API.refreshRemainingFriends = async function (friends) {
|
||||||
var friends = [];
|
for (var userId of this.currentUser.friends) {
|
||||||
var params = {
|
if (!friends.some((x) => x.id === userId)) {
|
||||||
n: 50,
|
|
||||||
offset: 0,
|
|
||||||
offline: true
|
|
||||||
};
|
|
||||||
var onlineCount =
|
|
||||||
this.currentUser.onlineFriends.length +
|
|
||||||
this.currentUser.activeFriends.length;
|
|
||||||
var N = this.currentUser.friends.length - onlineCount;
|
|
||||||
var count = Math.trunc(N / 50);
|
|
||||||
mainLoop: for (var i = count; i > -1; i--) {
|
|
||||||
if (params.offset > 5000) {
|
|
||||||
// API offset limit is 5000
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
retryLoop: for (var j = 0; j < 10; j++) {
|
|
||||||
// handle 429 ratelimit error, retry 10 times
|
|
||||||
try {
|
try {
|
||||||
var args = await this.getFriends(params);
|
console.log('Fetching remaining friend', userId);
|
||||||
friends = friends.concat(args.json);
|
var args = await this.getUser({ userId });
|
||||||
break retryLoop;
|
friends.push(args.json);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
if (!API.currentUser.isLoggedIn) {
|
|
||||||
console.error(`User isn't logged in`);
|
|
||||||
break mainLoop;
|
|
||||||
}
|
}
|
||||||
if (err?.message?.includes('Not Found')) {
|
|
||||||
console.error('Awful workaround for awful VRC API bug');
|
|
||||||
break retryLoop;
|
|
||||||
}
|
}
|
||||||
if (j === 9) {
|
|
||||||
throw err;
|
|
||||||
}
|
}
|
||||||
await new Promise((resolve) => {
|
return friends;
|
||||||
workerTimers.setTimeout(resolve, 5000);
|
};
|
||||||
|
|
||||||
|
API.refetchBrokenFriends = async function (friends) {
|
||||||
|
// attempt to broken data from bulk friend fetch
|
||||||
|
for (var i = 0; i < friends.length; i++) {
|
||||||
|
var friend = friends[i];
|
||||||
|
try {
|
||||||
|
// we don't update friend state here, it's not reliable
|
||||||
|
var state = 'offline';
|
||||||
|
if (friend.platform === 'web') {
|
||||||
|
state = 'active';
|
||||||
|
} else if (friend.platform) {
|
||||||
|
state = 'online';
|
||||||
|
}
|
||||||
|
var ref = $app.friends.get(friend.id);
|
||||||
|
if (ref?.state !== state) {
|
||||||
|
if ($app.debugFriendState) {
|
||||||
|
console.log(
|
||||||
|
`Refetching friend state it does not match ${friend.displayName} from ${ref?.state} to ${state}`,
|
||||||
|
friend
|
||||||
|
);
|
||||||
|
}
|
||||||
|
var args = await this.getUser({
|
||||||
|
userId: friend.id
|
||||||
});
|
});
|
||||||
|
friends[i] = args.json;
|
||||||
|
} else if (friend.location === 'traveling') {
|
||||||
|
if ($app.debugFriendState) {
|
||||||
|
console.log(
|
||||||
|
'Refetching traveling friend',
|
||||||
|
friend.displayName
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
var args = await this.getUser({
|
||||||
|
userId: friend.id
|
||||||
|
});
|
||||||
|
friends[i] = args.json;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
}
|
}
|
||||||
params.offset += 50;
|
|
||||||
}
|
}
|
||||||
return friends;
|
return friends;
|
||||||
};
|
};
|
||||||
@@ -5495,6 +5474,7 @@ speechSynthesis.getVoices();
|
|||||||
$app.applyGroupDialogInstances();
|
$app.applyGroupDialogInstances();
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
|
!props.state &&
|
||||||
props.location &&
|
props.location &&
|
||||||
props.location[0] !== 'offline' &&
|
props.location[0] !== 'offline' &&
|
||||||
props.location[0] !== '' &&
|
props.location[0] !== '' &&
|
||||||
@@ -5506,7 +5486,7 @@ speechSynthesis.getVoices();
|
|||||||
var previousLocation = props.location[1];
|
var previousLocation = props.location[1];
|
||||||
var newLocation = props.location[0];
|
var newLocation = props.location[0];
|
||||||
var time = props.location[2];
|
var time = props.location[2];
|
||||||
if (previousLocation === 'traveling') {
|
if (previousLocation === 'traveling' && ref.$previousLocation) {
|
||||||
previousLocation = ref.$previousLocation;
|
previousLocation = ref.$previousLocation;
|
||||||
var travelTime = Date.now() - ref.$travelingToTime;
|
var travelTime = Date.now() - ref.$travelingToTime;
|
||||||
time -= travelTime;
|
time -= travelTime;
|
||||||
@@ -6877,8 +6857,8 @@ speechSynthesis.getVoices();
|
|||||||
this.updateFriendship(ref);
|
this.updateFriendship(ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (typeof API.currentUser.friends !== 'undefined') {
|
if (typeof currentUser.friends !== 'undefined') {
|
||||||
this.updateFriendships(API.currentUser);
|
this.updateFriendships(currentUser);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user