parent
61461b7f59
commit
68571d8f57
10 changed files with 92 additions and 9 deletions
|
@ -7,6 +7,7 @@ import { SchemaType } from '@/misc/schema';
|
|||
import { awaitAll } from '../../prelude/await-all';
|
||||
import { populateEmojis } from '@/misc/populate-emojis';
|
||||
import { getAntennas } from '@/misc/antenna-cache';
|
||||
import { USER_ACTIVE_THRESHOLD, USER_ONLINE_THRESHOLD } from '@/const';
|
||||
|
||||
export type PackedUser = SchemaType<typeof packedUserSchema>;
|
||||
|
||||
|
@ -145,6 +146,17 @@ export class UserRepository extends Repository<User> {
|
|||
return count > 0;
|
||||
}
|
||||
|
||||
public getOnlineStatus(user: User): string {
|
||||
if (user.hideOnlineStatus == null) return 'unknown';
|
||||
if (user.lastActiveDate == null) return 'unknown';
|
||||
const elapsed = Date.now() - user.lastActiveDate.getTime();
|
||||
return (
|
||||
elapsed < USER_ONLINE_THRESHOLD ? 'online' :
|
||||
elapsed < USER_ACTIVE_THRESHOLD ? 'active' :
|
||||
'offline'
|
||||
);
|
||||
}
|
||||
|
||||
public async pack(
|
||||
src: User['id'] | User,
|
||||
me?: { id: User['id'] } | null | undefined,
|
||||
|
@ -192,6 +204,7 @@ export class UserRepository extends Repository<User> {
|
|||
themeColor: instance.themeColor,
|
||||
} : undefined) : undefined,
|
||||
emojis: populateEmojis(user.emojis, user.host),
|
||||
onlineStatus: this.getOnlineStatus(user),
|
||||
|
||||
...(opts.detail ? {
|
||||
url: profile!.url,
|
||||
|
@ -239,6 +252,7 @@ export class UserRepository extends Repository<User> {
|
|||
autoAcceptFollowed: profile!.autoAcceptFollowed,
|
||||
noCrawle: profile!.noCrawle,
|
||||
isExplorable: user.isExplorable,
|
||||
hideOnlineStatus: user.hideOnlineStatus,
|
||||
hasUnreadSpecifiedNotes: NoteUnreads.count({
|
||||
where: { userId: user.id, isSpecified: true },
|
||||
take: 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue