mirror of https://github.com/calzoneman/sync.git
Add channels.owner_last_seen column
This commit is contained in:
parent
8f266ccd44
commit
9239c2d465
|
@ -2,7 +2,7 @@
|
|||
"author": "Calvin Montgomery",
|
||||
"name": "CyTube",
|
||||
"description": "Online media synchronizer and chat",
|
||||
"version": "3.33.0",
|
||||
"version": "3.34.0",
|
||||
"repository": {
|
||||
"url": "http://github.com/calzoneman/sync"
|
||||
},
|
||||
|
|
|
@ -85,10 +85,11 @@ function Channel(name) {
|
|||
this.refCounter = new ReferenceCounter(this);
|
||||
this.flags = 0;
|
||||
this.id = 0;
|
||||
this.ownerName = null;
|
||||
this.broadcastUsercount = throttle(() => {
|
||||
this.broadcastAll("usercount", this.users.length);
|
||||
}, USERCOUNT_THROTTLE);
|
||||
var self = this;
|
||||
const self = this;
|
||||
db.channels.load(this, function (err) {
|
||||
if (err && err !== "Channel is not registered") {
|
||||
self.emit("loadFail", "Failed to load channel data from the database. Please try again later.");
|
||||
|
@ -397,6 +398,9 @@ Channel.prototype.acceptUser = function (user) {
|
|||
loginStr += " (aliases: " + user.account.aliases.join(",") + ")";
|
||||
self.logger.log(loginStr);
|
||||
self.sendUserJoin(self.users, user);
|
||||
if (user.getName().toLowerCase() === self.ownerName) {
|
||||
db.channels.updateOwnerLastSeen(self.id);
|
||||
}
|
||||
});
|
||||
|
||||
this.users.push(user);
|
||||
|
|
|
@ -274,6 +274,7 @@ module.exports = {
|
|||
chan.name = res[0].name;
|
||||
chan.uniqueName = chan.name.toLowerCase();
|
||||
chan.id = res[0].id;
|
||||
chan.ownerName = typeof res[0].owner === 'string' ? res[0].owner.toLowerCase() : null;
|
||||
chan.setFlag(Flags.C_REGISTERED);
|
||||
chan.logger.log("[init] Loaded channel from database");
|
||||
callback(null, true);
|
||||
|
@ -656,5 +657,20 @@ module.exports = {
|
|||
Logger.errlog.log(`Failed to update last_loaded column for channel ID ${channelId}: ${error}`);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates the `owner_last_seen` column to be the current timestamp
|
||||
*/
|
||||
updateOwnerLastSeen: function updateOwnerLastSeen(channelId) {
|
||||
if (channelId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.query("UPDATE channels SET owner_last_seen = ? WHERE id = ?", [new Date(), channelId], error => {
|
||||
if (error) {
|
||||
Logger.errlog.log(`Failed to update owner_last_seen column for channel ID ${channelId}: ${error}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ var Logger = require("../logger");
|
|||
var Q = require("q");
|
||||
import Promise from 'bluebird';
|
||||
|
||||
const DB_VERSION = 10;
|
||||
const DB_VERSION = 11;
|
||||
var hasUpdates = [];
|
||||
|
||||
module.exports.checkVersion = function () {
|
||||
|
@ -65,6 +65,8 @@ function update(version, cb) {
|
|||
populateUsernameDedupeColumn(cb);
|
||||
} else if (version < 10) {
|
||||
addChannelLastLoadedColumn(cb);
|
||||
} else if (version < 11) {
|
||||
addChannelOwnerLastSeenColumn(cb);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -408,3 +410,21 @@ function addChannelLastLoadedColumn(cb) {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
function addChannelOwnerLastSeenColumn(cb) {
|
||||
db.query("ALTER TABLE channels ADD COLUMN owner_last_seen TIMESTAMP NOT NULL DEFAULT 0", error => {
|
||||
if (error) {
|
||||
Logger.errlog.log(`Failed to add owner_last_seen column: ${error}`);
|
||||
return;
|
||||
}
|
||||
|
||||
db.query("ALTER TABLE channels ADD INDEX i_owner_last_seen (owner_last_seen)", error => {
|
||||
if (error) {
|
||||
Logger.errlog.log(`Failed to add index on owner_last_seen column: ${error}`);
|
||||
return;
|
||||
}
|
||||
|
||||
cb();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue