This commit is contained in:
Mirco Wittrien 2021-01-02 12:51:18 +01:00
parent 5f8fc040dd
commit 93503a305f
4 changed files with 193 additions and 81 deletions

View File

@ -16,15 +16,10 @@ module.exports = (_ => {
"info": { "info": {
"name": "BDFDB", "name": "BDFDB",
"author": "DevilBro", "author": "DevilBro",
"version": "1.2.5", "version": "1.2.6",
"description": "Give other plugins utility functions" "description": "Give other plugins utility functions"
}, },
"rawUrl": "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js", "rawUrl": "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js"
"changeLog": {
"improved": {
"Languages": "Added support for all languages used by discord"
}
}
}; };
const DiscordObjects = {}; const DiscordObjects = {};
@ -265,11 +260,11 @@ module.exports = (_ => {
return value; return value;
} }
}; };
BDFDB.ObjectUtils.map = function (obj, mapfunc) { BDFDB.ObjectUtils.map = function (obj, mapFunc) {
if (!BDFDB.ObjectUtils.is(obj)) return {}; if (!BDFDB.ObjectUtils.is(obj)) return {};
if (typeof mapfunc != "string" && typeof mapfunc != "function") return obj; if (typeof mapFunc != "string" && typeof mapFunc != "function") return obj;
let newObj = {}; let newObj = {};
for (let key in obj) if (BDFDB.ObjectUtils.is(obj[key])) newObj[key] = typeof mapfunc == "string" ? obj[key][mapfunc] : mapfunc(obj[key], key); for (let key in obj) if (BDFDB.ObjectUtils.is(obj[key])) newObj[key] = typeof mapFunc == "string" ? obj[key][mapFunc] : mapFunc(obj[key], key);
return newObj; return newObj;
}; };
BDFDB.ObjectUtils.toArray = function (obj) { BDFDB.ObjectUtils.toArray = function (obj) {
@ -3132,12 +3127,12 @@ module.exports = (_ => {
}; };
BDFDB.ColorUtils.setAlpha = function (color, a, conv) { BDFDB.ColorUtils.setAlpha = function (color, a, conv) {
if (BDFDB.ObjectUtils.is(color)) { if (BDFDB.ObjectUtils.is(color)) {
var newcolor = {}; let newcolor = {};
for (let pos in color) newcolor[pos] = BDFDB.ColorUtils.setAlpha(color[pos], a, conv); for (let pos in color) newcolor[pos] = BDFDB.ColorUtils.setAlpha(color[pos], a, conv);
return newcolor; return newcolor;
} }
else { else {
var comp = BDFDB.ColorUtils.convert(color, "RGBCOMP"); let comp = BDFDB.ColorUtils.convert(color, "RGBCOMP");
if (comp) { if (comp) {
a = a.toString(); a = a.toString();
a = (a.indexOf("%") > -1 ? 0.01 : 1) * parseFloat(a.replace(/[^0-9\.\-]/g, "")); a = (a.indexOf("%") > -1 ? 0.01 : 1) * parseFloat(a.replace(/[^0-9\.\-]/g, ""));
@ -3151,7 +3146,7 @@ module.exports = (_ => {
return null; return null;
}; };
BDFDB.ColorUtils.getAlpha = function (color) { BDFDB.ColorUtils.getAlpha = function (color) {
var comp = BDFDB.ColorUtils.convert(color, "RGBCOMP"); let comp = BDFDB.ColorUtils.convert(color, "RGBCOMP");
if (comp) { if (comp) {
if (comp.length == 3) return 1; if (comp.length == 3) return 1;
else if (comp.length == 4) { else if (comp.length == 4) {
@ -3166,12 +3161,12 @@ module.exports = (_ => {
value = parseFloat(value); value = parseFloat(value);
if (color != null && typeof value == "number" && !isNaN(value)) { if (color != null && typeof value == "number" && !isNaN(value)) {
if (BDFDB.ObjectUtils.is(color)) { if (BDFDB.ObjectUtils.is(color)) {
var newcolor = {}; let newColor = {};
for (let pos in color) newcolor[pos] = BDFDB.ColorUtils.change(color[pos], value, conv); for (let pos in color) newColor[pos] = BDFDB.ColorUtils.change(color[pos], value, conv);
return newcolor; return newColor;
} }
else { else {
var comp = BDFDB.ColorUtils.convert(color, "RGBCOMP"); let comp = BDFDB.ColorUtils.convert(color, "RGBCOMP");
if (comp) { if (comp) {
if (parseInt(value) !== value) { if (parseInt(value) !== value) {
value = value.toString(); value = value.toString();
@ -3187,12 +3182,12 @@ module.exports = (_ => {
}; };
BDFDB.ColorUtils.invert = function (color, conv) { BDFDB.ColorUtils.invert = function (color, conv) {
if (BDFDB.ObjectUtils.is(color)) { if (BDFDB.ObjectUtils.is(color)) {
var newcolor = {}; let newColor = {};
for (let pos in color) newcolor[pos] = BDFDB.ColorUtils.invert(color[pos], conv); for (let pos in color) newColor[pos] = BDFDB.ColorUtils.invert(color[pos], conv);
return newcolor; return newColor;
} }
else { else {
var comp = BDFDB.ColorUtils.convert(color, "RGBCOMP"); let comp = BDFDB.ColorUtils.convert(color, "RGBCOMP");
if (comp) return BDFDB.ColorUtils.convert([255 - comp[0], 255 - comp[1], 255 - comp[2]], conv || BDFDB.ColorUtils.getType(color)); if (comp) return BDFDB.ColorUtils.convert([255 - comp[0], 255 - comp[1], 255 - comp[2]], conv || BDFDB.ColorUtils.getType(color));
} }
return null; return null;
@ -3221,7 +3216,7 @@ module.exports = (_ => {
else if (/^#[a-f\d]{4}$|^#[a-f\d]{8}$/i.test(color)) return "HEXA"; else if (/^#[a-f\d]{4}$|^#[a-f\d]{8}$/i.test(color)) return "HEXA";
else { else {
color = color.toUpperCase(); color = color.toUpperCase();
var comp = color.replace(/[^0-9\.\-\,\%]/g, "").split(","); let comp = color.replace(/[^0-9\.\-\,\%]/g, "").split(",");
if (color.indexOf("RGB(") == 0 && comp.length == 3 && isRGB(comp)) return "RGB"; if (color.indexOf("RGB(") == 0 && comp.length == 3 && isRGB(comp)) return "RGB";
else if (color.indexOf("RGBA(") == 0 && comp.length == 4 && isRGB(comp)) return "RGBA"; else if (color.indexOf("RGBA(") == 0 && comp.length == 4 && isRGB(comp)) return "RGBA";
else if (color.indexOf("HSL(") == 0 && comp.length == 3 && isHSL(comp)) return "HSL"; else if (color.indexOf("HSL(") == 0 && comp.length == 3 && isHSL(comp)) return "HSL";
@ -4878,13 +4873,85 @@ module.exports = (_ => {
}; };
InternalComponents.LibraryComponents.Checkbox = reactInitialized && class BDFDB_Checkbox extends LibraryModules.React.Component { InternalComponents.LibraryComponents.Checkbox = reactInitialized && class BDFDB_Checkbox extends LibraryModules.React.Component {
handleChange() { handleClick(e) {if (typeof this.props.onClick == "function") this.props.onClick(e, this);}
this.props.value = !this.props.value; handleContextMenu(e) {if (typeof this.props.onContextMenu == "function") this.props.onContextMenu(e, this);}
handleMouseDown(e) {if (typeof this.props.onMouseDown == "function") this.props.onMouseDown(e, this);}
handleMouseUp(e) {if (typeof this.props.onMouseUp == "function") this.props.onMouseUp(e, this);}
handleMouseEnter(e) {if (typeof this.props.onMouseEnter == "function") this.props.onMouseEnter(e, this);}
handleMouseLeave(e) {if (typeof this.props.onMouseLeave == "function") this.props.onMouseLeave(e, this);}
getInputMode() {
return this.props.disabled ? "disabled" : this.props.readOnly ? "readonly" : "default";
}
getStyle() {
let style = this.props.style || {};
if (!this.props.value) return style;
style = Object.assign({}, style);
this.props.color = typeof this.props.getColor == "function" ? this.props.getColor(this.props.value) : this.props.color;
switch (this.props.type) {
case InternalComponents.NativeSubComponents.Checkbox.Types.DEFAULT:
style.borderColor = this.props.color;
break;
case InternalComponents.NativeSubComponents.Checkbox.Types.GHOST:
let color = BDFDB.ColorUtils.setAlpha(this.props.color, 0.15, "RGB");
style.borderColor = color;
style.backgroundColor = color;
break;
case InternalComponents.NativeSubComponents.Checkbox.Types.INVERTED:
style.backgroundColor = this.props.color;
style.borderColor = this.props.color;
}
return style;
}
getColor() {
return this.props.value ? (this.props.type === InternalComponents.NativeSubComponents.Checkbox.Types.INVERTED ? BDFDB.DiscordConstants.Colors.WHITE : this.props.color) : "transparent";
}
handleChange(e) {
this.props.value = typeof this.props.getValue == "function" ? this.props.getValue(this.props.value, e) : !this.props.value;
if (typeof this.props.onChange == "function") this.props.onChange(this.props.value, this); if (typeof this.props.onChange == "function") this.props.onChange(this.props.value, this);
BDFDB.ReactUtils.forceUpdate(this); BDFDB.ReactUtils.forceUpdate(this);
} }
render() { render() {
return BDFDB.ReactUtils.createElement(InternalComponents.NativeSubComponents.Checkbox, Object.assign({}, this.props, {onChange: this.handleChange.bind(this)})); let label = this.props.children ? BDFDB.ReactUtils.createElement("div", {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.checkboxlabel, this.props.disabled ? BDFDB.disCN.checkboxlabeldisabled : BDFDB.disCN.checkboxlabelclickable, this.props.reverse ? BDFDB.disCN.checkboxlabelreversed : BDFDB.disCN.checkboxlabelforward),
style: {
lineHeight: this.props.size + "px"
},
children: this.props.children
}) : null;
return BDFDB.ReactUtils.createElement("label", {
className: BDFDB.DOMUtils.formatClassName(this.props.disabled ? BDFDB.disCN.checkboxwrapperdisabled : BDFDB.disCN.checkboxwrapper, this.props.align, this.props.className),
children: [
this.props.reverse && label,
!this.props.displayOnly && BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.FocusRingScope, {
children: BDFDB.ReactUtils.createElement("input", {
className: BDFDB.disCN["checkboxinput" + this.getInputMode()],
type: "checkbox",
onClick: this.props.disabled || this.props.readOnly ? (_ => {}) : this.handleChange.bind(this),
onContextMenu: this.props.disabled || this.props.readOnly ? (_ => {}) : this.handleChange.bind(this),
checked: this.props.value,
style: {
width: this.props.size,
height: this.props.size
}
})
}),
BDFDB.ReactUtils.createElement("div", {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.checkbox, this.props.shape, this.props.value && BDFDB.disCN.checkboxchecked),
style: Object.assign({
width: this.props.size,
height: this.props.size,
borderColor: this.props.checkboxColor
}, this.getStyle()),
children: BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.Checkmark, {
width: 18,
height: 18,
color: this.getColor(),
"aria-hidden": true
})
}),
!this.props.reverse && label
].filter(n => n)
});
} }
}; };
@ -6574,13 +6641,15 @@ module.exports = (_ => {
shape: InternalComponents.LibraryComponents.Checkbox.Shapes.ROUND, shape: InternalComponents.LibraryComponents.Checkbox.Shapes.ROUND,
type: InternalComponents.LibraryComponents.Checkbox.Types.INVERTED, type: InternalComponents.LibraryComponents.Checkbox.Types.INVERTED,
color: this.props.checkboxColor, color: this.props.checkboxColor,
getColor: this.props.getCheckboxColor,
value: props[setting], value: props[setting],
getValue: this.props.getCheckboxValue,
onChange: this.props.onCheckboxChange onChange: this.props.onCheckboxChange
}) })
})).flat(10).filter(n => n) })).flat(10).filter(n => n)
}) })
] ]
}), "title", "data", "settings", "renderLabel", "cardClassName", "cardStyle", "checkboxColor", "onCheckboxChange", "maxWidth", "fullWidth", "biggestWidth", "pagination")); }), "title", "data", "settings", "renderLabel", "cardClassName", "cardStyle", "checkboxColor", "getCheckboxColor", "getCheckboxValue", "onCheckboxChange", "configWidth", "pagination"));
} }
render() { render() {
this.props.settings = BDFDB.ArrayUtils.is(this.props.settings) ? this.props.settings : []; this.props.settings = BDFDB.ArrayUtils.is(this.props.settings) ? this.props.settings : [];

View File

@ -488,6 +488,7 @@
"bdRepoHeaderControls": "controls-18FQsW", "bdRepoHeaderControls": "controls-18FQsW",
"bdRepoListHeader": "repoHeader-2KfNvH", "bdRepoListHeader": "repoHeader-2KfNvH",
"bdRepoListWrapper": "repoList-9JnAPs", "bdRepoListWrapper": "repoList-9JnAPs",
"cardDisabled": "cardDisabled-wnh5ZW",
"cardHorizontal": "horizontal-0ffRsT", "cardHorizontal": "horizontal-0ffRsT",
"cardInner": "inner-OP_8zd", "cardInner": "inner-OP_8zd",
"cardWrapper": "card-rT4Wbb", "cardWrapper": "card-rT4Wbb",
@ -1888,6 +1889,7 @@
"hotkeywrapper": ["BDFDB", "hotkeyWrapper"], "hotkeywrapper": ["BDFDB", "hotkeyWrapper"],
"hovercard": ["HoverCard", "card"], "hovercard": ["HoverCard", "card"],
"hovercardbutton": ["NotFound", "hoverCardButton"], "hovercardbutton": ["NotFound", "hoverCardButton"],
"hovercarddisabled": ["BDFDB", "cardDisabled"],
"hovercardhorizontal": ["BDFDB", "cardHorizontal"], "hovercardhorizontal": ["BDFDB", "cardHorizontal"],
"hovercardinner": ["BDFDB", "cardInner"], "hovercardinner": ["BDFDB", "cardInner"],
"hovercardwrapper": ["BDFDB", "cardWrapper"], "hovercardwrapper": ["BDFDB", "cardWrapper"],

View File

@ -364,9 +364,13 @@ img:not([src]), img[src=""], img[src="null"] {
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
} }
[REPLACE_CLASS_hovercardwrapper][REPLACE_CLASS_hovercardhorizontal] { [REPLACE_CLASS_hovercardhorizontal] {
flex-direction: row; flex-direction: row;
} }
[REPLACE_CLASS_hovercarddisabled] {
opacity: 0.7;
filter: grayscale(0.2);
}
[REPLACE_CLASS_settingspanel] [REPLACE_CLASS_hovercardwrapper] { [REPLACE_CLASS_settingspanel] [REPLACE_CLASS_hovercardwrapper] {
width: calc(100% - 22px); width: calc(100% - 22px);
} }

View File

@ -14,12 +14,12 @@ module.exports = (_ => {
"info": { "info": {
"name": "FriendNotifications", "name": "FriendNotifications",
"author": "DevilBro", "author": "DevilBro",
"version": "1.5.5", "version": "1.5.6",
"description": "Get a notification when a Friend or a User you choose to observe changes their online status, can be configured individually in the settings" "description": "Get a notification when a Friend or a User you choose to observe changes their online status, can be configured individually in the settings"
}, },
"changeLog": { "changeLog": {
"added": { "improved": {
"Search": "You can now search for a username in the time log modal" "Toast/Desktop": "You can now set toast/desktop notifications for single status options instead of the whole user"
} }
} }
}; };
@ -68,6 +68,24 @@ module.exports = (_ => {
var friendCounter, timeLogList; var friendCounter, timeLogList;
var settings = {}, amounts = {}, notificationStrings = {}, notificationSounds = {}, observedUsers = {}; var settings = {}, amounts = {}, notificationStrings = {}, notificationSounds = {}, observedUsers = {};
const notificationTypes = {
DISABLED: {
button: null,
value: 0,
color: ""
},
TOAST: {
button: 0,
value: 1,
color: "var(--bdfdb-blurple)"
},
DESKTOP: {
button: 2,
value: 2,
color: "STATUS_GREEN"
}
};
const FriendOnlineCounterComponent = class FriendOnlineCounter extends BdApi.React.Component { const FriendOnlineCounterComponent = class FriendOnlineCounter extends BdApi.React.Component {
componentDidMount() { componentDidMount() {
friendCounter = this; friendCounter = this;
@ -140,27 +158,27 @@ module.exports = (_ => {
this.defaults = { this.defaults = {
settings: { settings: {
addOnlineCount: {value: true, description: "Add an online friend counter to the server list (click to open logs)"}, addOnlineCount: {value: true, description: "Add an Online friend Counter to the Server List (click to open logs)"},
showDiscriminator: {value: false, description: "Add the user discriminator"}, showDiscriminator: {value: false, description: "Add the User Discriminator"},
disableForNew: {value: false, description: "Disable Notifications for newly added Friends: "}, disableForNew: {value: false, description: "Disable Notifications for newly added Friends: "},
muteOnDND: {value: false, description: "Do not notify me when I am DnD"}, muteOnDND: {value: false, description: "Do not notify me when I am in DnD"},
openOnClick: {value: false, description: "Open the DM when you click a Notification"} openOnClick: {value: false, description: "Open the DM when you click a Notification"}
}, },
notificationstrings: { notificationstrings: {
online: {value: "$user changed status to '$status'", libString: "STATUS_ONLINE", init: true}, online: {value: "$user changed status to '$status'", libString: "STATUS_ONLINE", init: true},
mobile: {value: "$user changed status to '$status'", libString: "STATUS_ONLINE_MOBILE", init: true}, mobile: {value: "$user changed status to '$status'", libString: "STATUS_ONLINE_MOBILE", init: true},
idle: {value: "$user changed status to '$status'", libString: "STATUS_IDLE", init: false}, idle: {value: "$user changed status to '$status'", libString: "STATUS_IDLE", init: false},
dnd: {value: "$user changed status to '$status'", libString: "STATUS_DND", init: false}, dnd: {value: "$user changed status to '$status'", libString: "STATUS_DND", init: false},
playing: {value: "$user started playing '$game'", statusName: "Playing", init: false}, playing: {value: "$user started playing '$game'", statusName: "Playing", init: false},
listening: {value: "$user started listening to '$song'", statusName: "Listening", init: false}, listening: {value: "$user started listening to '$song'", statusName: "Listening", init: false},
streaming: {value: "$user started streaming '$game'", libString: "STATUS_STREAMING", init: false}, streaming: {value: "$user started streaming '$game'", libString: "STATUS_STREAMING", init: false},
offline: {value: "$user changed status to '$status'", libString: "STATUS_OFFLINE", init: true} offline: {value: "$user changed status to '$status'", libString: "STATUS_OFFLINE", init: true}
}, },
notificationsounds: {}, notificationsounds: {},
amounts: { amounts: {
toastTime: {value: 5, min: 1, description: "Amount of seconds a toast notification stays on screen: "}, toastTime: {value: 5, min: 1, description: "Amount of Seconds a Toast Notification stays on Screen: "},
desktopTime: {value: 5, min: 1, description: "Amount of seconds a desktop notification stays on screen: "}, desktopTime: {value: 5, min: 1, description: "Amount of Seconds a Desktop Notification stays on Screen: "},
checkInterval: {value: 10, min: 5, description: "Check Users every X seconds: "} checkInterval: {value: 10, min: 5, description: "Check Users every X Seconds: "}
} }
}; };
@ -202,6 +220,20 @@ module.exports = (_ => {
} }
onStart() { onStart() {
// REMOVE 1.1.2021
let convert = type => {
let data = BDFDB.DataUtils.load(this, type);
if (Object.keys(data).length) {
for (let id in data) if (data[id].desktop != undefined) {
for (let key of Object.keys(this.defaults.notificationstrings)) data[id][key] = notificationTypes[!data[id][key] ? "DISABLED" : (data[id].desktop ? "DESKTOP" : "TOAST")].value;
delete data[id].desktop;
}
BDFDB.DataUtils.save(data, this, type);
}
};
convert("friends");
convert("nonfriends");
this.startInterval(); this.startInterval();
BDFDB.PatchUtils.forceAllUpdates(this); BDFDB.PatchUtils.forceAllUpdates(this);
@ -214,23 +246,16 @@ module.exports = (_ => {
} }
getSettingsPanel (collapseStates = {}) { getSettingsPanel (collapseStates = {}) {
let changeNotificationType = (type, userId, desktopOn, disableOn) => { let changeAllConfigs = (type, config, notificationType) => {
let data = BDFDB.DataUtils.load(this, type, userId) || this.createDefaultConfig();
data.desktop = desktopOn;
data.disabled = disableOn;
BDFDB.DataUtils.save(data, this, type, userId);
this.SettingsUpdated = true;
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
};
let changeAllConfigs = (type, config, enable) => {
let allData = BDFDB.DataUtils.load(this, type); let allData = BDFDB.DataUtils.load(this, type);
if (config == "type") { if (config == "all") {
config = "desktop"; config = "disabled";
enable = !enable; for (let id in allData) allData[id][config] = notificationTypes[notificationType].button == 0 ? false : true;
let disabled = BDFDB.ObjectUtils.toArray(allData).every(d => !d.disabled && d[config] == enable); }
for (let id in allData) allData[id].disabled = disabled; else {
let disabled = BDFDB.ObjectUtils.toArray(allData).every(d => !d.disabled && d[config] == notificationTypes[notificationType].value);
for (let id in allData) allData[id][config] = notificationTypes[disabled ? "DISABLED" : notificationType].value;
} }
for (let id in allData) allData[id][config] = enable;
BDFDB.DataUtils.save(allData, this, type); BDFDB.DataUtils.save(allData, this, type);
this.SettingsUpdated = true; this.SettingsUpdated = true;
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates); BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
@ -247,7 +272,7 @@ module.exports = (_ => {
items.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, { items.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
className: BDFDB.disCNS.settingsrowtitle + BDFDB.disCNS.settingsrowtitledefault + BDFDB.disCN.cursordefault, className: BDFDB.disCNS.settingsrowtitle + BDFDB.disCNS.settingsrowtitledefault + BDFDB.disCN.cursordefault,
children: [ children: [
"Click on an Icon to toggle", "Click on an Option to toggle",
BDFDB.ReactUtils.createElement("span", { BDFDB.ReactUtils.createElement("span", {
className: BDFDB.disCN._friendnotificationstypelabel, className: BDFDB.disCN._friendnotificationstypelabel,
style: {backgroundColor: "var(--bdfdb-blurple)"}, style: {backgroundColor: "var(--bdfdb-blurple)"},
@ -259,7 +284,7 @@ module.exports = (_ => {
if ("Notification" in window) items.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, { if ("Notification" in window) items.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
className: BDFDB.disCNS.settingsrowtitle + BDFDB.disCNS.settingsrowtitledefault + BDFDB.disCN.cursordefault, className: BDFDB.disCNS.settingsrowtitle + BDFDB.disCNS.settingsrowtitledefault + BDFDB.disCN.cursordefault,
children: [ children: [
"Right-Click on an Icon to toggle", "Right-Click on an Option to toggle",
BDFDB.ReactUtils.createElement("span", { BDFDB.ReactUtils.createElement("span", {
className: BDFDB.disCN._friendnotificationstypelabel, className: BDFDB.disCN._friendnotificationstypelabel,
style: {backgroundColor: BDFDB.DiscordConstants.Colors.STATUS_GREEN}, style: {backgroundColor: BDFDB.DiscordConstants.Colors.STATUS_GREEN},
@ -270,7 +295,7 @@ module.exports = (_ => {
})); }));
items.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, { items.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, {
className: BDFDB.disCN.margintop20, className: BDFDB.disCN.margintop20,
title: "type", title: "all",
settings: Object.keys(this.defaults.notificationstrings), settings: Object.keys(this.defaults.notificationstrings),
data: users, data: users,
pagination: { pagination: {
@ -279,6 +304,14 @@ module.exports = (_ => {
offset: paginationOffset[title] || 0, offset: paginationOffset[title] || 0,
onJump: offset => {paginationOffset[title] = offset;} onJump: offset => {paginationOffset[title] = offset;}
}, },
getCheckboxColor: value => {
let color = (BDFDB.ObjectUtils.toArray(notificationTypes).find(n => n.value == value) || {}).color;
return BDFDB.DiscordConstants.Colors[color] || color;
},
getCheckboxValue: (value, event) => {
let eventValue = (BDFDB.ObjectUtils.toArray(notificationTypes).find(n => n.button == event.button) || {}).value;
return eventValue == value ? 0 : eventValue;
},
renderLabel: data => [ renderLabel: data => [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.AvatarComponents.default, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.AvatarComponents.default, {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.listavatar, data.disabled && BDFDB.disCN.avatardisabled), className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.listavatar, data.disabled && BDFDB.disCN.avatardisabled),
@ -286,10 +319,11 @@ module.exports = (_ => {
status: BDFDB.UserUtils.getStatus(data.id), status: BDFDB.UserUtils.getStatus(data.id),
size: BDFDB.LibraryComponents.AvatarComponents.Sizes.SIZE_40, size: BDFDB.LibraryComponents.AvatarComponents.Sizes.SIZE_40,
onClick: (e, instance) => { onClick: (e, instance) => {
changeNotificationType(type, data.id, false, !(data.disabled || data.desktop)); let saveData = BDFDB.DataUtils.load(this, type, data.id) || this.createDefaultConfig();
}, saveData.disabled = !saveData.disabled;
onContextMenu: (e, instance) => { BDFDB.DataUtils.save(saveData, this, type, data.id);
changeNotificationType(type, data.id, true, !(data.disabled || !data.desktop)); this.SettingsUpdated = true;
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
} }
}), }),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextScroller, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextScroller, {
@ -297,10 +331,10 @@ module.exports = (_ => {
}) })
], ],
onHeaderClick: (config, instance) => { onHeaderClick: (config, instance) => {
changeAllConfigs(type, config, true); changeAllConfigs(type, config, "TOAST");
}, },
onHeaderContextMenu: (config, instance) => { onHeaderContextMenu: (config, instance) => {
changeAllConfigs(type, config, false); changeAllConfigs(type, config, "DESKTOP");
}, },
onCheckboxChange: (value, instance) => { onCheckboxChange: (value, instance) => {
let data = BDFDB.DataUtils.load(this, type, instance.props.cardId) || this.createDefaultConfig(); let data = BDFDB.DataUtils.load(this, type, instance.props.cardId) || this.createDefaultConfig();
@ -352,12 +386,18 @@ module.exports = (_ => {
nonFriendsData[id] = Object.assign({}, friendsData[id]); nonFriendsData[id] = Object.assign({}, friendsData[id]);
delete friendsData[id]; delete friendsData[id];
} }
else if (id != BDFDB.UserUtils.me.id) friends.push(Object.assign({}, user, friendsData[id], {key: id, className: friendsData[id].disabled ? "" : (friendsData[id].desktop ? BDFDB.disCN.cardsuccessoutline : BDFDB.disCN.cardbrandoutline)})); else if (id != BDFDB.UserUtils.me.id) friends.push(Object.assign({}, user, friendsData[id], {
key: id,
className: friendsData[id].disabled ? "" : BDFDB.disCN.hovercarddisabled
}));
} }
} }
for (let id in nonFriendsData) { for (let id in nonFriendsData) {
let user = BDFDB.LibraryModules.UserStore.getUser(id); let user = BDFDB.LibraryModules.UserStore.getUser(id);
if (user && id != BDFDB.UserUtils.me.id) nonFriends.push(Object.assign({}, user, nonFriendsData[id], {key: id, className: nonFriendsData[id].disabled ? "" : (nonFriendsData[id].desktop ? BDFDB.disCN.cardsuccessoutline : BDFDB.disCN.cardbrandoutline)})); if (user && id != BDFDB.UserUtils.me.id) nonFriends.push(Object.assign({}, user, nonFriendsData[id], {
key: id,
className: nonFriendsData[id].disabled ? "" : BDFDB.disCN.hovercarddisabled
}));
} }
BDFDB.DataUtils.save(friendsData, this, "friends"); BDFDB.DataUtils.save(friendsData, this, "friends");
@ -595,9 +635,8 @@ module.exports = (_ => {
createDefaultConfig () { createDefaultConfig () {
return Object.assign({ return Object.assign({
desktop: false,
disabled: settings.disableForNew disabled: settings.disableForNew
}, BDFDB.ObjectUtils.map(this.defaults.notificationstrings, "init")); }, BDFDB.ObjectUtils.map(this.defaults.notificationstrings, data => notificationTypes[data.init ? "TOAST" : "DISABLED"].value));
} }
getStatusWithMobileAndActivity (id, config) { getStatusWithMobileAndActivity (id, config) {
@ -669,24 +708,22 @@ module.exports = (_ => {
BDFDB.LibraryRequires.electron.remote.getCurrentWindow().focus(); BDFDB.LibraryRequires.electron.remote.getCurrentWindow().focus();
} }
}; };
if (!observedUsers[id].desktop) { if (observedUsers[id][status.statusName] == notificationTypes.DESKTOP.value) {
if (!document.querySelector(`.friendnotifications-${id}-toast`)) {
let toast = BDFDB.NotificationUtils.toast(`<div class="${BDFDB.disCN.toastinner}"><div class="${BDFDB.disCN.toastavatar}" style="background-image: url(${avatar});"></div><div>${toastString}</div></div>`, {html: true, timeout: toastTime, color: BDFDB.UserUtils.getStatusColor(status.statusName), icon: false, selector: `friendnotifications-${status.statusName}-toast friendnotifications-${id}-toast`});
toast.addEventListener("click", openChannel);
let notificationsound = notificationSounds["toast" + status.statusName] || {};
if (!notificationsound.mute && notificationsound.song) {
let audio = new Audio();
audio.src = notificationsound.song;
audio.play();
}
}
}
else {
let desktopString = string.replace(/\$user/g, `${name}${settings.showDiscriminator ? ("#" + user.discriminator) : ""}`).replace(/\$status/g, libString); let desktopString = string.replace(/\$user/g, `${name}${settings.showDiscriminator ? ("#" + user.discriminator) : ""}`).replace(/\$status/g, libString);
if (status.isActivity) desktopString = desktopString.replace(/\$song|\$game/g, status.name || status.details).replace(/\$artist/g, status.state); if (status.isActivity) desktopString = desktopString.replace(/\$song|\$game/g, status.name || status.details).replace(/\$artist/g, status.state);
let notificationsound = notificationSounds["desktop" + status.statusName] || {}; let notificationsound = notificationSounds["desktop" + status.statusName] || {};
BDFDB.NotificationUtils.desktop(desktopString, {icon: avatar, timeout: desktopTime, click: openChannel, silent: notificationsound.mute, sound: notificationsound.song}); BDFDB.NotificationUtils.desktop(desktopString, {icon: avatar, timeout: desktopTime, click: openChannel, silent: notificationsound.mute, sound: notificationsound.song});
} }
else if (!document.querySelector(`.friendnotifications-${id}-toast`)) {
let toast = BDFDB.NotificationUtils.toast(`<div class="${BDFDB.disCN.toastinner}"><div class="${BDFDB.disCN.toastavatar}" style="background-image: url(${avatar});"></div><div>${toastString}</div></div>`, {html: true, timeout: toastTime, color: BDFDB.UserUtils.getStatusColor(status.statusName), icon: false, selector: `friendnotifications-${status.statusName}-toast friendnotifications-${id}-toast`});
toast.addEventListener("click", openChannel);
let notificationsound = notificationSounds["toast" + status.statusName] || {};
if (!notificationsound.mute && notificationsound.song) {
let audio = new Audio();
audio.src = notificationsound.song;
audio.play();
}
}
} }
} }
userStatusStore[id] = status.statusName; userStatusStore[id] = status.statusName;