2020-08-26 12:10:17 +02:00
|
|
|
//META{"name":"BetterFriendList","authorId":"278543574059057154","invite":"Jx3TjNS","donate":"https://www.paypal.me/MircoWittrien","patreon":"https://www.patreon.com/MircoWittrien","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/BetterFriendList","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/BetterFriendList/BetterFriendList.plugin.js"}*//
|
|
|
|
|
|
|
|
var BetterFriendList = (_ => {
|
|
|
|
var rerenderTimeout, sortKey, sortReversed, searchQuery, searchTimeout;
|
2020-08-26 15:21:49 +02:00
|
|
|
var settings = {};
|
2020-08-26 12:10:17 +02:00
|
|
|
const statusSortOrder = {
|
|
|
|
online: 0,
|
|
|
|
streaming: 1,
|
|
|
|
idle: 2,
|
|
|
|
dnd: 3,
|
|
|
|
offline: 4,
|
|
|
|
invisible: 5,
|
|
|
|
unknown: 6
|
|
|
|
};
|
|
|
|
|
|
|
|
return class BetterFriendList {
|
|
|
|
getName () {return "BetterFriendList";}
|
|
|
|
|
2020-08-26 15:21:49 +02:00
|
|
|
getVersion () {return "1.2.6";}
|
2020-08-26 12:10:17 +02:00
|
|
|
|
|
|
|
getAuthor () {return "DevilBro";}
|
|
|
|
|
|
|
|
getDescription () {return "Adds extra controls to the friends page, like sort by name/status, search and all/request/blocked amount.";}
|
|
|
|
|
|
|
|
initConstructor () {
|
|
|
|
sortKey = null;
|
|
|
|
sortReversed = false;
|
|
|
|
searchQuery = "";
|
|
|
|
|
|
|
|
this.css = `
|
|
|
|
${BDFDB.dotCN._betterfriendlisttitle} {
|
|
|
|
width: 200px;
|
|
|
|
}
|
|
|
|
${BDFDB.dotCN._betterfriendlistnamecell} {
|
|
|
|
width: 150px;
|
|
|
|
}
|
|
|
|
`;
|
2020-08-26 15:21:49 +02:00
|
|
|
|
|
|
|
this.defaults = {
|
|
|
|
settings: {
|
|
|
|
addTotalAmount: {value:true, description:"Add total amount for all/requested/blocked"},
|
|
|
|
addSortOptions: {value:true, description:"Add sort options"},
|
|
|
|
addSearchbar: {value:true, description:"Add searchbar"}
|
|
|
|
}
|
|
|
|
};
|
2020-08-26 12:10:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor () {
|
|
|
|
this.changelog = {
|
2020-08-26 15:21:49 +02:00
|
|
|
"progress":[["New Features & Name","Name was changed from BetterFriendCount to BetterFriendList and new features were added"]],
|
|
|
|
"added":[["Settings","You can now disable the single features of this plugin"]]
|
2020-08-26 12:10:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
this.patchedModules = {
|
|
|
|
before: {
|
|
|
|
PeopleListSectionedLazy: "default"
|
|
|
|
},
|
|
|
|
after: {
|
|
|
|
TabBar: "render",
|
|
|
|
PeopleListItem: ["componentWillMount","componentWillUnmount"]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// Legacy
|
|
|
|
load () {
|
|
|
|
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) BDFDB.PluginUtils.load(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
start () {
|
|
|
|
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
|
|
|
|
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
|
|
|
|
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
|
|
|
|
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
|
|
|
if (libraryScript) libraryScript.remove();
|
|
|
|
libraryScript = document.createElement("script");
|
|
|
|
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
|
|
|
libraryScript.setAttribute("type", "text/javascript");
|
|
|
|
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
|
|
|
libraryScript.setAttribute("date", performance.now());
|
|
|
|
libraryScript.addEventListener("load", _ => {this.initialize();});
|
|
|
|
document.head.appendChild(libraryScript);
|
|
|
|
}
|
|
|
|
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
|
|
|
this.startTimeout = setTimeout(_ => {
|
|
|
|
try {return this.initialize();}
|
|
|
|
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
|
|
|
}, 30000);
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize () {
|
|
|
|
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
|
|
|
if (this.started) return;
|
|
|
|
BDFDB.PluginUtils.init(this);
|
|
|
|
|
2020-08-26 15:21:49 +02:00
|
|
|
this.forceUpdateAll();
|
2020-08-26 12:10:17 +02:00
|
|
|
}
|
|
|
|
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
|
|
|
}
|
|
|
|
|
|
|
|
stop () {
|
|
|
|
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
|
|
|
this.stopping = true;
|
|
|
|
|
2020-08-26 15:21:49 +02:00
|
|
|
this.forceUpdateAll();
|
2020-08-26 12:10:17 +02:00
|
|
|
|
|
|
|
BDFDB.PluginUtils.clear(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Begin of own functions
|
|
|
|
|
2020-08-26 15:21:49 +02:00
|
|
|
onSettingsClosed () {
|
|
|
|
if (this.SettingsUpdated) {
|
|
|
|
delete this.SettingsUpdated;
|
|
|
|
this.forceUpdateAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-26 12:10:17 +02:00
|
|
|
processTabBar (e) {
|
2020-08-26 15:21:49 +02:00
|
|
|
if (settings.addTotalAmount && e.returnvalue.props.children) for (let checkChild of e.returnvalue.props.children) if (checkChild && checkChild.props.id == "ADD_FRIEND") {
|
2020-08-26 12:10:17 +02:00
|
|
|
let relationships = BDFDB.LibraryModules.FriendUtils.getRelationships(), relationshipCount = {};
|
|
|
|
for (let type in BDFDB.DiscordConstants.RelationshipTypes) relationshipCount[type] = 0;
|
|
|
|
for (let id in relationships) relationshipCount[relationships[id]]++;
|
|
|
|
for (let child of e.returnvalue.props.children) if (child && child.props.id != "ADD_FRIEND") {
|
|
|
|
let newChildren = [child.props.children].flat().filter(child => BDFDB.ReactUtils.getValue(child, "type.displayName") != "NumberBadge");
|
|
|
|
switch (child.props.id) {
|
|
|
|
case "ALL":
|
|
|
|
newChildren.push(this.createBadge(relationshipCount[BDFDB.DiscordConstants.RelationshipTypes.FRIEND]));
|
|
|
|
break;
|
|
|
|
case "ONLINE":
|
|
|
|
newChildren.push(this.createBadge(BDFDB.LibraryModules.StatusMetaUtils.getOnlineFriendCount()));
|
|
|
|
break;
|
|
|
|
case "PENDING":
|
|
|
|
newChildren.push(this.createBadge(relationshipCount[BDFDB.DiscordConstants.RelationshipTypes.PENDING_INCOMING]));
|
|
|
|
newChildren.push(this.createBadge(relationshipCount[BDFDB.DiscordConstants.RelationshipTypes.PENDING_OUTGOING]));
|
|
|
|
break;
|
|
|
|
case "BLOCKED":
|
|
|
|
newChildren.push(this.createBadge(relationshipCount[BDFDB.DiscordConstants.RelationshipTypes.BLOCKED]));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
child.props.children = newChildren;
|
|
|
|
}
|
2020-08-26 15:21:49 +02:00
|
|
|
break;
|
2020-08-26 12:10:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
processPeopleListSectionedLazy (e) {
|
|
|
|
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(user => user && typeof user.usernameLower == "string" && user.usernameLower.indexOf(usedSearchQuery) > -1);
|
|
|
|
}
|
|
|
|
if (sortKey) {
|
|
|
|
newSection = BDFDB.ArrayUtils.keySort(newSection.map(user => Object.assign({}, user, {statusIndex: statusSortOrder[user.status]})), sortKey);
|
|
|
|
if (sortReversed) newSection.reverse();
|
|
|
|
}
|
|
|
|
return newSection;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
let getSectionTitle = e.instance.props.getSectionTitle;
|
|
|
|
e.instance.props.getSectionTitle = (...args) => {
|
|
|
|
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
|
|
|
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
|
|
|
|
children: [
|
|
|
|
BDFDB.ReactUtils.createElement("div", {
|
|
|
|
className: BDFDB.disCN._betterfriendlisttitle,
|
|
|
|
children: getSectionTitle(...args)
|
|
|
|
}),
|
2020-08-26 15:21:49 +02:00
|
|
|
settings.addSortOptions && [
|
2020-08-26 12:10:17 +02:00
|
|
|
{key: "usernameLower", label: BDFDB.LanguageUtils.LanguageStrings.FRIENDS_COLUMN_NAME},
|
|
|
|
{key: "statusIndex", label: BDFDB.LanguageUtils.LanguageStrings.FRIENDS_COLUMN_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)
|
|
|
|
}),
|
|
|
|
onClick: event => {
|
|
|
|
if (sortKey == data.key) {
|
|
|
|
if (!sortReversed) sortReversed = true;
|
|
|
|
else {
|
|
|
|
sortKey = null;
|
|
|
|
sortReversed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sortKey = data.key;
|
|
|
|
sortReversed = false;
|
|
|
|
}
|
|
|
|
this.rerenderList();
|
|
|
|
}
|
|
|
|
})),
|
2020-08-26 15:21:49 +02:00
|
|
|
settings.addSearchbar && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, {
|
2020-08-26 12:23:22 +02: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 = "";
|
2020-08-26 12:10:17 +02:00
|
|
|
this.rerenderList();
|
2020-08-26 12:23:22 +02:00
|
|
|
}
|
|
|
|
})
|
2020-08-26 12:10:17 +02:00
|
|
|
})
|
|
|
|
].flat(10).filter(n => n)
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
processPeopleListItem (e) {
|
|
|
|
BDFDB.TimeUtils.clear(rerenderTimeout);
|
|
|
|
rerenderTimeout = BDFDB.TimeUtils.timeout(_ => {BDFDB.ModuleUtils.forceAllUpdates(this, "TabBar");}, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
createBadge (amount) {
|
|
|
|
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Badges.NumberBadge, {
|
|
|
|
className: BDFDB.disCN.peoplesbadge,
|
|
|
|
count: amount,
|
|
|
|
style: {marginLeft: 6}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
rerenderList () {
|
|
|
|
let selectedButton = document.querySelector(BDFDB.dotCNS.peoplestabbar + BDFDB.dotCN.settingsitemselected);
|
|
|
|
if (selectedButton) selectedButton.click();
|
|
|
|
}
|
2020-08-26 15:21:49 +02:00
|
|
|
|
|
|
|
forceUpdateAll() {
|
|
|
|
settings = BDFDB.DataUtils.get(this, "settings");
|
|
|
|
|
|
|
|
BDFDB.ModuleUtils.forceAllUpdates(this, "TabBar");
|
|
|
|
this.rerenderList();
|
|
|
|
}
|
2020-08-26 12:10:17 +02:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
module.exports = BetterFriendList;
|