mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-22 01:15:25 +03:00
feat: improve follows you grouping (#1408)
This commit is contained in:
parent
dc23784c00
commit
66c9212a6f
1 changed files with 27 additions and 23 deletions
|
@ -27,6 +27,10 @@ const groupId = (item: mastodon.v1.Notification): string => {
|
||||||
return JSON.stringify(id)
|
return JSON.stringify(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasHeader(account: mastodon.v1.Account) {
|
||||||
|
return !account.header.endsWith('/original/missing.png')
|
||||||
|
}
|
||||||
|
|
||||||
function groupItems(items: mastodon.v1.Notification[]): NotificationSlot[] {
|
function groupItems(items: mastodon.v1.Notification[]): NotificationSlot[] {
|
||||||
const results: 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
|
// This normally happens when you transfer an account, if not, show
|
||||||
// a big profile card for each follow
|
// a big profile card for each follow
|
||||||
if (group[0].type === '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 (processedGroup.length > 0 && hasHeader(processedGroup[0].account))
|
||||||
if (groups.length > 0) {
|
results.push(processedGroup.shift()!)
|
||||||
results.push({
|
|
||||||
id: `grouped-${id++}`,
|
if (processedGroup.length === 1 && hasHeader(processedGroup[0].account))
|
||||||
type: 'grouped-follow',
|
results.push(processedGroup.shift()!)
|
||||||
items: groups,
|
|
||||||
})
|
if (processedGroup.length > 0) {
|
||||||
groups = []
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue