feat: 外部のサーバでも最終更新時刻からオンライン状況を推定

This commit is contained in:
sweshelo 2024-03-18 13:28:17 +09:00 committed by hijiki
parent 46e5192de1
commit 9132e2c701

View File

@ -376,8 +376,9 @@ export class UserEntityService implements OnModuleInit {
@bindThis
public getOnlineStatus(user: MiUser): 'unknown' | 'online' | 'active' | 'offline' {
if (user.hideOnlineStatus) return 'unknown';
if (user.lastActiveDate == null) return 'unknown';
const elapsed = Date.now() - user.lastActiveDate.getTime();
const activeDate = user.lastActiveDate ?? user.updatedAt
if (activeDate == null) return 'unknown';
const elapsed = Date.now() - activeDate.getTime();
return (
elapsed < USER_ONLINE_THRESHOLD ? 'online' :
elapsed < USER_ACTIVE_THRESHOLD ? 'active' :