Skip to content

Commit

Permalink
fix: sortFriendRequests patches (#1848)
Browse files Browse the repository at this point in the history
  • Loading branch information
MeguminSama authored Oct 25, 2023
1 parent 68419a0 commit 8054a1e
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/plugins/sortFriendRequests/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,28 @@ export default definePlugin({
description: "Sorts friend requests by date of receipt",

patches: [{
find: ".PENDING_INCOMING||",
replacement: [{
match: /\.sortBy\(\(function\((\w)\){return \w{1,3}\.comparator}\)\)/,
// If the row type is 3 or 4 (pendinng incoming or outgoing), sort by date of receipt
// 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: "getRelationshipCounts(){",
replacement: {
match: /\.sortBy\(\i=>\i\.comparator\)/,
replace: ".sortBy((row) => $self.sortList(row))"
}
}, {
find: "RelationshipTypes.PENDING_INCOMING?",
replacement: {
predicate: () => Settings.plugins.SortFriendRequests.showDates,
match: /(user:(\w{1,3}),.{10,30}),subText:(\w{1,3}),(.{10,30}userInfo}\))/,
// Show dates in the friend request list
replace: (_, pre, user, subText, post) => `${pre},
subText: Vencord.Plugins.plugins.SortFriendRequests.makeSubtext(${subText}, ${user}),
${post}`
}]
match: /(user:(\i),.{10,50}),subText:(\i),(className:\i\.userInfo}\))/,
replace: (_, pre, user, subtext, post) => `${pre},
subText: $self.makeSubtext(${subtext}, ${user}),
${post}`
}
}],

sortList(row: any) {
return row.type === 3 || row.type === 4
? -this.getSince(row.user)
: row.comparator;
},

getSince(user: User) {
return new Date(RelationshipStore.getSince(user.id));
},
Expand Down

0 comments on commit 8054a1e

Please sign in to comment.