From 66c9212a6ff6e9afd57e8df441349b3d01a7520d Mon Sep 17 00:00:00 2001 From: patak Date: Mon, 23 Jan 2023 21:49:00 +0100 Subject: [PATCH] feat: improve follows you grouping (#1408) --- .../notification/NotificationPaginator.vue | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/components/notification/NotificationPaginator.vue b/components/notification/NotificationPaginator.vue index db5e6015..6f7a00e0 100644 --- a/components/notification/NotificationPaginator.vue +++ b/components/notification/NotificationPaginator.vue @@ -27,6 +27,10 @@ const groupId = (item: mastodon.v1.Notification): string => { return JSON.stringify(id) } +function hasHeader(account: mastodon.v1.Account) { + return !account.header.endsWith('/original/missing.png') +} + function groupItems(items: mastodon.v1.Notification[]): NotificationSlot[] { const results: NotificationSlot[] = [] @@ -44,31 +48,31 @@ function groupItems(items: mastodon.v1.Notification[]): NotificationSlot[] { // This normally happens when you transfer an account, if not, show // a big profile card for each follow if (group[0].type === 'follow') { - let groups: mastodon.v1.Notification[] = [] + // Order group by followers count + const processedGroup = [...group] + processedGroup.sort((a, b) => { + const aHasHeader = hasHeader(a.account) + const bHasHeader = hasHeader(b.account) + if (bHasHeader && !aHasHeader) + return 1 + if (aHasHeader && !bHasHeader) + return -1 + return b.account.followersCount - a.account.followersCount + }) - function newGroup() { - if (groups.length > 0) { - results.push({ - id: `grouped-${id++}`, - type: 'grouped-follow', - items: groups, - }) - groups = [] - } + if (processedGroup.length > 0 && hasHeader(processedGroup[0].account)) + results.push(processedGroup.shift()!) + + if (processedGroup.length === 1 && hasHeader(processedGroup[0].account)) + results.push(processedGroup.shift()!) + + if (processedGroup.length > 0) { + results.push({ + id: `grouped-${id++}`, + type: 'grouped-follow', + items: processedGroup, + }) } - - for (const item of group) { - const hasHeader = !item.account.header.endsWith('/original/missing.png') - if (hasHeader && (item.account.followersCount > 250 || (group.length === 1 && item.account.followersCount > 25))) { - newGroup() - results.push(item) - } - else { - groups.push(item) - } - } - - newGroup() return }