fix: sortFriendRequests patches (#1848)

This commit is contained in:
megumin 2023-10-25 16:00:39 +01:00 committed by V
parent cd06980016
commit 7de1b5dcb6

View file

@ -29,26 +29,28 @@ export default definePlugin({
description: "Sorts friend requests by date of receipt", description: "Sorts friend requests by date of receipt",
patches: [{ patches: [{
find: ".PENDING_INCOMING||", find: "getRelationshipCounts(){",
replacement: [{ replacement: {
match: /\.sortBy\(\(function\((\w)\){return \w{1,3}\.comparator}\)\)/, match: /\.sortBy\(\i=>\i\.comparator\)/,
// If the row type is 3 or 4 (pendinng incoming or outgoing), sort by date of receipt replace: ".sortBy((row) => $self.sortList(row))"
// Otherwise, use the default comparator }
replace: (_, row) => `.sortBy((function(${row}) {
return ${row}.type === 3 || ${row}.type === 4
? -Vencord.Plugins.plugins.SortFriendRequests.getSince(${row}.user)
: ${row}.comparator
}))`
}, { }, {
find: "RelationshipTypes.PENDING_INCOMING?",
replacement: {
predicate: () => Settings.plugins.SortFriendRequests.showDates, predicate: () => Settings.plugins.SortFriendRequests.showDates,
match: /(user:(\w{1,3}),.{10,30}),subText:(\w{1,3}),(.{10,30}userInfo}\))/, match: /(user:(\i),.{10,50}),subText:(\i),(className:\i\.userInfo}\))/,
// Show dates in the friend request list replace: (_, pre, user, subtext, post) => `${pre},
replace: (_, pre, user, subText, post) => `${pre}, subText: $self.makeSubtext(${subtext}, ${user}),
subText: Vencord.Plugins.plugins.SortFriendRequests.makeSubtext(${subText}, ${user}),
${post}` ${post}`
}] }
}], }],
sortList(row: any) {
return row.type === 3 || row.type === 4
? -this.getSince(row.user)
: row.comparator;
},
getSince(user: User) { getSince(user: User) {
return new Date(RelationshipStore.getSince(user.id)); return new Date(RelationshipStore.getSince(user.id));
}, },