From cd94aeeb1a60d9924d99c25c6fb219e293ac04be Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Fri, 6 Sep 2024 13:47:41 +0200 Subject: [PATCH] Improve user history logging --- .../admin-panel/user-support/userHistory.vue | 6 +++++- website/server/libs/cron.js | 2 +- website/server/models/group.js | 10 +++++++++- website/server/models/userHistory.js | 4 +++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/website/client/src/components/admin-panel/user-support/userHistory.vue b/website/client/src/components/admin-panel/user-support/userHistory.vue index 0374174198..31798f942c 100644 --- a/website/client/src/components/admin-panel/user-support/userHistory.vue +++ b/website/client/src/components/admin-panel/user-support/userHistory.vue @@ -97,7 +97,7 @@ @@ -125,6 +125,9 @@ Client + + Checkin Count + {{ entry.timestamp | timeAgo }} {{ entry.client }} + {{ entry.checkinCount }} diff --git a/website/server/libs/cron.js b/website/server/libs/cron.js index a4b6fa425e..412711eb1e 100644 --- a/website/server/libs/cron.js +++ b/website/server/libs/cron.js @@ -525,7 +525,7 @@ export async function cron (options = {}) { trackCronAnalytics(analytics, user, _progress, options); await UserHistory.beginUserHistoryUpdate(user._id, options.headers) - .withCron() + .withCron(user.flags.cronCount) .commit(); return _progress; diff --git a/website/server/models/group.js b/website/server/models/group.js index 6db5ff3e05..fa589add5a 100644 --- a/website/server/models/group.js +++ b/website/server/models/group.js @@ -38,6 +38,7 @@ import stripePayments from '../libs/payments/stripe'; // eslint-disable-line imp import { getGroupChat, translateMessage } from '../libs/chat/group-chat'; // eslint-disable-line import/no-cycle import { model as UserNotification } from './userNotification'; import { sendChatPushNotifications } from '../libs/chat'; // eslint-disable-line import/no-cycle +import { model as UserHistory } from './userHistory'; // eslint-disable-line import/no-cycle const questScrolls = shared.content.quests; const { questSeriesAchievements } = shared.content; @@ -679,7 +680,8 @@ schema.methods.startQuest = async function startQuest (user) { } const nonMembers = Object.keys(_.pickBy(this.quest.members, member => !member)); - + const noResponseMembers = Object.keys(_.pickBy(this.quest.members, member => member === null)); + console.log(this.quest.members, nonMembers, noResponseMembers); // Changes quest.members to only include participating members this.quest.members = _.pickBy(this.quest.members, _.identity); @@ -751,6 +753,12 @@ schema.methods.startQuest = async function startQuest (user) { _id: { $in: nonMembers }, }, _cleanQuestParty()).exec(); + noResponseMembers.forEach(member => { + UserHistory.beginUserHistoryUpdate(member) + .withQuestInviteResponse(this.quest.key, 'no response') + .commit(); + }); + const newMessage = await this.sendChat({ message: `\`${shared.i18n.t('chatQuestStarted', { questName: quest.text('en') }, 'en')}\``, metaData: { diff --git a/website/server/models/userHistory.js b/website/server/models/userHistory.js index 88530a7d98..435a650daa 100644 --- a/website/server/models/userHistory.js +++ b/website/server/models/userHistory.js @@ -34,6 +34,7 @@ export const schema = new Schema({ { _id: false, timestamp: { $type: Date, required: true }, + checkinCount: { $type: Number, required: true }, client: { $type: String, required: false }, }, ], @@ -110,9 +111,10 @@ model.beginUserHistoryUpdate = function beginUserHistoryUpdate (userID, headers }); return this; }, - withCron: function withCron () { + withCron: function withCron (checkinCount) { this.data.cron.push({ timestamp: new Date(), + checkinCount, client: this.data.headers['x-client'], }); return this;