Plugin

SortFriendRequests

Sorts friend requests by date of receipt

Friends Organisation
index.tsx
Download

Source

src/plugins/sortFriendRequests/index.tsx
1/*
2 * FiveCord — a Discord client mod
3 * Copyright (c) 2025 FiveCord
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7import "./styles.css";
8
9import { definePluginSettings } from "@api/Settings";
10import ErrorBoundary from "@components/ErrorBoundary";
11import { TooltipContainer } from "@components/TooltipContainer";
12import { Devs } from "@utils/constants";
13import { classNameFactory } from "@utils/css";
14import definePlugin, { OptionType } from "@utils/types";
15import { User } from "@vencord/discord-types";
16import { DateUtils, RelationshipStore, Text } from "@webpack/common";
17import { PropsWithChildren } from "react";
18
19const formatter = new Intl.DateTimeFormat(undefined, {
20 month: "numeric",
21 day: "numeric",
22 year: "numeric",
23});
24
25const cl = classNameFactory("vc-sortFriendRequests-");
26
27function getSince(user: User) {
28 return new Date(RelationshipStore.getSince(user.id));
29}
30
31const settings = definePluginSettings({
32 showDates: {
33 type: OptionType.BOOLEAN,
34 description: "Show dates on friend requests",
35 default: false,
36 restartNeeded: true
37 }
38});
39
40export default definePlugin({
41 name: "SortFriendRequests",
42 authors: [Devs.Megu],
43 description: "Sorts friend requests by date of receipt",
44 tags: ["Friends", "Organisation"],
45 settings,
46
47 patches: [{
48 find: "getRelationshipCounts(){",
49 replacement: {
50 match: /\}\)\.sortBy\((.+?)\)\.value\(\)/,
51 replace: "}).sortBy(row => $self.wrapSort(($1), row)).value()"
52 }
53 }, {
54 find: "#{intl::FRIEND_REQUEST_CANCEL}",
55 replacement: {
56 predicate: () => settings.store.showDates,
57 match: /(?<=children:\[)\(0,.{0,100}user:\i,hovered:\i.+?(?=,\(0)(?<=user:(\i).+?)/,
58 replace: (children, user) => `$self.WrapperDateComponent({user:${user},children:${children}})`
59 }
60 }],
61
62 wrapSort(comparator: Function, row: any) {
63 return row.type === 3 || row.type === 4
64 ? -getSince(row.user)
65 : comparator(row);
66 },
67
68 WrapperDateComponent: ErrorBoundary.wrap(({ user, children }: PropsWithChildren<{ user: User; }>) => {
69 const since = getSince(user);
70
71 return <div className={cl("wrapper")}>
72 {children}
73 {!isNaN(since.getTime()) && (
74 <TooltipContainer text={DateUtils.dateFormat(since, "LLLL")} tooltipClassName={cl("tooltip")}>
75 <Text variant="text-xs/normal" className={cl("date")}>{formatter.format(since)}</Text>
76 </TooltipContainer>
77 )}
78 </div>;
79 }, { noop: true })
80});
81