Update FriendNotifications.plugin.js
This commit is contained in:
parent
ec9c242496
commit
e2872eba91
|
@ -2,7 +2,7 @@
|
|||
* @name FriendNotifications
|
||||
* @author DevilBro
|
||||
* @authorId 278543574059057154
|
||||
* @version 1.7.6
|
||||
* @version 1.7.7
|
||||
* @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,13 @@ module.exports = (_ => {
|
|||
"info": {
|
||||
"name": "FriendNotifications",
|
||||
"author": "DevilBro",
|
||||
"version": "1.7.6",
|
||||
"version": "1.7.7",
|
||||
"description": "Shows a Notification when a Friend or a User, you choose to observe, changes their Status"
|
||||
},
|
||||
"changeLog": {
|
||||
"fixed": {
|
||||
"Crash": ""
|
||||
"added": {
|
||||
"Time Log Option": "You can now disable the time log for users, in case you only want the time log for your important friends",
|
||||
"Log In Option": "You can now enable the login option, this will notify you in case a user changed his status from offline to any other status (so enabling only offline and login will only notify you about logout and logins, no notifications about status changes from example online to dnd)"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -116,6 +117,9 @@ module.exports = (_ => {
|
|||
name: "STATUS_OFFLINE",
|
||||
sound: true
|
||||
},
|
||||
login: {
|
||||
value: false
|
||||
},
|
||||
mobile: {
|
||||
value: false
|
||||
},
|
||||
|
@ -227,6 +231,7 @@ module.exports = (_ => {
|
|||
listening: {value: "$user started listening to '$song'"},
|
||||
streaming: {value: "$user started streaming '$game'"},
|
||||
offline: {value: "$user changed status to '$status'"},
|
||||
login: {value: "$user just logged in '$status'"},
|
||||
custom: {value: "$user changed status to '$custom'"}
|
||||
},
|
||||
notificationSounds: {},
|
||||
|
@ -291,7 +296,7 @@ module.exports = (_ => {
|
|||
}
|
||||
|
||||
forceUpdateAll () {
|
||||
defaultSettings = Object.assign(BDFDB.ObjectUtils.map(statuses, status => notificationTypes[status.value ? "TOAST" : "DISABLED"].value), BDFDB.DataUtils.load(this, "defaultSettings"));
|
||||
defaultSettings = Object.assign(BDFDB.ObjectUtils.map(statuses, status => notificationTypes[status.value ? "TOAST" : "DISABLED"].value), {timelog: true}, BDFDB.DataUtils.load(this, "defaultSettings"));
|
||||
BDFDB.PatchUtils.forceAllUpdates(this);
|
||||
}
|
||||
|
||||
|
@ -301,7 +306,12 @@ module.exports = (_ => {
|
|||
let specificObserved = observed[type] || {};
|
||||
if (config == "all") {
|
||||
config = "disabled";
|
||||
for (let id in specificObserved) specificObserved[id][config] = notificationTypes[notificationType].button == 0 ? false : true;
|
||||
const value = notificationTypes[notificationType].button == 0 ? false : true;
|
||||
for (let id in specificObserved) specificObserved[id][config] = value;
|
||||
}
|
||||
else if (config == "timelog") {
|
||||
const value = notificationType == "TOAST" ? notificationTypes.TOAST.value : notificationTypes.DISABLED.value;
|
||||
for (let id in specificObserved) specificObserved[id][config] = value;
|
||||
}
|
||||
else {
|
||||
let disabled = BDFDB.ObjectUtils.toArray(specificObserved).every(d => !d.disabled && d[config] == notificationTypes[notificationType].value);
|
||||
|
@ -395,21 +405,26 @@ module.exports = (_ => {
|
|||
items.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, {
|
||||
className: BDFDB.disCN.margintop20,
|
||||
title: "all",
|
||||
settings: Object.keys(statuses),
|
||||
settings: Object.keys(statuses).concat("timelog"),
|
||||
data: users,
|
||||
pagination: {
|
||||
alphabetKey: "username",
|
||||
amount: 50,
|
||||
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;
|
||||
getCheckboxValue: (value, event, instance) => {
|
||||
if (instance && instance.props.settingId == "timelog") {
|
||||
return value == notificationTypes.DISABLED.value ? notificationTypes.TOAST.value : notificationTypes.DISABLED.value;
|
||||
}
|
||||
else {
|
||||
let eventValue = (BDFDB.ObjectUtils.toArray(notificationTypes).find(n => n.button == event.button) || {}).value;
|
||||
return eventValue == value ? 0 : eventValue;
|
||||
}
|
||||
},
|
||||
renderLabel: cardData => [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.AvatarComponents.default, {
|
||||
|
@ -531,7 +546,6 @@ module.exports = (_ => {
|
|||
value: !!defaultSettings[key],
|
||||
onChange: value => {
|
||||
defaultSettings[key] = !!statuses[key] ? notificationTypes[value ? "TOAST" : "DISABLED"].value : value;
|
||||
console.log(defaultSettings);
|
||||
BDFDB.DataUtils.save(defaultSettings, this, "defaultSettings");
|
||||
}
|
||||
}))
|
||||
|
@ -701,7 +715,7 @@ module.exports = (_ => {
|
|||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
|
||||
type: "Button",
|
||||
label: "Overview of LogIns/-Outs of current Session",
|
||||
onClick: _ => {this.showTimeLog()},
|
||||
onClick: _ => this.showTimeLog(),
|
||||
children: "Timelog"
|
||||
})
|
||||
}));
|
||||
|
@ -761,7 +775,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] || defaultSettings);
|
||||
observed.friends[id] = Object.assign({}, defaultSettings, observed.friends[id] || observed.strangers[id]);
|
||||
delete observed.strangers[id];
|
||||
}
|
||||
}
|
||||
|
@ -834,8 +848,8 @@ module.exports = (_ => {
|
|||
for (let id in observedUsers) if (!observedUsers[id].disabled) {
|
||||
let user = BDFDB.LibraryModules.UserStore.getUser(id);
|
||||
let status = this.getStatusWithMobileAndActivity(id, observedUsers[id], clientStatuses);
|
||||
let customChanged = false;
|
||||
if (user && observedUsers[id][status.name] && (
|
||||
let customChanged = false, loginNotice = false;
|
||||
if (user && (!observedUsers[id][status.name] && observedUsers[id].login && status.name != "offline" && userStatusStore[id].name == "offline" && (loginNotice = true) || observedUsers[id][status.name] && (
|
||||
observedUsers[id].custom && (
|
||||
userStatusStore[id].custom != status.custom && ((customChanged = status.custom) || true) ||
|
||||
(customChanged = status.custom && !this.activityIsSame(id, status))
|
||||
|
@ -843,7 +857,7 @@ module.exports = (_ => {
|
|||
observedUsers[id].mobile && userStatusStore[id].mobile != status.mobile ||
|
||||
statuses[status.name].checkActivity && !this.activityIsSame(id, status) ||
|
||||
userStatusStore[id].name != status.name
|
||||
)) {
|
||||
))) {
|
||||
let EUdata = BDFDB.BDUtils.isPluginEnabled("EditUsers") && BDFDB.DataUtils.load("EditUsers", "users", user.id) || {};
|
||||
let name = EUdata.name || user.username;
|
||||
let avatar = EUdata.removeIcon ? "" : (EUdata.url || BDFDB.UserUtils.getAvatar(user.id));
|
||||
|
@ -852,12 +866,12 @@ module.exports = (_ => {
|
|||
let statusName = this.getStatusName(id, status);
|
||||
let oldStatusName = this.getStatusName(id, userStatusStore[id]);
|
||||
|
||||
let string = this.settings.notificationStrings[customChanged ? "custom" : status.name] || "'$user' changed status to '$status'";
|
||||
let string = this.settings.notificationStrings[customChanged ? "custom" : loginNotice ? "login" : status.name] || "'$user' changed status to '$status'";
|
||||
let toastString = BDFDB.StringUtils.htmlEscape(string).replace(/'{0,1}\$user'{0,1}/g, `<strong>${BDFDB.StringUtils.htmlEscape(name)}</strong>${this.settings.general.showDiscriminator ? ("#" + user.discriminator) : ""}`).replace(/'{0,1}\$statusOld'{0,1}/g, `<strong>${oldStatusName}</strong>`).replace(/'{0,1}\$status'{0,1}/g, `<strong>${statusName}</strong>`);
|
||||
if (status.activity) toastString = toastString.replace(/'{0,1}\$song'{0,1}|'{0,1}\$game'{0,1}/g, `<strong>${status.activity.name || status.activity.details || ""}</strong>`).replace(/'{0,1}\$artist'{0,1}|'{0,1}\$custom'{0,1}/g, `<strong>${[status.activity.emoji && status.activity.emoji.name, status.activity.state].filter(n => n).join(" ") || ""}</strong>`);
|
||||
|
||||
let statusType = BDFDB.UserUtils.getStatus(user.id);
|
||||
timeLog.unshift({
|
||||
if (observedUsers[id].timelog == undefined || observedUsers[id].timelog) timeLog.unshift({
|
||||
string: toastString,
|
||||
avatar: avatar,
|
||||
name: name,
|
||||
|
|
Loading…
Reference in New Issue