Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Natsumi-sama committed Oct 31, 2024
1 parent 3424398 commit 7c3c14a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
41 changes: 28 additions & 13 deletions html/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
});
Expand All @@ -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');
Expand All @@ -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);
}
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion html/src/classes/currentUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class extends baseClass {
}).then((json) => {
var args = {
json,
origin: true
fromGetCurrentUser: true
};
if (
json.requiresTwoFactorAuth &&
Expand Down
12 changes: 10 additions & 2 deletions html/src/classes/updateLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions html/src/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Expand Down

0 comments on commit 7c3c14a

Please sign in to comment.