BetterDiscordAddons/Plugins/BetterFriendList/BetterFriendList.plugin.js

747 lines
33 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
2023-10-19 12:27:07 +02:00
* @version 1.5.5
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 = (_ => {
2022-09-01 14:40:11 +02:00
const changeLog = {
2022-09-02 12:37:10 +02:00
2020-09-19 20:49:33 +02:00
};
2020-11-13 19:47:44 +01:00
2022-02-05 21:14:17 +01:00
return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class {
2022-09-01 14:55:22 +02:00
constructor (meta) {for (let key in meta) this[key] = meta[key];}
getName () {return this.name;}
getAuthor () {return this.author;}
getVersion () {return this.version;}
getDescription () {return `The Library Plugin needed for ${this.name} is missing. Open the Plugin Settings to download it. \n\n${this.description}`;}
2021-02-01 17:13:13 +01:00
downloadLibrary () {
2023-11-18 18:31:34 +01:00
BdApi.Net.fetch("https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js").then(r => {
if (!r || r.status != 200) throw new Error();
else return r.text();
}).then(b => {
if (!b) throw new Error();
else return require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0BDFDB.plugin.js"), b, _ => BdApi.showToast("Finished downloading BDFDB Library", {type: "success"}));
}).catch(error => {
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;
2022-09-01 14:55:22 +02:00
BdApi.showConfirmationModal("Library Missing", `The Library Plugin needed for ${this.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
}
2022-09-01 14:55:22 +02:00
if (!window.BDFDB_Global.pluginQueue.includes(this.name)) window.BDFDB_Global.pluginQueue.push(this.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");
2022-09-01 14:55:22 +02: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 ${this.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]) => {
2022-02-09 21:15:49 +01:00
var rerenderTimeout, sortKey, sortReversed;
2020-09-19 20:49:33 +02:00
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"},
2023-11-18 18:31:04 +01:00
addFavorizedCategory: {value: true, description: "Adds Favorites Category"},
2021-08-02 21:23:52 +02:00
addHiddenCategory: {value: true, description: "Adds Hidden Category"},
addSortOptions: {value: true, description: "Adds Sort Options"},
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
2022-10-28 13:04:56 +02:00
this.modulePatches = {
before: [
2022-12-14 10:40:37 +01:00
"AnalyticsContext",
2022-10-28 13:04:56 +02:00
"PeopleListSectionedLazy",
"PeopleListSectionedNonLazy",
"TabBar"
],
after: [
"PeopleListItem",
"TabBar"
],
componentDidMount: [
"PeopleListItem"
],
componentWillUnmount: [
"PeopleListItem"
]
2020-09-19 20:49:33 +02:00
};
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} {
2022-02-09 21:15:49 +01:00
width: 200px;
2020-09-19 20:49:33 +02:00
}
2023-04-16 11:51:49 +02:00
${BDFDB.dotCNS.peoplespeoplecolumn + BDFDB.dotCN.searchbar} {
padding-bottom: 0;
margin-bottom: 0;
}
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;
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
2022-02-24 22:41:47 +01:00
onUserContextMenu (e) {
2022-10-28 13:04:56 +02:00
if (!e.instance.props.user || !BDFDB.LibraryStores.RelationshipStore.isFriend(e.instance.props.user.id)) return;
let favorized = favorizedFriends.indexOf(e.instance.props.user.id) > -1;
let hidden = hiddenFriends.indexOf(e.instance.props.user.id) > -1;
let [children, index] = BDFDB.ContextMenuUtils.findItem(e.returnvalue, {id: "remove-friend"});
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);
2021-08-02 21:23:52 +02:00
}
2022-10-28 13:04:56 +02:00
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, {
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);
else {
BDFDB.ArrayUtils.remove(favorizedFriends, e.instance.props.user.id, true);
hiddenFriends.push(e.instance.props.user.id);
2021-06-30 18:05:39 +02:00
}
2022-10-28 13:04:56 +02:00
BDFDB.DataUtils.save(favorizedFriends, this, "favorizedFriends");
BDFDB.DataUtils.save(hiddenFriends, this, "hiddenFriends");
this.rerenderList();
}
}));
2021-06-30 18:05:39 +02:00
}
2020-09-19 20:49:33 +02:00
processTabBar (e) {
2023-10-19 12:27:07 +02:00
if (e.instance.props.children && e.instance.props.children.some(c => c && c.props && c.props.id == BDFDB.DiscordConstants.FriendsSections.ADD_FRIEND)) {
2021-06-30 18:05:39 +02:00
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) {
2022-09-27 16:53:10 +02:00
let relationships = BDFDB.LibraryStores.RelationshipStore.getRelationships(), relationshipCount = {};
2021-06-30 18:05:39 +02:00
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) {
2022-12-11 12:57:32 +01:00
let newChildren = [child.props.children].flat().filter(n => !n || !n.props || n.props.count == undefined);
2021-06-30 18:05:39 +02:00
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:
2022-10-02 17:12:02 +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.LibraryStores.PresenceStore.getStatus(n[0]) != BDFDB.LibraryComponents.StatusComponents.Types.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;
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
2022-12-14 10:40:37 +01:00
processAnalyticsContext (e) {
if (e.instance.props.section != BDFDB.DiscordConstants.AnalyticsSections.FRIENDS_LIST) return;
let [children, index] = BDFDB.ReactUtils.findParent(e.instance, {filter: n => n && n.props && n.props.title && n.props.id});
2022-10-28 13:04:56 +02:00
if (index == -1) return;
2022-12-14 10:40:37 +01:00
let users = (BDFDB.ReactUtils.findChild(e.instance, {props: ["statusSections"]}) || {props: {statusSections: []}}).props.statusSections.flat(10);
2022-10-28 13:04:56 +02:00
let filteredUsers = users;
if (this.settings.general.addFavorizedCategory) {
if (isFavoritesSelected) filteredUsers = filteredUsers.filter(n => n && n.user && favorizedFriends.indexOf(n.user.id) > -1);
}
if (this.settings.general.addHiddenCategory) {
if (isHiddenSelected) filteredUsers = filteredUsers.filter(n => n && n.user && hiddenFriends.indexOf(n.user.id) > -1);
else filteredUsers = filteredUsers.filter(n => n && n.user && hiddenFriends.indexOf(n.user.id) == -1);
}
children[index].props.title = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
children: [
BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN._betterfriendlisttitle,
children: this.settings.general.addFavorizedCategory && isFavoritesSelected ? `${this.labels.favorites} - ${filteredUsers.filter(u => u && u.key != placeHolderId).length}` : this.settings.general.addHiddenCategory && isHiddenSelected ? `${this.labels.hidden} - ${filteredUsers.filter(u => u && u.key != placeHolderId).length}` : children[index].props.title.replace(users.length, filteredUsers.filter(u => u && u.key != placeHolderId).length)
}),
this.settings.general.addSortOptions && [
2023-01-10 10:12:56 +01:00
{key: "nicknameLower", label: BDFDB.LanguageUtils.LanguageStrings.USER_SETTINGS_LABEL_USERNAME},
2022-10-28 13:04:56 +02:00
{key: "statusIndex", label: BDFDB.LanguageUtils.LibraryStrings.status}
].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)
2022-02-09 21:15:49 +01:00
}),
2022-10-28 13:04:56 +02:00
onClick: event => {
if (sortKey == data.key) {
if (!sortReversed) sortReversed = true;
2022-02-09 21:15:49 +01:00
else {
2022-10-28 13:04:56 +02:00
sortKey = null;
2022-02-09 21:15:49 +01:00
sortReversed = false;
}
}
2022-10-28 13:04:56 +02:00
else {
sortKey = data.key;
sortReversed = false;
}
this.rerenderList();
}
}))
].flat(10).filter(n => n)
});
2022-02-09 21:15:49 +01:00
}
2022-12-14 10:40:37 +01:00
processPeopleListSectionedLazy (e) {
this.processPeopleListSectionedNonLazy(e);
}
processPeopleListSectionedNonLazy (e) {
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));
}
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));
}
2023-04-17 13:08:18 +02:00
if (sortKey && e.instance.props.statusSections.flat(10).length) e.instance.props.statusSections = [].concat(e.instance.props.statusSections).map(section => {
2022-12-14 10:40:37 +01:00
let newSection = [].concat(section);
2023-01-10 10:12:56 +01:00
newSection = BDFDB.ArrayUtils.keySort(newSection.map(entry => Object.assign({}, entry, {
statusIndex: statusSortOrder[entry.status],
nicknameLower: entry.nickname ? entry.nickname.toLowerCase() : entry.usernameLower
})), sortKey);
if (sortReversed) newSection.reverse();
2022-12-14 10:40:37 +01:00
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;
});
}
2022-02-09 21:15:49 +01: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;
2022-12-07 11:11:41 +01:00
else if (this.settings.general.addMutualGuild) {
let mutualGuilds = BDFDB.ArrayUtils.removeCopies([].concat(BDFDB.LibraryStores.GuildMemberStore.memberOf(e.instance.props.user.id), (BDFDB.LibraryStores.UserProfileStore.getMutualGuilds(e.instance.props.user.id) || []).map(n => n && n.guild && n.guild.id)).flat()).filter(n => n);
if (mutualGuilds && mutualGuilds.length) {
2023-06-06 08:48:41 +02:00
let guildsIds = BDFDB.LibraryStores.SortedGuildStore.getFlattenedGuildIds();
2020-11-27 17:53:50 +01:00
let childrenRender = e.returnvalue.props.children;
2021-07-05 16:33:10 +02:00
e.returnvalue.props.children = BDFDB.TimeUtils.suppress((...args) => {
2022-12-07 11:11:41 +01:00
let returnValue = childrenRender(...args);
let [children, index] = BDFDB.ReactUtils.findParent(returnValue, {filter: n => n && n.props && n.props.subText && n.props.user});
if (index > -1) children.splice(index + 1, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.GuildSummaryItem, {
className: BDFDB.disCN._betterfriendlistmutualguilds,
guilds: mutualGuilds.sort((x, y) => guildsIds.indexOf(x) < guildsIds.indexOf(y) ? -1 : 1).map(BDFDB.LibraryStores.GuildStore.getGuild),
showTooltip: true,
max: 10
}, true));
return returnValue;
2021-07-05 16:33:10 +02:00
}, "", this);
2020-11-27 17:53:50 +01:00
}
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
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 () {
2022-08-30 18:34:48 +02:00
let selectedButton = document.querySelector(BDFDB.dotCNS.dmchannel + BDFDB.dotCNS.namecontainerselected + "a");
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 {
2023-04-19 10:39:58 +02:00
context_favorizefriend: "Προσθήκη φίλου στους αγαπημένους",
2021-06-30 18:05:39 +02:00
context_hidefriend: "Απόκρυψη φίλου",
2023-04-19 10:39:58 +02:00
context_unfavorizefriend: "Κατάργηση φίλου από τούς αγαπημένους",
context_unhidefriend: "Επανεμφάνιση φίλου",
favorites: "Αγαπημένοι",
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
};
2022-09-01 14:40:11 +02:00
})(window.BDFDB_Global.PluginUtils.buildPlugin(changeLog));
2020-09-19 20:49:33 +02:00
})();