Browse Source

Added prevention for the same user being (un)subscribed multiple times

shorten
benji7425 4 years ago
parent
commit
4ea0035479
  1. 16
      feed-bot.js

16
feed-bot.js

@ -136,14 +136,18 @@ var Subscriptions = {
});
},
subscribe: function (userID, user) {
this.subscribers.push(userID);
this.writeToFile();
Log.event("Subscribed user " + (user ? user + "(" + userID + ")" : userID));
if (this.subscribers.indexOf(userID) === -1) {
this.subscribers.push(userID); //subscribe the user if they aren't already subscribed
this.writeToFile();
Log.event("Subscribed user " + (user ? user + "(" + userID + ")" : userID));
}
},
unsubscribe: function (userID, user) {
this.subscribers.splice(this.subscribers.indexOf(userID));
this.writeToFile();
Log.event("Unsubscribed user " + (user ? user + "(" + userID + ")" : userID));
if (this.subscribers.indexOf(userID) > -1) {
this.subscribers.splice(this.subscribers.indexOf(userID));
this.writeToFile();
Log.event("Unsubscribed user " + (user ? user + "(" + userID + ")" : userID));
}
},
writeToFile: function () {
JsonFile.writeFile(Config.subscribersFile, this.subscribers, (err) => { if (err) Log.error("Unable to write subscribers to json file", err); });

Loading…
Cancel
Save