From 8b50b441f7223eb9c7c20cd5cd4c6e3325f63176 Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Wed, 30 Jun 2021 15:38:41 +0200 Subject: [PATCH] Update FriendNotifications.plugin.js --- .../FriendNotifications.plugin.js | 77 ++++++++----------- 1 file changed, 32 insertions(+), 45 deletions(-) diff --git a/Plugins/FriendNotifications/FriendNotifications.plugin.js b/Plugins/FriendNotifications/FriendNotifications.plugin.js index c207731d0c..2072fa482a 100644 --- a/Plugins/FriendNotifications/FriendNotifications.plugin.js +++ b/Plugins/FriendNotifications/FriendNotifications.plugin.js @@ -2,7 +2,7 @@ * @name FriendNotifications * @author DevilBro * @authorId 278543574059057154 - * @version 1.7.2 + * @version 1.7.4 * @description Shows a Notification when a Friend or a User, you choose to observe, changes their Status * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -17,12 +17,12 @@ module.exports = (_ => { "info": { "name": "FriendNotifications", "author": "DevilBro", - "version": "1.7.2", + "version": "1.7.4", "description": "Shows a Notification when a Friend or a User, you choose to observe, changes their Status" }, "changeLog": { "improved": { - "Added some extra Info": "New Info on how to control the Observer List better" + "Default Settings": "Added extended Options to configure a default Setup for new Users" } } }; @@ -76,6 +76,7 @@ module.exports = (_ => { var _this; var userStatusStore, timeLog, lastTimes, checkInterval; var friendCounter, timeLogList; + var defaultSettings = {}; var observedUsers = {}; var paginationOffset = {}; @@ -215,7 +216,6 @@ module.exports = (_ => { general: { addOnlineCount: {value: true, description: "Add an Online Friend Counter to the Server List (Click to open Time Log)"}, showDiscriminator: {value: false, description: "Add the User Discriminator"}, - disableForNew: {value: false, description: "Disable Notifications for newly added Friends"}, muteOnDND: {value: false, description: "Do not notify me when I am in DnD Status"}, openOnClick: {value: false, description: "Open the DM when you click a Notification"} }, @@ -278,41 +278,20 @@ module.exports = (_ => { } } - onStart () { - // REMOVE 24.04.2021 - let oldData = BDFDB.DataUtils.load(this); - if (oldData.settings) { - this.settings.general = oldData.settings; - BDFDB.DataUtils.save(this.settings.general, this, "general"); - BDFDB.DataUtils.remove(this, "settings"); - } - if (oldData.notificationstrings) { - this.settings.notificationStrings = oldData.notificationstrings; - BDFDB.DataUtils.save(this.settings.notificationStrings, this, "notificationStrings"); - BDFDB.DataUtils.remove(this, "notificationstrings"); - } - if (oldData.notificationsounds) { - this.settings.notificationSounds = oldData.notificationsounds; - BDFDB.DataUtils.save(this.settings.notificationSounds, this, "notificationSounds"); - BDFDB.DataUtils.remove(this, "notificationsounds"); - } - if (!BDFDB.DataUtils.load(this, "observed", BDFDB.UserUtils.me.id)) { - let observed = {}; - let friendsObserved = BDFDB.DataUtils.load(this, "friends"); - let strangersObserved = BDFDB.DataUtils.load(this, "nonfriends"); - if (!BDFDB.ObjectUtils.isEmpty(friendsObserved)) observed.friends = friendsObserved; - if (!BDFDB.ObjectUtils.isEmpty(strangersObserved)) observed.strangers = strangersObserved; - if (observed.friends || observed.strangers) BDFDB.DataUtils.save(observed, this, "observed", BDFDB.UserUtils.me.id); - } - + onStart () { this.startInterval(); - BDFDB.PatchUtils.forceAllUpdates(this); + this.forceUpdateAll(); } onStop () { BDFDB.TimeUtils.clear(checkInterval); + this.forceUpdateAll(); + } + + forceUpdateAll () { + defaultSettings = Object.assign(BDFDB.ObjectUtils.map(statuses, status => notificationTypes[status.value ? "TOAST" : "DISABLED"].value), BDFDB.DataUtils.load(this, "defaultSettings")); BDFDB.PatchUtils.forceAllUpdates(this); } @@ -440,7 +419,7 @@ module.exports = (_ => { size: BDFDB.LibraryComponents.AvatarComponents.Sizes.SIZE_40, onClick: _ => { let observed = this.getObservedData(); - let data = observed[type][cardData.id] || this.createDefaultConfig(); + let data = observed[type][cardData.id] || Object.assign({}, defaultSettings); data.disabled = !data.disabled; observed[type][data.id] = data; BDFDB.DataUtils.save(observed, this, "observed", BDFDB.UserUtils.me.id); @@ -449,7 +428,7 @@ module.exports = (_ => { }, onContextMenu: _ => { let observed = this.getObservedData(); - let data = observed[type][cardData.id] || this.createDefaultConfig(); + let data = observed[type][cardData.id] || Object.assign({}, defaultSettings); let batchType; for (let config in statuses) { if (data[config] == notificationTypes.TOAST.value) batchType = notificationTypes.DESKTOP.value; @@ -475,7 +454,7 @@ module.exports = (_ => { }, onCheckboxChange: (value, instance) => { let observed = this.getObservedData(); - let data = observed[type][instance.props.cardId] || this.createDefaultConfig(); + let data = observed[type][instance.props.cardId] || Object.assign({}, defaultSettings); data[instance.props.settingId] = value; observed[type][instance.props.cardId] = data; BDFDB.DataUtils.save(observed, this, "observed", BDFDB.UserUtils.me.id); @@ -543,6 +522,21 @@ module.exports = (_ => { ] })); + settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { + title: "Default Settings for new Users", + collapseStates: collapseStates, + children: ["disabled"].concat(Object.keys(defaultSettings)).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { + type: "Switch", + label: BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(key), + value: !!defaultSettings[key], + onChange: value => { + defaultSettings[key] = !!statuses[key] ? notificationTypes[value ? "TOAST" : "DISABLED"].value : value; + console.log(defaultSettings); + BDFDB.DataUtils.save(defaultSettings, this, "defaultSettings"); + } + })) + })); + let friendCards = Object.keys(observed.friends).map(BDFDB.LibraryModules.UserStore.getUser).filter(n => n); let strangerCards = Object.keys(observed.strangers).map(BDFDB.LibraryModules.UserStore.getUser).filter(n => n); @@ -561,7 +555,6 @@ module.exports = (_ => { children: [ BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, { children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, { - className: `input-newstranger`, placeholder: "user (id or name#discriminator)", value: "", onChange: value => strangerId = value @@ -576,7 +569,7 @@ module.exports = (_ => { else { let user = /.+#[0-9]{4}/.test(userId) ? BDFDB.LibraryModules.UserStore.findByTag(userId.split("#").slice(0, -1).join("#"), userId.split("#").pop()) : BDFDB.LibraryModules.UserStore.getUser(userId); if (user) { - observed.strangers[user.id || userId] = this.createDefaultConfig(); + observed.strangers[user.id || userId] = Object.assign({}, defaultSettings); BDFDB.DataUtils.save(observed, this, "observed", BDFDB.UserUtils.me.id); BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates); this.SettingsUpdated = true; @@ -723,7 +716,7 @@ module.exports = (_ => { delete this.SettingsUpdated; this.startInterval(); - BDFDB.PatchUtils.forceAllUpdates(this); + this.forceUpdateAll(); } } @@ -768,7 +761,7 @@ module.exports = (_ => { for (let id of friendIds) { let user = BDFDB.LibraryModules.UserStore.getUser(id); if (user) { - observed.friends[id] = Object.assign({}, observed.friends[id] || observed.strangers[id] || this.createDefaultConfig()); + observed.friends[id] = Object.assign({}, observed.friends[id] || observed.strangers[id] || defaultSettings); delete observed.strangers[id]; } } @@ -784,12 +777,6 @@ module.exports = (_ => { return observed; } - createDefaultConfig () { - return Object.assign({ - disabled: this.settings.general.disableForNew - }, BDFDB.ObjectUtils.map(statuses, init => notificationTypes[init ? "TOAST" : "DISABLED"].value)); - } - getStatusWithMobileAndActivity (id, config, clientStatuses) { let status = { name: BDFDB.UserUtils.getStatus(id),