This commit is contained in:
Natsumi
2024-10-31 13:54:18 +13:00
parent 0870805222
commit 97385d4769
5 changed files with 46 additions and 17 deletions

View File

@@ -599,6 +599,14 @@ speechSynthesis.getVoices();
this.applyUserTrustLevel(ref);
this.applyUserLanguage(ref);
this.cachedUsers.set(ref.id, ref);
if (this.currentUser?.offlineFriends.includes(ref.id)) {
$app.addFriend(ref.id, 'offline');
} else if (this.currentUser?.activeFriends.includes(ref.id)) {
$app.addFriend(ref.id, 'active');
} else if (this.currentUser?.onlineFriends.includes(ref.id)) {
$app.addFriend(ref.id, 'online');
}
} else {
var props = {};
for (var prop in ref) {
@@ -4219,7 +4227,7 @@ speechSynthesis.getVoices();
API.$on('USER:CURRENT', function (args) {
// USER:CURRENT에서 처리를 함
$app.refreshFriends(args.ref, args.origin);
$app.refreshFriends(args.ref, args.fromGetCurrentUser);
$app.updateOnlineFriendCoutner();
if ($app.randomUserColours) {
@@ -4252,13 +4260,9 @@ speechSynthesis.getVoices();
$app.updateFriend({ id: args.ref.favoriteId });
});
API.$on('LOGIN', function () {
$app.nextFriendsRefresh = 0;
});
$app.methods.refreshFriendsList = async function () {
// If we just got user less then 1 min before code call, don't call it again
if (this.nextCurrentUserRefresh < 720) {
// If we just got user less then 2 min before code call, don't call it again
if (this.nextCurrentUserRefresh < 300) {
await API.getCurrentUser().catch((err) => {
console.error(err);
});
@@ -4269,7 +4273,10 @@ speechSynthesis.getVoices();
API.reconnectWebSocket();
};
$app.methods.refreshFriends = function (ref, origin) {
$app.methods.refreshFriends = function (ref, fromGetCurrentUser) {
if (!this.friendLogInitStatus) {
return;
}
var map = new Map();
for (var id of ref.friends) {
map.set(id, 'offline');
@@ -4285,7 +4292,7 @@ speechSynthesis.getVoices();
}
for (var [id, state] of map) {
if (this.friends.has(id)) {
this.updateFriend({ id, state, origin });
this.updateFriend({ id, state, fromGetCurrentUser });
} else {
this.addFriend(id, state);
}
@@ -4408,7 +4415,7 @@ speechSynthesis.getVoices();
$app.data.updateFriendInProgress = new Map();
$app.methods.updateFriend = function (ctx) {
var { id, state, origin } = ctx;
var { id, state, fromGetCurrentUser } = ctx;
var stateInput = state;
var ctx = this.friends.get(id);
if (typeof ctx === 'undefined') {
@@ -4475,11 +4482,16 @@ speechSynthesis.getVoices();
}
// from getCurrentUser only, fetch user if offline in an instance
if (
origin &&
fromGetCurrentUser &&
ctx.state !== 'online' &&
typeof ref !== 'undefined' &&
this.isRealInstance(ref.location)
) {
if (this.debugFriendState) {
console.log(
`Fetching offline friend in an instance ${ctx.name}`
);
}
API.getUser({
userId: id
});
@@ -5343,10 +5355,11 @@ speechSynthesis.getVoices();
} else {
await $app.initFriendLog(args.json.id);
}
$app.refreshFriends(args.ref, args.fromGetCurrentUser);
} catch (err) {
if (!$app.dontLogMeOut) {
$app.$message({
message: 'Failed to load freinds list, logging out',
message: 'Failed to load friends list, logging out',
type: 'error'
});
this.logout();
@@ -6855,7 +6868,9 @@ speechSynthesis.getVoices();
API.getUser({
userId: id
});
} catch {}
} catch (err) {
console.error('Fetch user on add as friend', err);
}
return;
}
API.getFriendStatus({

View File

@@ -16,7 +16,7 @@ export default class extends baseClass {
}).then((json) => {
var args = {
json,
origin: true
fromGetCurrentUser: true
};
if (
json.requiresTwoFactorAuth &&

View File

@@ -6,9 +6,17 @@ export default class extends baseClass {
super(_app, _API, _t);
}
init() {
API.$on('LOGIN', function () {
$app.nextCurrentUserRefresh = 300;
$app.nextFriendsRefresh = 3600;
$app.nextGroupInstanceRefresh = 0;
});
}
_data = {
nextCurrentUserRefresh: 0,
nextFriendsRefresh: 0,
nextCurrentUserRefresh: 300,
nextFriendsRefresh: 3600,
nextGroupInstanceRefresh: 0,
nextAppUpdateCheck: 3600,
ipcTimeout: 0,

View File

@@ -106,6 +106,12 @@ html
include ./mixins/dialogs/groupDialog.pug
+groupDialog()
include ./mixins/dialogs/favoritesDialog.pug
+favoritesDialog()
include ./mixins/dialogs/images.pug
+images()
include ./mixins/dialogs/newInstance.pug
+newInstance()

View File

@@ -1,4 +1,4 @@
mixin favorites()
mixin favoritesDialog()
//- dialog: favorite
el-dialog.x-dialog(:before-close="beforeDialogClose" @mousedown.native="dialogMouseDown" @mouseup.native="dialogMouseUp" ref="favoriteDialog" :visible.sync="favoriteDialog.visible" :title="$t('dialog.favorite.header')" width="300px")
div(v-if="favoriteDialog.visible" v-loading="favoriteDialog.loading")