fix: updateOwner

if there is another owner don't do anything
if not then make the next user in the room the owner
This commit is contained in:
Barış Soner Uşaklı
2023-07-17 22:49:02 -04:00
parent 91642cb324
commit 16fe1eb98c

View File

@@ -334,14 +334,13 @@ module.exports = function (Messaging) {
async function updateOwner(roomId) {
let nextOwner = await db.getSortedSetRange(`chat:room:${roomId}:owners`, 0, 0);
if (!nextOwner[0]) {
if (!nextOwner.length) {
// no owners left grab next user
nextOwner = await db.getSortedSetRange(`chat:room:${roomId}:uids`, 0, 0);
}
const newOwner = nextOwner[0] || 0;
if (parseInt(newOwner, 10) > 0) {
await db.sortedSetAdd(`chat:room:${roomId}:owners`, Date.now(), newOwner);
const newOwner = nextOwner[0] || 0;
if (parseInt(newOwner, 10) > 0) {
await db.sortedSetAdd(`chat:room:${roomId}:owners`, Date.now(), newOwner);
}
}
}