upd: federate listenbrainz, fix background federation

This commit is contained in:
Mar0xy 2023-10-06 20:53:34 +02:00
parent f81d6f8e24
commit 67cfa53118
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828
4 changed files with 15 additions and 4 deletions

View file

@ -523,6 +523,10 @@ export class ApRendererService {
person['vcard:Address'] = profile.location; person['vcard:Address'] = profile.location;
} }
if (profile.listenbrainz) {
person.listenbrainz = profile.listenbrainz;
}
return person; return person;
} }
@ -797,6 +801,7 @@ export class ApRendererService {
// Sharkey // Sharkey
sharkey: "https://joinsharkey.org/ns#", sharkey: "https://joinsharkey.org/ns#",
backgroundUrl: "sharkey:backgroundUrl", backgroundUrl: "sharkey:backgroundUrl",
listenbrainz: "sharkey:listenbrainz",
// vcard // vcard
vcard: 'http://www.w3.org/2006/vcard/ns#', vcard: 'http://www.w3.org/2006/vcard/ns#',
}, },

View file

@ -225,8 +225,8 @@ export class ApPersonService implements OnModuleInit {
return null; return null;
} }
private async resolveAvatarAndBanner(user: MiRemoteUser, icon: any, image: any): Promise<Pick<MiRemoteUser, 'avatarId' | 'bannerId' | 'backgroundId' | 'avatarUrl' | 'bannerUrl' | 'backgroundUrl' | 'avatarBlurhash' | 'bannerBlurhash' | 'backgroundBlurhash'>> { private async resolveAvatarAndBanner(user: MiRemoteUser, icon: any, image: any, bgimg: any): Promise<Pick<MiRemoteUser, 'avatarId' | 'bannerId' | 'backgroundId' | 'avatarUrl' | 'bannerUrl' | 'backgroundUrl' | 'avatarBlurhash' | 'bannerBlurhash' | 'backgroundBlurhash'>> {
const [avatar, banner, background] = await Promise.all([icon, image].map(img => { const [avatar, banner, background] = await Promise.all([icon, image, bgimg].map(img => {
if (img == null) return null; if (img == null) return null;
if (user == null) throw new Error('failed to create user: user is null'); if (user == null) throw new Error('failed to create user: user is null');
return this.apImageService.resolveImage(user, img).catch(() => null); return this.apImageService.resolveImage(user, img).catch(() => null);
@ -307,6 +307,7 @@ export class ApPersonService implements OnModuleInit {
id: this.idService.genId(), id: this.idService.genId(),
avatarId: null, avatarId: null,
bannerId: null, bannerId: null,
backgroundId: null,
createdAt: new Date(), createdAt: new Date(),
lastFetchedAt: new Date(), lastFetchedAt: new Date(),
name: truncate(person.name, nameLength), name: truncate(person.name, nameLength),
@ -341,6 +342,7 @@ export class ApPersonService implements OnModuleInit {
birthday: bday?.[0] ?? null, birthday: bday?.[0] ?? null,
location: person['vcard:Address'] ?? null, location: person['vcard:Address'] ?? null,
userHost: host, userHost: host,
listenbrainz: person.listenbrainz ?? null,
})); }));
if (person.publicKey) { if (person.publicKey) {
@ -386,7 +388,7 @@ export class ApPersonService implements OnModuleInit {
//#region アバターとヘッダー画像をフェッチ //#region アバターとヘッダー画像をフェッチ
try { try {
const updates = await this.resolveAvatarAndBanner(user, person.icon, person.image); const updates = await this.resolveAvatarAndBanner(user, person.icon, person.image, person.backgroundUrl);
await this.usersRepository.update(user.id, updates); await this.usersRepository.update(user.id, updates);
user = { ...user, ...updates }; user = { ...user, ...updates };
@ -469,7 +471,7 @@ export class ApPersonService implements OnModuleInit {
movedToUri: person.movedTo ?? null, movedToUri: person.movedTo ?? null,
alsoKnownAs: person.alsoKnownAs ?? null, alsoKnownAs: person.alsoKnownAs ?? null,
isExplorable: person.discoverable, isExplorable: person.discoverable,
...(await this.resolveAvatarAndBanner(exist, person.icon, person.image).catch(() => ({}))), ...(await this.resolveAvatarAndBanner(exist, person.icon, person.image, person.backgroundUrl).catch(() => ({}))),
} as Partial<MiRemoteUser> & Pick<MiRemoteUser, 'isBot' | 'isCat' | 'speakAsCat' | 'isLocked' | 'movedToUri' | 'alsoKnownAs' | 'isExplorable'>; } as Partial<MiRemoteUser> & Pick<MiRemoteUser, 'isBot' | 'isCat' | 'speakAsCat' | 'isLocked' | 'movedToUri' | 'alsoKnownAs' | 'isExplorable'>;
const moving = ((): boolean => { const moving = ((): boolean => {
@ -508,6 +510,7 @@ export class ApPersonService implements OnModuleInit {
description: person.summary ? this.apMfmService.htmlToMfm(truncate(person.summary, summaryLength), person.tag) : null, description: person.summary ? this.apMfmService.htmlToMfm(truncate(person.summary, summaryLength), person.tag) : null,
birthday: bday?.[0] ?? null, birthday: bday?.[0] ?? null,
location: person['vcard:Address'] ?? null, location: person['vcard:Address'] ?? null,
listenbrainz: person.listenbrainz ?? null,
}); });
this.globalEventService.publishInternalEvent('remoteUserUpdated', { id: exist.id }); this.globalEventService.publishInternalEvent('remoteUserUpdated', { id: exist.id });

View file

@ -183,6 +183,8 @@ export interface IActor extends IObject {
}; };
'vcard:bday'?: string; 'vcard:bday'?: string;
'vcard:Address'?: string; 'vcard:Address'?: string;
listenbrainz?: string;
backgroundUrl?: string;
} }
export const isCollection = (object: IObject): object is ICollection => export const isCollection = (object: IObject): object is ICollection =>

View file

@ -38,6 +38,7 @@ export type UserDetailed = UserLite & {
backgroundUrl: string | null; backgroundUrl: string | null;
backgroundBlurhash: string | null; backgroundBlurhash: string | null;
birthday: string | null; birthday: string | null;
listenbrainz: string | null;
createdAt: DateString; createdAt: DateString;
description: string | null; description: string | null;
ffVisibility: 'public' | 'followers' | 'private'; ffVisibility: 'public' | 'followers' | 'private';