fix(revision-service): fix count of duplicate authors

`getRevisionUserInfo` returned an incorrect list of usernames,
as users who edited a note at multiple places appeared multiple times.

 This commit fixes this behaviour by deduplicating the author
  objects using a Set.

  Closes #2180

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-05-22 21:27:48 +02:00 committed by Philip Molares
parent 52b5dc1929
commit 1ac4258d07
2 changed files with 33 additions and 6 deletions

View file

@ -109,16 +109,21 @@ export class RevisionsService {
}
async getRevisionUserInfo(revision: Revision): Promise<RevisionUserInfo> {
const users = await Promise.all(
(
await revision.edits
).map(async (edit) => await (await edit.author).user),
// get a deduplicated list of all authors
let authors = await Promise.all(
(await revision.edits).map(async (edit) => await edit.author),
);
authors = [...new Set(authors)]; // remove duplicates with Set
// retrieve user objects of the authors
const users = await Promise.all(
authors.map(async (author) => await author.user),
);
// collect usernames of the users
const usernames = users.flatMap((user) => (user ? [user.username] : []));
const anonymousUserCount = users.filter((user) => user === null).length;
return {
usernames: usernames,
anonymousUserCount: anonymousUserCount,
anonymousUserCount: users.length - usernames.length,
};
}