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
+25
View File
@@ -0,0 +1,25 @@
import type { Activity, ActivityType } from './types.js';
export const ACTIVITY_LIMITS = {
MAX_ACTIVITIES_PER_USER: 5,
MAX_NAME_LENGTH: 128,
MAX_DETAILS_LENGTH: 128,
MAX_STATE_LENGTH: 128,
MAX_ASSET_TEXT_LENGTH: 128,
MAX_URL_LENGTH: 512,
} as const;
export const ACTIVITY_PRIORITY: Record<ActivityType, number> = {
streaming: 5,
playing: 4,
listening: 3,
watching: 2,
custom: 1,
};
export function getPrimaryActivity(activities: Activity[]): Activity | null {
if (!activities.length) return null;
return activities.reduce((best, current) =>
ACTIVITY_PRIORITY[current.type] > ACTIVITY_PRIORITY[best.type] ? current : best
);
}