Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
noridev committed Aug 31, 2023
2 parents ef1436c + fef1ad3 commit 3248529
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_CHERRYPICK.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- 타임라인 소개 추가
- 이용 약관을 서버 메뉴에서 볼 수 있도록
- 계정 초기 설정과 타임라인 튜토리얼을 다시 진행할 수 있도록
- 리모트 사용자의 노트/팔로잉/팔로워 수를 리모트 서버의 정보와 동일하게 보이도록
- 유저 메뉴에서 '리모트 유저 정보 갱신'을 진행할 수 있도록
- 설정에서 변경 가능한 옵션은 다이얼로그에서 안내하도록 주석 추가

Expand Down
140 changes: 139 additions & 1 deletion packages/backend/src/core/activitypub/models/ApPersonService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,51 @@ export class ApPersonService implements OnModuleInit {
throw new Error('unexpected schema of person url: ' + url);
}

let followersCount: number | undefined;

if (typeof person.followers === 'string') {
try {
const data = await fetch(person.followers, {
headers: { Accept: 'application/json' },
});
const jsonData = JSON.parse(await data.text());

followersCount = jsonData.totalItems;
} catch {
followersCount = undefined;
}
}

let followingCount: number | undefined;

if (typeof person.following === 'string') {
try {
const data = await fetch(person.following, {
headers: { Accept: 'application/json' },
});
const jsonData = JSON.parse(await data.text());

followingCount = jsonData.totalItems;
} catch (e) {
followingCount = undefined;
}
}

let notesCount: number | undefined;

if (typeof person.outbox === 'string') {
try {
const data = await fetch(person.outbox, {
headers: { Accept: 'application/json' },
});
const jsonData = JSON.parse(await data.text());

notesCount = jsonData.totalItems;
} catch (e) {
notesCount = undefined;
}
}

// Create user
let user: MiRemoteUser | null = null;

Expand Down Expand Up @@ -312,6 +357,30 @@ export class ApPersonService implements OnModuleInit {
inbox: person.inbox,
sharedInbox: person.sharedInbox ?? person.endpoints?.sharedInbox,
followersUri: person.followers ? getApId(person.followers) : undefined,
followersCount:
followersCount !== undefined
? followersCount
: person.followers &&
typeof person.followers !== 'string' &&
isCollectionOrOrderedCollection(person.followers)
? person.followers.totalItems
: undefined,
followingCount:
followingCount !== undefined
? followingCount
: person.following &&
typeof person.following !== 'string' &&
isCollectionOrOrderedCollection(person.following)
? person.following.totalItems
: undefined,
notesCount:
notesCount !== undefined
? notesCount
: person.outbox &&
typeof person.outbox !== 'string' &&
isCollectionOrOrderedCollection(person.outbox)
? person.outbox.totalItems
: undefined,
featured: person.featured ? getApId(person.featured) : undefined,
uri: person.id,
tags,
Expand Down Expand Up @@ -440,11 +509,80 @@ export class ApPersonService implements OnModuleInit {
throw new Error('unexpected schema of person url: ' + url);
}

let followersCount: number | undefined;

if (typeof person.followers === 'string') {
try {
const data = await fetch(person.followers, {
headers: { Accept: 'application/json' },
});
const jsonData = JSON.parse(await data.text());

followersCount = jsonData.totalItems;
} catch {
followersCount = undefined;
}
}

let followingCount: number | undefined;

if (typeof person.following === 'string') {
try {
const data = await fetch(person.following, {
headers: { Accept: 'application/json' },
});
const jsonData = JSON.parse(await data.text());

followingCount = jsonData.totalItems;
} catch {
followingCount = undefined;
}
}

let notesCount: number | undefined;

if (typeof person.outbox === 'string') {
try {
const data = await fetch(person.outbox, {
headers: { Accept: 'application/json' },
});
const jsonData = JSON.parse(await data.text());

notesCount = jsonData.totalItems;
} catch (e) {
notesCount = undefined;
}
}

const updates = {
lastFetchedAt: new Date(),
inbox: person.inbox,
sharedInbox: person.sharedInbox ?? person.endpoints?.sharedInbox,
followersUri: person.followers ? getApId(person.followers) : undefined,
followersCount:
followersCount !== undefined
? followersCount
: person.followers &&
typeof person.followers !== 'string' &&
isCollectionOrOrderedCollection(person.followers)
? person.followers.totalItems
: undefined,
followingCount:
followingCount !== undefined
? followingCount
: person.following &&
typeof person.following !== 'string' &&
isCollectionOrOrderedCollection(person.following)
? person.following.totalItems
: undefined,
notesCount:
notesCount !== undefined
? notesCount
: person.outbox &&
typeof person.outbox !== 'string' &&
isCollectionOrOrderedCollection(person.outbox)
? person.outbox.totalItems
: undefined,
featured: person.featured,
emojis: emojiNames,
name: truncate(person.name, nameLength),
Expand Down Expand Up @@ -587,7 +725,7 @@ export class ApPersonService implements OnModuleInit {

// Resolve to Object(may be Note) arrays
const unresolvedItems = isCollection(collection) ? collection.items : collection.orderedItems;
const items = await Promise.all(toArray(unresolvedItems).map(x => _resolver.resolve(x)));
const items = await Promise.all(toArray(unresolvedItems).map(x => _resolver?.resolve(x)));

// Resolve and regist Notes
const limit = promiseLimit<MiNote | null>(2);
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/core/entities/UserEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ export class UserEntityService implements OnModuleInit {
birthday: profile!.birthday,
lang: profile!.lang,
fields: profile!.fields,
followersCount: followersCount ?? 0,
followingCount: followingCount ?? 0,
followersCount: followersCount ?? '?',
followingCount: followingCount ?? '?',
notesCount: user.notesCount,
pinnedNoteIds: pins.map(pin => pin.noteId),
pinnedNotes: this.noteEntityService.packMany(pins.map(pin => pin.note!), me, {
Expand Down

0 comments on commit 3248529

Please sign in to comment.