From 85cea30e77b819dc452911a1853aa23ee8a4facd Mon Sep 17 00:00:00 2001 From: Natsumi Date: Wed, 17 Jul 2024 10:58:56 +1200 Subject: [PATCH] Last time joined instance timer --- html/src/app.js | 63 ++++++++++++++++++++++++++++++++ html/src/index.pug | 3 ++ html/src/localization/en/en.json | 1 + html/src/repository/database.js | 19 ++++++++++ 4 files changed, 86 insertions(+) diff --git a/html/src/app.js b/html/src/app.js index 48fb93fe..e303f152 100644 --- a/html/src/app.js +++ b/html/src/app.js @@ -1101,6 +1101,39 @@ speechSynthesis.getVoices(); } }); + Vue.component('last-join', { + template: + '' + + '' + + '
' + + '{{ $t("dialog.user.info.last_join") }} ' + + '
' + + '' + + '
' + + '
', + props: { + location: String + }, + data() { + return { + lastJoin: this.lastJoin + }; + }, + methods: { + parse() { + this.lastJoin = $app.instanceJoinHistory.get(this.location); + } + }, + watch: { + locationobject() { + this.parse(); + } + }, + created() { + this.parse(); + } + }); + Vue.component('instance-info', { template: '
' + @@ -10897,6 +10930,7 @@ speechSynthesis.getVoices(); } break; case 'location': + this.addInstanceJoinHistory(this.lastLocation, gameLog.dt); var worldName = this.replaceBioSymbols(gameLog.worldName); if (this.isGameRunning) { this.lastLocationReset(gameLog.dt); @@ -10916,6 +10950,7 @@ speechSynthesis.getVoices(); this.applyWorldDialogInstances(); this.applyGroupDialogInstances(); } + this.addInstanceJoinHistory(gameLog.location, gameLog.dt); var L = API.parseLocation(gameLog.location); var entry = { created_at: gameLog.dt, @@ -32919,6 +32954,34 @@ speechSynthesis.getVoices(); // #endregion + // #region instance join history + + $app.data.instanceJoinHistory = new Map(); + + API.$on('LOGIN', function () { + $app.instanceJoinHistory = new Map(); + $app.getInstanceJoinHistory(); + }); + + $app.methods.getInstanceJoinHistory = async function () { + this.instanceJoinHistory = await database.getInstanceJoinHistory(); + }; + + $app.methods.addInstanceJoinHistory = function (location, dateTime) { + if (!location || !dateTime) { + return; + } + + if (this.instanceJoinHistory.has(location)) { + this.instanceJoinHistory.delete(location); + } + + var epoch = new Date(dateTime).getTime(); + this.instanceJoinHistory.set(location, epoch); + }; + + // #endregion + $app = new Vue($app); window.$app = $app; })(); diff --git a/html/src/index.pug b/html/src/index.pug index 3adfcede..e41d9187 100644 --- a/html/src/index.pug +++ b/html/src/index.pug @@ -332,6 +332,7 @@ html invite-yourself(:location="userDialog.$location.tag" :shortname="userDialog.$location.shortName" style="margin-left:5px") el-tooltip(placement="top" :content="$t('dialog.user.info.refresh_instance_info')" :disabled="hideTooltips") el-button(@click="refreshInstancePlayerCount(userDialog.$location.tag)" size="mini" icon="el-icon-refresh" style="margin-left:5px" circle) + last-join(:location="userDialog.$location.tag") instance-info(:location="userDialog.$location.tag" :instance="userDialog.instance.ref" :friendcount="userDialog.instance.friendCount" :updateelement="updateInstanceInfo") location(:location="userDialog.ref.location" :traveling="userDialog.ref.travelingToLocation" style="display:block;margin-top:5px") .x-friend-list(style="flex:1;margin-top:10px;max-height:150px") @@ -707,6 +708,7 @@ html invite-yourself(:location="room.$location.tag" :shortname="room.$location.shortName" style="margin-left:5px") el-tooltip(placement="top" :content="$t('dialog.world.instances.refresh_instance_info')" :disabled="hideTooltips") el-button(@click="refreshInstancePlayerCount(room.tag)" size="mini" icon="el-icon-refresh" style="margin-left:5px" circle) + last-join(:location="room.$location.tag") instance-info(:location="room.tag" :instance="room.ref" :friendcount="room.friendCount" :updateelement="updateInstanceInfo") .x-friend-list(style="margin:10px 0;max-height:unset" v-if="room.$location.userId || room.users.length") .x-friend-item(v-if="room.$location.userId" @click="showUserDialog(room.$location.userId)" class="x-friend-item-border") @@ -1053,6 +1055,7 @@ html invite-yourself(:location="room.tag" style="margin-left:5px") el-tooltip(placement="top" content="Refresh player count" :disabled="hideTooltips") el-button(@click="refreshInstancePlayerCount(room.tag)" size="mini" icon="el-icon-refresh" style="margin-left:5px" circle) + last-join(:location="room.tag") instance-info(:location="room.tag" :instance="room.ref" :friendcount="room.friendCount" :updateelement="updateInstanceInfo") .x-friend-list(style="margin:10px 0;padding:0;max-height:unset" v-if="room.users.length") .x-friend-item(v-for="user in room.users" :key="user.id" @click="showUserDialog(user.id)" class="x-friend-item-border") diff --git a/html/src/localization/en/en.json b/html/src/localization/en/en.json index b61e6156..796c96e1 100644 --- a/html/src/localization/en/en.json +++ b/html/src/localization/en/en.json @@ -597,6 +597,7 @@ "instance_queue": "Queue:", "instance_users": "Users:", "instance_game_version": "Game Version:", + "last_join": "Last Join:", "instance_queuing_enabled": "Queuing Enabled", "instance_creator": "Instance Creator", "note": "Note", diff --git a/html/src/repository/database.js b/html/src/repository/database.js index 1c1f8345..90b3b4ef 100644 --- a/html/src/repository/database.js +++ b/html/src/repository/database.js @@ -2530,6 +2530,25 @@ class Database { async setWal() { await sqliteService.executeNonQuery('PRAGMA journal_mode=WAL'); } + + async getInstanceJoinHistory() { + var oneWeekAgo = new Date(Date.now() - 604800000).toJSON(); + var instances = new Map(); + await sqliteService.execute( + (row) => { + if (!instances.has(row[1])) { + var epoch = new Date(row[0]).getTime(); + instances.set(row[1], epoch); + } + }, + `SELECT created_at, location FROM gamelog_join_leave WHERE user_id = @userId AND created_at > @created_at ORDER BY created_at DESC`, + { + '@userId': Database.userId, + '@created_at': oneWeekAgo + } + ); + return instances; + } } var self = new Database();