Skip to content

Commit cee5864

Browse files
committed
chore: Fix seens
1 parent cb3ef1d commit cee5864

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

src/cache/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const PSCommands: { [key: string]: PSCommand & { path: string } } = {};
1616
export const PSAliases: { [key: string]: string } = {};
1717
export const PSNoPrefixHelp: { [key: string]: Date } = {};
1818
export const PSAltCache: { [key: string]: { from: string; to: string; at: Date } } = {};
19-
export const PSSeenCache: { [key: string]: { at: Date; in: string[] } } = {};
19+
export const PSSeenCache: { [key: string]: { id: string; name: string; at: Date; seenIn: string[] } } = {};
2020

2121
export const PSQuoteRoomPrefs: { [key: string]: { room: string; at: Date } } = {};
2222
export const PSCronJobs: { manager: PSCronJobManager | null } = { manager: null };

src/database/seens.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ const schema = new mongoose.Schema({
1616
required: true,
1717
default: Date.now,
1818
},
19-
in: {
19+
name: {
20+
type: String,
21+
required: true,
22+
},
23+
seenIn: {
2024
type: [String],
2125
required: true,
2226
default: [],
@@ -26,13 +30,14 @@ const schema = new mongoose.Schema({
2630
interface Model {
2731
id: string;
2832
at: Date;
29-
in: string[];
33+
name: string;
34+
seenIn: string[];
3035
}
3136
const model = mongoose.model('seen', schema, 'seens');
3237

3338
export function seeUser(user: string, rooms: string[] = []): Promise<Model> {
3439
const userId = toId(user);
35-
return model.findOneAndUpdate({ id: userId }, { id: userId, in: rooms }, { upsert: true, new: true });
40+
return model.findOneAndUpdate({ id: userId }, { id: userId, name: user, seenIn: rooms }, { upsert: true, new: true });
3641
}
3742

3843
export function lastSeen(user: string): Promise<Model | null> {

src/ps/handlers/joins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ export function leaveHandler(this: Client, room: string, user: string, isIntro:
3131
if (Date.now() - PSSeenCache[userId]?.at.getTime() < fromHumanTime('5 seconds')) return;
3232
const userObj = this.getUser(user);
3333
const rooms = userObj && userObj.rooms ? Object.keys(userObj.rooms).map(room => room.replace(/^[^a-z0-9]/, '')) : [room];
34-
PSSeenCache[userId] = { at: new Date(), in: rooms };
34+
PSSeenCache[userId] = { id: toId(user), name: user, at: new Date(), seenIn: rooms };
3535
seeUser(user, rooms);
3636
}

src/ps/loaders/seens.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { PSAltCache } from '@/cache';
2-
import { fetchAllAlts } from '@/database/alts';
1+
import { PSSeenCache } from '@/cache';
2+
import { fetchAllSeens } from '@/database/seens';
33
import { log } from '@/utils/logger';
44

5-
export async function loadAlts(): Promise<void> {
6-
const fetched = await fetchAllAlts();
5+
export async function loadSeens(): Promise<void> {
6+
const fetched = await fetchAllSeens();
77
fetched.forEach(entry => {
8-
const { id, from, to, at } = entry;
9-
PSAltCache[id] = { from, to, at };
8+
const { id, name, at, seenIn } = entry;
9+
PSSeenCache[id] = { id, name, at, seenIn };
1010
});
1111
log('Loaded alts!');
1212
}

0 commit comments

Comments
 (0)