mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-15 07:34:42 -04:00
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:
parent
52b5dc1929
commit
1ac4258d07
2 changed files with 33 additions and 6 deletions
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue