BetterDiscordAddons/Plugins/BetterFriendList/BetterFriendList.plugin.js

784 lines
34 KiB
JavaScript
Raw Normal View History

2020-10-20 23:25:34 +02:00
/**
* @name BetterFriendList
2021-03-05 13:26:41 +01:00
* @author DevilBro
2020-10-20 23:25:34 +02:00
* @authorId 278543574059057154
2022-01-14 17:29:33 +01:00
* @version 1.4.1
2021-03-05 13:26:41 +01:00
* @description Adds extra Controls to the Friends Page, for example sort by Name/Status, Search and All/Request/Blocked Amount
2020-10-20 23:25:34 +02:00
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
* @patreon https://www.patreon.com/MircoWittrien
2021-03-09 15:10:55 +01:00
* @website https://mwittrien.github.io/
* @source https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/BetterFriendList/
2021-03-10 09:17:37 +01:00
* @updateUrl https://mwittrien.github.io/BetterDiscordAddons/Plugins/BetterFriendList/BetterFriendList.plugin.js
2020-10-20 23:25:34 +02:00
*/
2020-08-26 12:10:17 +02:00
2020-09-19 20:49:33 +02:00
module.exports = (_ => {
2020-10-09 21:09:35 +02:00
const config = {
2020-09-19 20:49:33 +02:00
"info": {
"name": "BetterFriendList",
"author": "DevilBro",
2022-01-14 17:29:33 +01:00
"version": "1.4.1",
2021-03-04 11:31:05 +01:00
"description": "Adds extra Controls to the Friends Page, for example sort by Name/Status, Search and All/Request/Blocked Amount"
2020-08-26 20:07:49 +02:00
}
2020-09-19 20:49:33 +02:00
};
2020-11-13 19:47:44 +01:00
2021-09-06 18:58:10 +02:00
return (window.Lightcord && !Node.prototype.isPrototypeOf(window.Lightcord) || window.LightCord && !Node.prototype.isPrototypeOf(window.LightCord) || window.Astra && !Node.prototype.isPrototypeOf(window.Astra)) ? class {
2021-06-15 13:42:02 +02:00
getName () {return config.info.name;}
getAuthor () {return config.info.author;}
getVersion () {return config.info.version;}
getDescription () {return "Do not use LightCord!";}
load () {BdApi.alert("Attention!", "By using LightCord you are risking your Discord Account, due to using a 3rd Party Client. Switch to an official Discord Client (https://discord.com/) with the proper BD Injection (https://betterdiscord.app/)");}
start() {}
stop() {}
} : !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class {
2021-01-06 12:38:36 +01:00
getName () {return config.info.name;}
getAuthor () {return config.info.author;}
getVersion () {return config.info.version;}
2021-02-01 17:13:13 +01:00
getDescription () {return `The Library Plugin needed for ${config.info.name} is missing. Open the Plugin Settings to download it. \n\n${config.info.description}`;}
downloadLibrary () {
require("request").get("https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js", (e, r, b) => {
2021-03-05 13:14:18 +01:00
if (!e && b && r.statusCode == 200) require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0BDFDB.plugin.js"), b, _ => BdApi.showToast("Finished downloading BDFDB Library", {type: "success"}));
2021-03-06 14:59:48 +01:00
else BdApi.alert("Error", "Could not download BDFDB Library Plugin. Try again later or download it manually from GitHub: https://mwittrien.github.io/downloader/?library");
2021-02-01 17:13:13 +01:00
});
}
2020-08-26 20:07:49 +02:00
2021-01-06 12:38:36 +01:00
load () {
2020-11-19 16:51:14 +01:00
if (!window.BDFDB_Global || !Array.isArray(window.BDFDB_Global.pluginQueue)) window.BDFDB_Global = Object.assign({}, window.BDFDB_Global, {pluginQueue: []});
2020-09-19 20:49:33 +02:00
if (!window.BDFDB_Global.downloadModal) {
window.BDFDB_Global.downloadModal = true;
2021-01-14 16:14:44 +01:00
BdApi.showConfirmationModal("Library Missing", `The Library Plugin needed for ${config.info.name} is missing. Please click "Download Now" to install it.`, {
2020-09-19 20:49:33 +02:00
confirmText: "Download Now",
cancelText: "Cancel",
onCancel: _ => {delete window.BDFDB_Global.downloadModal;},
2020-09-20 08:15:13 +02:00
onConfirm: _ => {
delete window.BDFDB_Global.downloadModal;
2021-02-01 17:13:13 +01:00
this.downloadLibrary();
2020-09-20 08:15:13 +02:00
}
2020-09-19 20:49:33 +02:00
});
2020-08-26 12:10:17 +02:00
}
2020-09-19 20:49:33 +02:00
if (!window.BDFDB_Global.pluginQueue.includes(config.info.name)) window.BDFDB_Global.pluginQueue.push(config.info.name);
2020-10-09 21:09:35 +02:00
}
2021-01-06 12:38:36 +01:00
start () {this.load();}
stop () {}
getSettingsPanel () {
2020-11-28 23:12:09 +01:00
let template = document.createElement("template");
2021-01-14 16:14:44 +01:00
template.innerHTML = `<div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${config.info.name} is missing.\nPlease click <a style="font-weight: 500;">Download Now</a> to install it.</div>`;
2021-02-01 17:13:13 +01:00
template.content.firstElementChild.querySelector("a").addEventListener("click", this.downloadLibrary);
2020-11-28 23:12:09 +01:00
return template.content.firstElementChild;
}
2020-10-09 21:09:35 +02:00
} : (([Plugin, BDFDB]) => {
2020-09-19 20:49:33 +02:00
var rerenderTimeout, sortKey, sortReversed, searchQuery, searchTimeout;
2021-08-02 21:23:52 +02:00
const favorizedFriendsSection = "FAVORIZED_FRIENDS";
2021-06-30 18:05:39 +02:00
const hiddenFriendsSection = "HIDDEN_FRIENDS";
2020-09-19 20:49:33 +02:00
const placeHolderId = "PLACEHOLDER_BETTERFRIENDLIST";
2021-08-02 21:23:52 +02:00
var favorizedFriends = [], hiddenFriends = [];
var currentSection, isFavoritesSelected = false, isHiddenSelected = false;
2021-06-30 18:05:39 +02:00
2020-09-19 20:49:33 +02:00
const statusSortOrder = {
online: 0,
streaming: 1,
idle: 2,
dnd: 3,
offline: 4,
invisible: 5,
unknown: 6
};
2020-10-09 21:09:35 +02:00
return class BetterFriendList extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad () {
2020-09-19 20:49:33 +02:00
this.defaults = {
2021-05-13 21:18:23 +02:00
general: {
2021-08-02 21:23:52 +02:00
addTotalAmount: {value: true, description: "Adds total Amount for All/Requested/Blocked"},
addFavorizedCategory: {value: true, description: "Adds Favorites Category"},
addHiddenCategory: {value: true, description: "Adds Hidden Category"},
addSortOptions: {value: true, description: "Adds Sort Options"},
addSearchbar: {value: true, description: "Adds a Searchbar"},
addMutualGuild: {value: true, description: "Adds mutual Servers in Friend List"}
2020-09-19 20:49:33 +02:00
}
};
2020-08-26 12:10:17 +02:00
2020-09-19 20:49:33 +02:00
this.patchedModules = {
before: {
2021-06-30 18:05:39 +02:00
TabBar: "render",
2020-09-19 20:49:33 +02:00
PeopleListSectionedLazy: "default",
2020-10-25 18:15:18 +01:00
PeopleListSectionedNonLazy: "default"
2020-09-19 20:49:33 +02:00
},
after: {
TabBar: "render",
PeopleListSectionedLazy: "default",
2020-10-25 18:15:18 +01:00
PeopleListSectionedNonLazy: "default",
2020-09-19 20:49:33 +02:00
FriendRow: "render",
PendingRow: "default",
BlockedRow: "render",
PeopleListItem: ["render", "componentDidMount","componentWillUnmount"]
}
};
this.css = `
2021-05-14 09:22:15 +02:00
${BDFDB.dotCNS.peoplestabbar + BDFDB.dotCN.peoplesbadge} {
background-color: var(--background-accent);
margin-left: 6px;
}
2020-09-19 20:49:33 +02:00
${BDFDB.dotCN._betterfriendlisttitle} {
width: 200px;
}
${BDFDB.dotCN._betterfriendlistnamecell} {
width: 150px;
}
2021-07-02 21:24:10 +02:00
${BDFDB.dotCN.peoplesuser} {
flex: 1 1 auto;
}
${BDFDB.dotCN.peoplesactions} {
flex: 0 0 auto;
}
${BDFDB.dotCN._betterfriendlistmutualguilds} {
flex: 0 0 200px;
margin-left: 13px;
}
2020-09-19 20:49:33 +02:00
`;
}
2021-01-06 12:38:36 +01:00
onStart () {
2020-09-19 20:49:33 +02:00
sortKey = null;
sortReversed = false;
searchQuery = "";
2021-08-02 21:23:52 +02:00
isFavoritesSelected = false;
2021-06-30 18:05:39 +02:00
isHiddenSelected = false;
2020-08-26 12:10:17 +02:00
2020-08-26 15:21:49 +02:00
this.forceUpdateAll();
2020-08-26 12:10:17 +02:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStop () {
2020-08-26 15:21:49 +02:00
this.forceUpdateAll();
2020-08-26 12:10:17 +02:00
}
2020-09-19 20:49:33 +02:00
getSettingsPanel (collapseStates = {}) {
2021-05-13 21:18:23 +02:00
let settingsPanel;
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, {
collapseStates: collapseStates,
children: _ => {
let settingsItems = [];
2020-09-19 20:49:33 +02:00
2021-05-13 21:18:23 +02:00
for (let key in this.defaults.general) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch",
plugin: this,
keys: ["general", key],
label: this.defaults.general[key].description,
value: this.settings.general[key]
}));
return settingsItems;
}
});
2020-09-19 20:49:33 +02:00
}
2020-08-26 12:10:17 +02:00
2021-01-06 12:38:36 +01:00
onSettingsClosed () {
2020-09-19 20:49:33 +02:00
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
this.forceUpdateAll();
}
}
2021-01-06 12:38:36 +01:00
forceUpdateAll () {
2021-08-02 21:23:52 +02:00
favorizedFriends = BDFDB.DataUtils.load(this, "favorizedFriends");
favorizedFriends = !BDFDB.ArrayUtils.is(favorizedFriends) ? [] : favorizedFriends;
2021-06-30 18:05:39 +02:00
hiddenFriends = BDFDB.DataUtils.load(this, "hiddenFriends");
hiddenFriends = !BDFDB.ArrayUtils.is(hiddenFriends) ? [] : hiddenFriends;
2020-09-19 20:49:33 +02:00
BDFDB.PatchUtils.forceAllUpdates(this);
this.rerenderList();
2020-08-26 15:21:49 +02:00
}
2021-06-30 18:05:39 +02:00
onUserContextMenu (e) {
2021-08-02 21:23:52 +02:00
if (e.instance.props.user) {
2021-06-30 18:05:39 +02:00
let [children, index] = BDFDB.ContextMenuUtils.findItem(e.returnvalue, {id: "remove-friend"});
2021-08-02 21:23:52 +02:00
let favorized = favorizedFriends.indexOf(e.instance.props.user.id) > -1;
2021-06-30 18:05:39 +02:00
let hidden = hiddenFriends.indexOf(e.instance.props.user.id) > -1;
2021-08-02 21:23:52 +02:00
if (index > -1) children.splice(index + 1, 0, this.settings.general.addFavorizedCategory && BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: favorized ? this.labels.context_unfavorizefriend : this.labels.context_favorizefriend,
id: BDFDB.ContextMenuUtils.createItemId(this.name, favorized ? "unfavorize-friend" : "favorize-friend"),
action: _ => {
if (favorized) BDFDB.ArrayUtils.remove(favorizedFriends, e.instance.props.user.id, true);
else {
favorizedFriends.push(e.instance.props.user.id);
BDFDB.ArrayUtils.remove(hiddenFriends, e.instance.props.user.id, true);
}
BDFDB.DataUtils.save(favorizedFriends, this, "favorizedFriends");
BDFDB.DataUtils.save(hiddenFriends, this, "hiddenFriends");
this.rerenderList();
}
}), this.settings.general.addHiddenCategory && BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
2021-06-30 18:05:39 +02:00
label: hidden ? this.labels.context_unhidefriend : this.labels.context_hidefriend,
id: BDFDB.ContextMenuUtils.createItemId(this.name, hidden ? "unhide-friend" : "hide-friend"),
action: _ => {
if (hidden) BDFDB.ArrayUtils.remove(hiddenFriends, e.instance.props.user.id, true);
2021-08-02 21:23:52 +02:00
else {
BDFDB.ArrayUtils.remove(favorizedFriends, e.instance.props.user.id, true);
hiddenFriends.push(e.instance.props.user.id);
}
BDFDB.DataUtils.save(favorizedFriends, this, "favorizedFriends");
2021-06-30 18:05:39 +02:00
BDFDB.DataUtils.save(hiddenFriends, this, "hiddenFriends");
this.rerenderList();
}
}));
}
}
2020-09-19 20:49:33 +02:00
processTabBar (e) {
2021-06-30 18:05:39 +02:00
if (e.instance.props.children && e.instance.props.children.some(c => c && c.props.id == BDFDB.DiscordConstants.FriendsSections.ADD_FRIEND)) {
currentSection = e.instance.props.selectedItem;
2021-08-02 21:23:52 +02:00
isFavoritesSelected = currentSection == favorizedFriendsSection;
isHiddenSelected = currentSection == hiddenFriendsSection;
2021-06-30 18:05:39 +02:00
if (!e.returnvalue) {
2021-08-02 21:23:52 +02:00
e.instance.props.children = e.instance.props.children.filter(c => c && c.props.id != favorizedFriendsSection && c.props.id != hiddenFriendsSection);
if (this.settings.general.addFavorizedCategory) e.instance.props.children.splice(e.instance.props.children.findIndex(c => c && c.props.id == BDFDB.DiscordConstants.FriendsSections.ONLINE) + 1, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TabBar.Item, {
id: favorizedFriendsSection,
className: BDFDB.disCN.peoplestabbaritem,
children: this.labels.favorites
}));
2021-06-30 18:05:39 +02:00
if (this.settings.general.addHiddenCategory) e.instance.props.children.splice(e.instance.props.children.findIndex(c => c && c.props.id == BDFDB.DiscordConstants.FriendsSections.BLOCKED) + 1, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TabBar.Item, {
id: hiddenFriendsSection,
className: BDFDB.disCN.peoplestabbaritem,
children: this.labels.hidden
}));
}
else {
if (this.settings.general.addTotalAmount) {
let relationships = BDFDB.LibraryModules.RelationshipStore.getRelationships(), relationshipCount = {};
for (let type in BDFDB.DiscordConstants.RelationshipTypes) relationshipCount[type] = 0;
2021-08-21 20:47:24 +02:00
for (let id in relationships) if (!this.settings.general.addHiddenCategory || (hiddenFriends.indexOf(id) == -1 || relationships[id] != BDFDB.DiscordConstants.RelationshipTypes.FRIEND)) relationshipCount[relationships[id]]++;
2021-06-30 18:05:39 +02:00
for (let child of e.returnvalue.props.children) if (child && child.props.id != BDFDB.DiscordConstants.FriendsSections.ADD_FRIEND) {
let newChildren = [child.props.children].flat().filter(child => BDFDB.ObjectUtils.get(child, "type.displayName") != "NumberBadge");
switch (child.props.id) {
case BDFDB.DiscordConstants.FriendsSections.ALL:
newChildren.push(this.createBadge(relationshipCount[BDFDB.DiscordConstants.RelationshipTypes.FRIEND]));
break;
2021-08-02 21:23:52 +02:00
case favorizedFriendsSection:
newChildren.push(this.createBadge(favorizedFriends.filter(id => relationships[id] == BDFDB.DiscordConstants.RelationshipTypes.FRIEND).length));
break;
2021-06-30 18:05:39 +02:00
case BDFDB.DiscordConstants.FriendsSections.ONLINE:
2021-08-02 21:23:52 +02:00
newChildren.push(this.createBadge(Object.entries(relationships).filter(n => n[1] == BDFDB.DiscordConstants.RelationshipTypes.FRIEND && !(this.settings.general.addHiddenCategory && hiddenFriends.indexOf(n[0]) > -1) && BDFDB.LibraryModules.StatusMetaUtils.getStatus(n[0]) != BDFDB.DiscordConstants.StatusTypes.OFFLINE).length));
2021-06-30 18:05:39 +02:00
break;
case BDFDB.DiscordConstants.FriendsSections.PENDING:
newChildren.push(this.createBadge(relationshipCount[BDFDB.DiscordConstants.RelationshipTypes.PENDING_INCOMING], this.labels.incoming, relationshipCount[BDFDB.DiscordConstants.RelationshipTypes.PENDING_INCOMING] > 0));
newChildren.push(this.createBadge(relationshipCount[BDFDB.DiscordConstants.RelationshipTypes.PENDING_OUTGOING], this.labels.outgoing));
break;
2022-01-14 17:29:33 +01:00
case BDFDB.DiscordConstants.FriendsSections.SUGGESTIONS:
newChildren.push(this.createBadge(BDFDB.LibraryModules.RelationshipSuggestionUtils.getSuggestionCount()));
break;
2021-06-30 18:05:39 +02:00
case BDFDB.DiscordConstants.FriendsSections.BLOCKED:
newChildren.push(this.createBadge(relationshipCount[BDFDB.DiscordConstants.RelationshipTypes.BLOCKED]));
break;
case hiddenFriendsSection:
newChildren.push(this.createBadge(hiddenFriends.filter(id => relationships[id] == BDFDB.DiscordConstants.RelationshipTypes.FRIEND).length));
break;
}
child.props.children = newChildren;
}
2020-09-19 20:49:33 +02:00
}
2020-08-26 12:10:17 +02:00
}
}
}
2020-09-19 20:49:33 +02:00
processPeopleListSectionedLazy (e) {
2022-01-11 22:56:04 +01:00
this.processPeopleListSectionedNonLazy(e);
}
processPeopleListSectionedNonLazy (e) {
2021-08-02 21:23:52 +02:00
if (this.settings.general.addFavorizedCategory) {
if (isFavoritesSelected) e.instance.props.statusSections = [].concat(e.instance.props.statusSections).map(section => [].concat(section).filter(entry => entry && entry.user && favorizedFriends.indexOf(entry.user.id) > -1));
}
2021-06-30 18:05:39 +02:00
if (this.settings.general.addHiddenCategory) {
if (isHiddenSelected) e.instance.props.statusSections = [].concat(e.instance.props.statusSections).map(section => [].concat(section).filter(entry => entry && entry.user && hiddenFriends.indexOf(entry.user.id) > -1));
else if (([].concat(e.instance.props.statusSections).flat(10)[0] || {}).type == BDFDB.DiscordConstants.RelationshipTypes.FRIEND) e.instance.props.statusSections = [].concat(e.instance.props.statusSections).map(section => [].concat(section).filter(entry => entry && entry.user && hiddenFriends.indexOf(entry.user.id) == -1));
2020-09-19 20:49:33 +02:00
}
2021-06-30 18:05:39 +02:00
if (sortKey || searchQuery) e.instance.props.statusSections = [].concat(e.instance.props.statusSections).map(section => {
let newSection = [].concat(section);
if (searchQuery) {
let usedSearchQuery = searchQuery.toLowerCase();
newSection = newSection.filter(entry => entry && typeof entry.usernameLower == "string" && entry.usernameLower.indexOf(usedSearchQuery) > -1);
}
if (sortKey) {
newSection = BDFDB.ArrayUtils.keySort(newSection.map(entry => Object.assign({}, entry, {statusIndex: statusSortOrder[entry.status]})), sortKey);
if (sortReversed) newSection.reverse();
}
if (!newSection.length) {
let placeholder = new BDFDB.DiscordObjects.User({
id: placeHolderId,
username: placeHolderId
});
if (placeholder) newSection.push(new BDFDB.DiscordObjects.Relationship({
activities: [],
applicationStream: null,
isMobile: false,
key: placeHolderId,
mutualGuilds: [],
mutualGuildsLength: 0,
status: "offline",
type: BDFDB.DiscordConstants.RelationshipTypes.NONE,
user: placeholder,
usernameLower: placeholder.usernameNormalized
}));
}
return newSection;
});
2021-07-28 20:08:45 +02:00
BDFDB.PatchUtils.patch(this, e.instance.props, "getSectionTitle", {after: e2 => {
2020-11-16 09:51:45 +01:00
if (typeof e2.returnValue == "string") {
let users = e.instance.props.statusSections.flat(10);
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
children: [
BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN._betterfriendlisttitle,
2021-08-02 21:23:52 +02:00
children: this.settings.general.addFavorizedCategory && isFavoritesSelected ? `${this.labels.favorites} - ${users.filter(u => u && u.key != placeHolderId).length}` : this.settings.general.addHiddenCategory && isHiddenSelected ? `${this.labels.hidden} - ${users.filter(u => u && u.key != placeHolderId).length}` : e2.returnValue.replace(users.length, users.filter(u => u && u.key != placeHolderId).length)
2020-09-19 20:49:33 +02:00
}),
2021-05-13 21:18:23 +02:00
this.settings.general.addSortOptions && [
2022-01-11 22:56:04 +01:00
{key: "usernameLower", label: BDFDB.LanguageUtils.LanguageStrings.USER_SETTINGS_LABEL_USERNAME},
{key: "statusIndex", label: BDFDB.LanguageUtils.LibraryStrings.status}
2020-11-16 09:51:45 +01:00
].filter(n => n).map(data => BDFDB.ReactUtils.createElement("div", {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.tableheadercellwrapper, BDFDB.disCN.tableheadercell, BDFDB.disCN._betterfriendlistnamecell, sortKey == data.key && BDFDB.disCN.tableheadercellsorted, BDFDB.disCN.tableheadercellclickable),
children: BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN.tableheadercellcontent,
children: [
data.label,
sortKey == data.key && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
className: BDFDB.disCN.tableheadersorticon,
name: BDFDB.LibraryComponents.SvgIcon.Names[sortReversed ? "ARROW_UP" : "ARROW_DOWN"]
})
].filter(n => n)
}),
onClick: event => {
if (sortKey == data.key) {
if (!sortReversed) sortReversed = true;
else {
sortKey = null;
sortReversed = false;
}
}
2020-09-19 20:49:33 +02:00
else {
2020-11-16 09:51:45 +01:00
sortKey = data.key;
2020-09-19 20:49:33 +02:00
sortReversed = false;
}
this.rerenderList();
}
2020-11-16 09:51:45 +01:00
})),
2021-05-13 21:18:23 +02:00
this.settings.general.addSearchbar && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
2020-11-16 09:51:45 +01:00
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SearchBar, {
query: searchQuery,
onChange: value => {
BDFDB.TimeUtils.clear(searchTimeout);
searchTimeout = BDFDB.TimeUtils.timeout(_ => {
searchQuery = value;
this.rerenderList();
}, 1000);
},
onClear: _ => {
searchQuery = "";
this.rerenderList();
}
})
2020-09-19 20:49:33 +02:00
})
2020-11-16 09:51:45 +01:00
].flat(10).filter(n => n)
});
}
}}, {force: true, noCache: true});
2021-06-30 18:05:39 +02:00
if (e.returnvalue && !e.instance.props.statusSections.flat(10).length) e.returnvalue.props.children = BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN.peopleslistempty,
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FriendsEmptyState, {
2021-08-02 21:23:52 +02:00
type: !currentSection || !Object.entries(BDFDB.DiscordConstants.FriendsSections).find(n => n[1] == currentSection) ? BDFDB.DiscordConstants.FriendsSections.ALL : currentSection
2021-06-30 18:05:39 +02:00
})
});
2020-09-19 20:49:33 +02:00
}
processFriendRow (e) {
e.returnvalue.props.mutualGuilds = e.instance.props.mutualGuilds;
}
processPendingRow (e) {
this.processFriendRow(e);
}
processBlockedRow (e) {
this.processFriendRow(e);
2020-08-29 00:48:29 +02:00
}
2020-09-19 20:49:33 +02:00
processPeopleListItem (e) {
if (e.node) {
BDFDB.TimeUtils.clear(rerenderTimeout);
2021-07-28 20:08:45 +02:00
rerenderTimeout = BDFDB.TimeUtils.timeout(_ => BDFDB.PatchUtils.forceAllUpdates(this, "TabBar"), 1000);
2020-09-19 20:49:33 +02:00
}
else {
if (e.instance.props.user.id == placeHolderId) return null;
2021-05-13 21:18:23 +02:00
else if (this.settings.general.addMutualGuild && e.instance.props.mutualGuilds && e.instance.props.mutualGuilds.length) {
2020-11-27 17:53:50 +01:00
if (typeof e.returnvalue.props.children == "function") {
let childrenRender = e.returnvalue.props.children;
2021-07-05 16:33:10 +02:00
e.returnvalue.props.children = BDFDB.TimeUtils.suppress((...args) => {
2020-11-27 17:53:50 +01:00
let children = childrenRender(...args);
this.injectMutualGuilds(children, e.instance.props.mutualGuilds);
return children;
2021-07-05 16:33:10 +02:00
}, "", this);
2020-11-27 17:53:50 +01:00
}
else this.injectMutualGuilds(e.returnvalue, e.instance.props.mutualGuilds);
2020-09-19 20:49:33 +02:00
}
2020-08-29 08:55:29 +02:00
}
2020-08-29 00:48:29 +02:00
}
2020-09-19 20:49:33 +02:00
2020-11-27 17:53:50 +01:00
injectMutualGuilds (returnvalue, mutualGuilds) {
let [children, index] = BDFDB.ReactUtils.findParent(returnvalue, {name: "UserInfo"});
if (index > -1) children.splice(index + 1, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.GuildSummaryItem, {
className: BDFDB.disCN._betterfriendlistmutualguilds,
guilds: mutualGuilds,
showTooltip: true,
max: 10
}, true));
}
2021-05-14 09:22:15 +02:00
createBadge (amount, text, red) {
2021-03-01 10:37:57 +01:00
let badge = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Badges.NumberBadge, {
2021-05-14 09:22:15 +02:00
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.peoplesbadge),
2020-09-19 20:49:33 +02:00
count: amount,
2021-05-14 09:22:15 +02:00
disableColor: !red
2020-09-19 20:49:33 +02:00
});
2021-03-01 10:37:57 +01:00
return text ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
text: text,
tooltipConfig: {
type: "bottom"
},
children: badge
}) : badge;
2020-09-19 20:49:33 +02:00
}
2021-01-06 12:38:36 +01:00
rerenderList () {
2021-07-28 20:08:45 +02:00
let selectedButton = document.querySelector(BDFDB.dotCN.dmchannel + BDFDB.dotCN.namecontainerselected);
2020-09-19 20:49:33 +02:00
if (selectedButton) selectedButton.click();
}
2021-03-01 10:37:57 +01:00
setLabelsByLanguage () {
switch (BDFDB.LanguageUtils.getLanguage().id) {
case "bg": // Bulgarian
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Добавете приятел към любими",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Скрий приятел",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Премахване на приятел от любимите",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Разкрий приятел",
2021-08-02 21:23:52 +02:00
favorites: "Любими",
2021-06-30 18:05:39 +02:00
hidden: "Скрити",
2021-03-01 10:37:57 +01:00
incoming: "Входящи",
outgoing: "Изходящи"
};
2021-06-30 18:05:39 +02:00
case "cs": // Czech
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Přidat přítele do oblíbených",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Skrýt přítele",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Odebrat přítele z oblíbených",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Odkrýt přítele",
2021-08-02 21:23:52 +02:00
favorites: "Oblíbené",
2021-06-30 18:05:39 +02:00
hidden: "Skrytý",
incoming: "Přicházející",
outgoing: "Odchozí"
};
2021-03-01 10:37:57 +01:00
case "da": // Danish
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Føj ven til favoritter",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Skjul ven",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Fjern ven fra favoritter",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Skjul ven",
2021-08-02 21:23:52 +02:00
favorites: "Favoritter",
2021-06-30 18:05:39 +02:00
hidden: "Skjult",
2021-03-01 10:37:57 +01:00
incoming: "Indgående",
outgoing: "Udgående"
};
case "de": // German
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Freund zu Favoriten hinzufügen",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Freund ausblenden",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Freund aus Favoriten entfernen",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Freund einblenden",
2021-08-02 21:23:52 +02:00
favorites: "Favoriten",
2021-06-30 18:05:39 +02:00
hidden: "Versteckt",
2021-03-01 10:37:57 +01:00
incoming: "Eingehend",
outgoing: "Ausgehend"
};
case "el": // Greek
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Προσθήκη φίλου στα αγαπημένα",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Απόκρυψη φίλου",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Κατάργηση φίλου από τα αγαπημένα",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Απόκρυψη φίλου",
2021-08-02 21:23:52 +02:00
favorites: "Αγαπημένα",
2021-06-30 18:05:39 +02:00
hidden: "Κρυμμένος",
2021-03-01 10:37:57 +01:00
incoming: "Εισερχόμενος",
outgoing: "Εξερχόμενος"
};
case "es": // Spanish
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Agregar amigo a favoritos",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Ocultar amigo",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Quitar amigo de favoritos",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Mostrar amigo",
2021-08-02 21:23:52 +02:00
favorites: "Favoritos",
2021-06-30 18:05:39 +02:00
hidden: "Oculto",
2021-03-01 10:37:57 +01:00
incoming: "Entrante",
outgoing: "Saliente"
};
case "fi": // Finnish
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Lisää ystävä suosikkeihin",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Piilota ystävä",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Poista ystävä suosikeista",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Näytä ystävä",
2021-08-02 21:23:52 +02:00
favorites: "Suosikit",
2021-06-30 18:05:39 +02:00
hidden: "Piilotettu",
2021-03-01 10:37:57 +01:00
incoming: "Saapuva",
outgoing: "Lähtevä"
};
case "fr": // French
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Ajouter un ami aux favoris",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Masquer l'ami",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Supprimer un ami des favoris",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Afficher l'ami",
2021-08-02 21:23:52 +02:00
favorites: "Favoris",
2021-06-30 18:05:39 +02:00
hidden: "Caché",
2021-03-01 10:37:57 +01:00
incoming: "Entrant",
outgoing: "Sortant"
};
2021-06-30 18:05:39 +02:00
case "hi": // Hindi
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "मित्र को पसंदीदा में जोड़ें",
2021-06-30 18:05:39 +02:00
context_hidefriend: "दोस्त छुपाएं",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "मित्र को पसंदीदा से हटाएं",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "मित्र दिखाएँ",
2021-08-02 21:23:52 +02:00
favorites: "पसंदीदा",
2021-06-30 18:05:39 +02:00
hidden: "छिपा हुआ",
incoming: "आने वाली",
outgoing: "निवर्तमान"
};
2021-03-01 10:37:57 +01:00
case "hr": // Croatian
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Dodaj prijatelja u favorite",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Sakrij prijatelja",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Ukloni prijatelja iz omiljenih",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Otkrij prijatelja",
2021-08-02 21:23:52 +02:00
favorites: "Favoriti",
2021-06-30 18:05:39 +02:00
hidden: "Skriven",
2021-03-01 10:37:57 +01:00
incoming: "Dolazni",
outgoing: "Odlazni"
};
case "hu": // Hungarian
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Ismerős hozzáadása a kedvencekhez",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Barát elrejtése",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Ismerős eltávolítása a kedvencekből",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Barát megjelenítése",
2021-08-02 21:23:52 +02:00
favorites: "Kedvencek",
2021-06-30 18:05:39 +02:00
hidden: "Rejtett",
2021-03-01 10:37:57 +01:00
incoming: "Beérkező",
outgoing: "Kimenő"
};
case "it": // Italian
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Aggiungi amico ai preferiti",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Nascondi amico",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Rimuovi amico dai preferiti",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Scopri amico",
2021-08-02 21:23:52 +02:00
favorites: "Preferiti",
2021-06-30 18:05:39 +02:00
hidden: "Nascosto",
2021-03-01 10:37:57 +01:00
incoming: "In arrivo",
outgoing: "Estroverso"
};
case "ja": // Japanese
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "お気に入りに友達を追加する",
2021-06-30 18:05:39 +02:00
context_hidefriend: "友達を隠す",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "お気に入りから友達を削除する",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "友達を再表示",
2021-08-02 21:23:52 +02:00
favorites: "お気に入り",
2021-06-30 18:05:39 +02:00
hidden: "隠し",
2021-03-01 10:37:57 +01:00
incoming: "着信",
outgoing: "発信"
};
case "ko": // Korean
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "즐겨찾기에 친구 추가",
2021-06-30 18:05:39 +02:00
context_hidefriend: "친구 숨기기",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "즐겨찾기에서 친구 제거",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "친구 숨기기 해제",
2021-08-02 21:23:52 +02:00
favorites: "즐겨찾기",
2021-06-30 18:05:39 +02:00
hidden: "숨겨진",
2021-03-01 10:37:57 +01:00
incoming: "들어오는",
outgoing: "나가는"
};
case "lt": // Lithuanian
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Pridėti draugą prie mėgstamiausių",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Slėpti draugą",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Pašalinti draugą iš mėgstamiausių",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Nerodyti draugo",
2021-08-02 21:23:52 +02:00
favorites: "Mėgstamiausi",
2021-06-30 18:05:39 +02:00
hidden: "Paslėpta",
2021-03-01 10:37:57 +01:00
incoming: "Gaunamasis",
outgoing: "Išeinantis"
};
case "nl": // Dutch
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Vriend toevoegen aan favorieten",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Vriend verbergen",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Vriend uit favorieten verwijderen",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Vriend zichtbaar maken",
2021-08-02 21:23:52 +02:00
favorites: "Favorieten",
2021-06-30 18:05:39 +02:00
hidden: "Verborgen",
2021-03-01 10:37:57 +01:00
incoming: "Inkomend",
outgoing: "Uitgaand"
};
case "no": // Norwegian
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Legg til en venn i favoritter",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Skjul venn",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Fjern venn fra favoritter",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Skjul venn",
2021-08-02 21:23:52 +02:00
favorites: "Favoritter",
2021-06-30 18:05:39 +02:00
hidden: "Skjult",
2021-03-01 10:37:57 +01:00
incoming: "Innkommende",
outgoing: "Utgående"
};
case "pl": // Polish
return {
2021-09-20 18:46:32 +02:00
context_favorizefriend: "Dodaj znajomego do ulubionych",
context_hidefriend: "Ukryj znajomego",
context_unfavorizefriend: "Usuń znajomego z ulubionych",
context_unhidefriend: "Pokaż znajomego",
2021-08-02 21:23:52 +02:00
favorites: "Ulubione",
2021-09-20 18:46:32 +02:00
hidden: "Ukryci",
incoming: "Przychodzące",
outgoing: "Wychodzące"
2021-03-01 10:37:57 +01:00
};
case "pt-BR": // Portuguese (Brazil)
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Adicionar amigo aos favoritos",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Esconder Amigo",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Remover amigo dos favoritos",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Reexibir amigo",
2021-08-02 21:23:52 +02:00
favorites: "Favoritos",
2021-06-30 18:05:39 +02:00
hidden: "Escondido",
2021-03-01 10:37:57 +01:00
incoming: "Entrada",
outgoing: "Extrovertido"
};
case "ro": // Romanian
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Adaugă prieten la favorite",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Ascunde prietenul",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Scoateți prietenul din favorite",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Afișează prietenul",
2021-08-02 21:23:52 +02:00
favorites: "Favorite",
2021-06-30 18:05:39 +02:00
hidden: "Ascuns",
2021-03-01 10:37:57 +01:00
incoming: "Primite",
outgoing: "De ieșire"
};
case "ru": // Russian
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Добавить друга в избранное",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Скрыть друга",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Удалить друга из избранного",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Показать друга",
2021-08-02 21:23:52 +02:00
favorites: "Избранное",
2021-06-30 18:05:39 +02:00
hidden: "Скрытый",
2021-03-01 10:37:57 +01:00
incoming: "Входящий",
outgoing: "Исходящий"
};
case "sv": // Swedish
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Lägg till vän till favoriter",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Dölj vän",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Ta bort vän från favoriter",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Göm din vän",
2021-08-02 21:23:52 +02:00
favorites: "Favoriter",
2021-06-30 18:05:39 +02:00
hidden: "Dold",
2021-03-01 10:37:57 +01:00
incoming: "Inkommande",
outgoing: "Utgående"
};
case "th": // Thai
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "เพิ่มเพื่อนในรายการโปรด",
2021-06-30 18:05:39 +02:00
context_hidefriend: "ซ่อนเพื่อน",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "ลบเพื่อนออกจากรายการโปรด",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "เลิกซ่อนเพื่อน",
2021-08-02 21:23:52 +02:00
favorites: "รายการโปรด",
2021-06-30 18:05:39 +02:00
hidden: "ซ่อนเร้น",
2021-03-01 10:37:57 +01:00
incoming: "ขาเข้า",
outgoing: "ขาออก"
};
case "tr": // Turkish
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Favorilere arkadaş ekle",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Arkadaşı Gizle",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Arkadaşını favorilerden kaldır",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Arkadaşı Göster",
2021-08-02 21:23:52 +02:00
favorites: "Favoriler",
2021-06-30 18:05:39 +02:00
hidden: "Gizli",
2021-03-01 10:37:57 +01:00
incoming: "Gelen",
outgoing: "Dışa dönük"
};
case "uk": // Ukrainian
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Додати друга у вибране",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Сховати друга",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Видалити друга з вибраного",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Показати друга",
2021-08-02 21:23:52 +02:00
favorites: "Вибране",
2021-06-30 18:05:39 +02:00
hidden: "Прихований",
2021-03-01 10:37:57 +01:00
incoming: "Вхідні",
outgoing: "Вихідний"
};
case "vi": // Vietnamese
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Thêm bạn bè vào danh sách yêu thích",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Ẩn bạn bè",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Xóa bạn bè khỏi danh sách yêu thích",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Bỏ ẩn bạn bè",
2021-08-02 21:23:52 +02:00
favorites: "Yêu thích",
2021-06-30 18:05:39 +02:00
hidden: "Ẩn",
2021-03-01 10:37:57 +01:00
incoming: "Mới đến",
outgoing: "Hướng ngoaị"
};
case "zh-CN": // Chinese (China)
return {
2021-12-15 21:44:54 +01:00
context_favorizefriend: "添加好友到收藏夹",
context_hidefriend: "隐藏好友",
context_unfavorizefriend: "从收藏夹中移除好友",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "取消隐藏好友",
2021-08-02 21:23:52 +02:00
favorites: "收藏夹",
2021-12-15 21:44:54 +01:00
hidden: "隐藏",
incoming: "导入",
outgoing: "导出"
2021-03-01 10:37:57 +01:00
};
case "zh-TW": // Chinese (Taiwan)
return {
2021-12-15 21:44:54 +01:00
context_favorizefriend: "新增好友到我的最愛",
context_hidefriend: "隱藏好友",
context_unfavorizefriend: "從我的最愛中移除好友",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "取消隱藏好友",
2021-12-15 21:44:54 +01:00
favorites: "我的最愛",
hidden: "隱藏",
incoming: "匯入",
outgoing: "匯出"
2021-03-01 10:37:57 +01:00
};
default: // English
return {
2021-08-02 21:23:52 +02:00
context_favorizefriend: "Add Friend to Favorites",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Hide Friend",
2021-08-02 21:23:52 +02:00
context_unfavorizefriend: "Remove Friend from Favorites",
2021-06-30 18:05:39 +02:00
context_unhidefriend: "Unhide Friend",
2021-08-02 21:23:52 +02:00
favorites: "Favorites",
2021-06-30 18:05:39 +02:00
hidden: "Hidden",
2021-03-01 10:37:57 +01:00
incoming: "Incoming",
outgoing: "Outgoing"
};
}
}
2020-09-19 20:49:33 +02:00
};
2020-10-09 21:09:35 +02:00
})(window.BDFDB_Global.PluginUtils.buildPlugin(config));
2020-09-19 20:49:33 +02:00
})();