`;
for (let key in amounts) {
@@ -142,7 +148,9 @@ class StalkerNotifications {
for (let key in settings) {
settingshtml += `
`;
+ for (let key in notificationsounds) {
+ if (key.indexOf("desktop") == -1 || "Notification" in window) settingshtml += `
`;
@@ -161,11 +169,12 @@ class StalkerNotifications {
$(settingspanel)
.on("click", ".settings-checkbox", () => {this.updateSettings(settingspanel);})
- .on("click", ".btn-savesong", () => {this.saveAudio(settingspanel);})
+ .on("click", ".btn-savesong", (e) => {this.saveAudio(settingspanel, e.currentTarget.getAttribute("option"));})
.on("click", ".mute-checkbox", (e) => {
- var notificationsound = BDFDB.loadAllData(this, "notificationsound");
+ var option = e.currentTarget.getAttribute("option");
+ var notificationsound = BDFDB.getData(option, this, "notificationsounds");
notificationsound.mute = e.currentTarget.checked;
- BDFDB.saveAllData(notificationsound, this, "notificationsound");
+ BDFDB.saveData(option, notificationsound, this, "notificationsounds");
})
.on("mouseenter", ".settings-avatar", (e) => {
let user = this.UserUtils.getUser(e.currentTarget.getAttribute("user-id"));
@@ -269,6 +278,15 @@ class StalkerNotifications {
if (typeof BDFDB === "object") {
BDFDB.loadMessage(this);
+ var notificationsound = BDFDB.loadAllData(this, "notificationsound");
+ if (!BDFDB.isObjectEmpty(notificationsound)) {
+ var data = {};
+ data.desktoponline = notificationsound;
+ data.desktopoffline = notificationsound;
+ BDFDB.saveAllData(data, this, "notificationsounds");
+ BDFDB.removeAllData(this, "notificationsound");
+ }
+
this.ChannelUtils = BDFDB.WebModules.findByProperties(["getDMFromUserId"]);
this.ChannelSwitchUtils = BDFDB.WebModules.findByProperties(["selectPrivateChannel"]);
this.PrivateChannelUtils = BDFDB.WebModules.findByProperties(["openPrivateChannel"]);
@@ -298,67 +316,24 @@ class StalkerNotifications {
updateSettings (settingspanel) {
var settings = {};
- for (var input of settingspanel.querySelectorAll(BDFDB.dotCN.switchinner)) {
+ for (var input of settingspanel.querySelectorAll(BDFDB.dotCN.switchinner + ".settings-checkbox")) {
settings[input.value] = input.checked;
}
BDFDB.saveAllData(settings, this, "settings");
}
- createSettingsAvatarHtml (user, settings) {
- let data = BDFDB.loadData(user.id, "EditUsers", "users") || {};
- return `
`;
- }
-
- startInterval () {
- clearInterval(this.checkInterval);
- this.checkInterval = setInterval(() => {
- let settings = BDFDB.getAllData(this, "settings");
- let notificationsound = BDFDB.loadAllData(this, "notificationsound");
- let users = BDFDB.loadAllData(this, "users");
- for (let id in users) {
- let online = this.UserMetaStore.getStatus(id) != "offline";
- let user = this.UserUtils.getUser(id);
- if (user && this.stalkerOnlineList[id] != online && !users[id].disabled) {
- this.timeLog.push({user, online, time: new Date()});
- if (!(settings.onlyOnOnline && !online) && !(settings.muteOnDND && BDFDB.getUserStatus() == "dnd")) {
- let data = BDFDB.loadData(user.id, "EditUsers", "users") || {};
- let string = `${BDFDB.encodeToHTML(data.name ? data.name : user.username)} is ${online ? "online" : "offline"}.`;
- let avatar = data.removeIcon ? "" : (data.url ? data.url : BDFDB.getUserAvatar(user.id));
- let openChannel = () => {
- if (settings.openOnClick) {
- let DMid = this.ChannelStore.getDMFromUserId(user.id)
- if (DMid) this.ChannelSwitchUtils.selectPrivateChannel(DMid);
- else this.PrivateChannelUtils.openPrivateChannel(BDFDB.myData.id, user.id);
- require("electron").remote.getCurrentWindow().maximize();
- }
- };
- if (!users[id].desktop) {
- let toast = BDFDB.showToast(`
`, {html:true, timeout:5000, type:(online ? "success" : null), icon:false});
- $(toast).on("click." + this.getName(), openChannel);
- }
- else {
- let notificationsound = BDFDB.loadAllData(this, "notificationsound");
- BDFDB.showDesktopNotification(string, {icon:avatar, timeout:5000, click:openChannel, silent:notificationsound.mute, sound:notificationsound.song});
- }
- }
- }
- this.stalkerOnlineList[id] = online;
- }
- },BDFDB.getData("checkInterval", this, "amounts") * 1000);
- }
-
- saveAudio (settingspanel) {
+ saveAudio (settingspanel, option) {
var successSavedAudio = (parsedurl, parseddata) => {
if (parsedurl && parseddata) BDFDB.showToast(`Sound was saved successfully.`, {type:"success"});
- let notificationsound = BDFDB.loadAllData(this, "notificationsound");
+ let notificationsound = BDFDB.getData(option, this, "notificationsounds");
notificationsound.url = parsedurl;
notificationsound.song = parseddata;
- BDFDB.saveAllData(notificationsound, this, "notificationsound");
+ BDFDB.saveData(option, notificationsound, this, "notificationsounds");
};
- var url = settingspanel.querySelector(".songInput").value;
+ var url = settingspanel.querySelector(`.songInput[option="${option}"]`).value;
if (url.length == 0) {
- BDFDB.showToast(`Sound was set to the default sound.`, {type:"warn"});
+ BDFDB.showToast(`Sound file was removed.`, {type:"warn"});
successSavedAudio(url, url);
}
else if (url.indexOf("http") == 0) {
@@ -385,6 +360,54 @@ class StalkerNotifications {
}
}
+ createSettingsAvatarHtml (user, settings) {
+ let data = BDFDB.loadData(user.id, "EditUsers", "users") || {};
+ return `
`;
+ }
+
+ startInterval () {
+ clearInterval(this.checkInterval);
+ this.checkInterval = setInterval(() => {
+ let settings = BDFDB.getAllData(this, "settings");
+ let users = BDFDB.loadAllData(this, "users");
+ for (let id in users) {
+ let online = this.UserMetaStore.getStatus(id) != "offline";
+ let user = this.UserUtils.getUser(id);
+ if (user && this.friendsOnlineList[id] != online && !BDFDB.loadData(id, this, "disabled")) {
+ this.timeLog.push({user, online, time: new Date()});
+ if (!(settings.onlyOnOnline && !online) && !(settings.muteOnDND && BDFDB.getUserStatus() == "dnd")) {
+ let data = BDFDB.loadData(user.id, "EditUsers", "users") || {};
+ let string = `${BDFDB.encodeToHTML(data.name ? data.name : user.username)} is ${online ? "online" : "offline"}.`;
+ let avatar = data.removeIcon ? "" : (data.url ? data.url : BDFDB.getUserAvatar(user.id));
+ let openChannel = () => {
+ if (settings.openOnClick) {
+ let DMid = this.ChannelUtils.getDMFromUserId(user.id)
+ if (DMid) this.ChannelSwitchUtils.selectPrivateChannel(DMid);
+ else this.PrivateChannelUtils.openPrivateChannel(BDFDB.myData.id, user.id);
+ require("electron").remote.getCurrentWindow().maximize();
+ }
+ };
+ if (!BDFDB.loadData(id, this, "desktop")) {
+ let toast = BDFDB.showToast(`
`, {html:true, timeout:5000, type:(online ? "success" : null), icon:false});
+ $(toast).on("click." + this.getName(), openChannel);
+ let notificationsound = BDFDB.getData(online ? "toastonline" : "toastoffline", this, "notificationsounds");
+ if (!notificationsound.mute && notificationsound.song) {
+ var audio = new Audio();
+ audio.src = notificationsound.song;
+ audio.play();
+ }
+ }
+ else {
+ let notificationsound = BDFDB.getData(online ? "desktoponline" : "desktopoffline", this, "notificationsounds");
+ BDFDB.showDesktopNotification(string, {icon:avatar, timeout:5000, click:openChannel, silent:notificationsound.mute, sound:notificationsound.song});
+ }
+ }
+ }
+ this.stalkerOnlineList[id] = online;
+ }
+ },BDFDB.getData("checkInterval", this, "amounts") * 1000);
+ }
+
showTimeLog () {
var timeLogModal = $(this.timeLogModalMarkup);
let logs = this.timeLog.slice(0).reverse();