Skip to content

Commit 8a0b51e

Browse files
committed
chore: Update/remove comments
1 parent 1688107 commit 8a0b51e

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/database/points.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ const schema = new mongoose.Schema<MapModel>({
3232
},
3333
});
3434

35-
export const model = mongoose.model<MapModel>('point', schema, 'points', {
36-
overwriteModels: true,
37-
});
35+
export const model = mongoose.model<MapModel>('point', schema, 'points', { overwriteModels: true });
3836

3937
const DEFAULT_LB_USERS_CAP = 50;
4038

src/database/seens.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import mongoose from 'mongoose';
22

3+
import { IS_ENABLED } from '@/enabled';
34
import { toId } from '@/tools';
45

56
// We don't really care about storing joins (since we can just use their 'online' status)
@@ -36,16 +37,19 @@ const schema = new mongoose.Schema<Model>({
3637

3738
const model = mongoose.model<Model>('seen', schema, 'seens', { overwriteModels: true });
3839

39-
export function seeUser(user: string, rooms: string[] = [], at = new Date()): Promise<Model> {
40+
export async function seeUser(user: string, rooms: string[] = [], at = new Date()): Promise<Model | null> {
41+
if (!IS_ENABLED.DB) return null;
4042
const userId = toId(user);
4143
return model.findOneAndUpdate({ id: userId }, { id: userId, name: user, seenIn: rooms, at }, { upsert: true, new: true });
4244
}
4345

44-
export function lastSeen(user: string): Promise<Model | null> {
46+
export async function lastSeen(user: string): Promise<Model | null> {
47+
if (!IS_ENABLED.DB) return null;
4548
const userId = toId(user);
4649
return model.findOne({ id: userId });
4750
}
4851

49-
export function fetchAllSeens(): Promise<Model[]> {
52+
export async function fetchAllSeens(): Promise<Model[]> {
53+
if (!IS_ENABLED.DB) return [];
5054
return model.find({}).lean();
5155
}

src/ps/handlers/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export async function commandHandler(message: PSMessage, indirect: IndirectCtx |
116116
return await commandObj.run({ ...context, message });
117117
} catch (err) {
118118
if (err instanceof Error) {
119+
// TODO: Ping the user in case they're in another room! (Eg: for spoof messages)
119120
message.privateReply(err.message as string);
120121
if (err.name !== 'ChatError') Logger.errorLog(err);
121122
} else {

src/ps/handlers/joins.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ export function nickHandler(this: Client, room: string, newName: string, oldName
2929
to = toId(newName),
3030
id = `${from}-${to}`;
3131
if (from === to) return;
32-
// Throttling cache updates at once per 5s per rename (A-B)
33-
// TODO: Use debounce
3432
DebounceAltCache[id] ??= {
3533
at: new Date(),
3634
call: debounce(() => rename(oldName, newName), fromHumanTime('5 seconds')),
@@ -44,11 +42,10 @@ const DebounceSeenCache: Record<string, { name: string; at: Date; call: (rooms:
4442
export function leaveHandler(this: Client, room: string, name: string, isIntro: boolean): void {
4543
if (isIntro) return;
4644
const userId = toId(name);
47-
// Throttling cache updates at once per 5s per leave
4845
DebounceSeenCache[userId] ??= {
4946
name,
5047
at: new Date(),
51-
call: debounce(rooms => seeUser(name, rooms, DebounceSeenCache[userId].at), fromHumanTime('5 seconds')),
48+
call: debounce((rooms: string[]) => seeUser(name, rooms.unique(), DebounceSeenCache[userId].at), fromHumanTime('5 seconds')),
5249
};
5350
DebounceSeenCache[userId].at = new Date();
5451
const userObj = this.getUser(name);

0 commit comments

Comments
 (0)