feat: add Activity type system, DB migration, and self-only showActivity in sanitizeUser

- Add Activity, ActivityType, ActivityTimestamps, ActivityAssets types to shared types
- Add activity_update client event and activities field on presence_update server event
- Add userActivities to ready payload and showActivity to User/UpdateUserRequest
- Create shared activities.ts with ACTIVITY_LIMITS, ACTIVITY_PRIORITY, getPrimaryActivity
- Add show_activity column to users table (schema + migration)
- Update sanitizeUser with isSelf parameter; only include showActivity for self
- Fix .map(sanitizeUser) calls to use arrow wrapper to prevent index-as-boolean bug
- Mark auth routes (register/login) as isSelf=true since they return own user data
This commit is contained in:
Jannis Braun
2026-03-21 01:38:36 +01:00
parent ce981ee5fc
commit bc408235c9
11 changed files with 83 additions and 18 deletions
+4 -4
View File
@@ -33,7 +33,7 @@ export async function userRoutes(app: FastifyInstance): Promise<void> {
return reply.code(401).send({ error: 'This account has been deleted', statusCode: 401 });
}
return reply.code(200).send(sanitizeUser(user));
return reply.code(200).send(sanitizeUser(user, true));
});
// POST /api/users/@me/verify-password — verify password matches current account
@@ -328,7 +328,7 @@ export async function userRoutes(app: FastifyInstance): Promise<void> {
const storedTs = currentUser.profileUpdatedAt ?? currentUser.createdAt;
if (profileUpdatedAt < storedTs) {
// Incoming data is older — return current state without updating
return reply.code(200).send(sanitizeUser(currentUser));
return reply.code(200).send(sanitizeUser(currentUser, true));
}
}
(updateData as Record<string, unknown>).profileUpdatedAt = profileUpdatedAt;
@@ -373,7 +373,7 @@ export async function userRoutes(app: FastifyInstance): Promise<void> {
return reply.code(404).send({ error: 'User not found', statusCode: 404 });
}
const sanitized = sanitizeUser(updatedUser);
const sanitized = sanitizeUser(updatedUser, true);
// Broadcast presence update if status changed
if (status !== undefined) {
@@ -681,7 +681,7 @@ export async function userRoutes(app: FastifyInstance): Promise<void> {
const mutualFriendIds = [...myFriendIds].filter((id) => targetFriendIds.has(id));
const mutualFriends = mutualFriendIds.length > 0
? db.select().from(schema.users).where(inArray(schema.users.id, mutualFriendIds)).all().map(sanitizeUser)
? db.select().from(schema.users).where(inArray(schema.users.id, mutualFriendIds)).all().map(u => sanitizeUser(u))
: [];
// Mutual spaces: spaces both me and the target are members of