mx-puppet-bridge
Advanced tools
Comparing version 0.0.43-3 to 0.0.43-4
@@ -25,2 +25,5 @@ "use strict"; | ||
const log_1 = require("./log"); | ||
// tslint:disable no-magic-numbers | ||
const PRESENCE_SYNC_TIMEOUT = 1000 * 25; // synapse has a timeout of 30s, an extra 5s gives some slack | ||
// tslint:enable no-magic-numbers | ||
const log = new log_1.Log("PresenceHandler"); | ||
@@ -69,2 +72,3 @@ class PresenceHandler { | ||
presence, | ||
last_sent: Date.now(), | ||
}; | ||
@@ -78,2 +82,3 @@ this.presenceQueue.push(p); | ||
this.presenceQueue[index].presence = presence; | ||
this.presenceQueue[index].last_sent = Date.now(); | ||
// do this async in the BG for live updates | ||
@@ -94,2 +99,3 @@ // tslint:disable-next-line:no-floating-promises | ||
status, | ||
last_sent: Date.now(), | ||
}; | ||
@@ -105,2 +111,3 @@ this.presenceQueue.push(p); | ||
this.presenceQueue[index].status = status; | ||
this.presenceQueue[index].last_sent = Date.now(); | ||
// do this async in the BG for live updates | ||
@@ -138,8 +145,16 @@ // tslint:disable-next-line:no-floating-promises | ||
if (info) { | ||
yield this.setMatrixPresence(info); | ||
if (info.presence !== "offline") { | ||
this.presenceQueue.push(info); | ||
const now = Date.now(); | ||
if ((now - info.last_sent) > PRESENCE_SYNC_TIMEOUT) { | ||
yield this.setMatrixPresence(info); | ||
if (info.presence !== "offline") { | ||
info.last_sent = now; | ||
this.presenceQueue.push(info); | ||
} | ||
else { | ||
log.verbose(`Dropping ${info.mxid} from the presence queue.`); | ||
} | ||
} | ||
else { | ||
log.verbose(`Dropping ${info.mxid} from the presence queue.`); | ||
this.presenceQueue.push(info); | ||
log.silly(`Not updating presence for ${info.mxid}, still fresh enough`); | ||
} | ||
@@ -146,0 +161,0 @@ } |
{ | ||
"name": "mx-puppet-bridge", | ||
"version": "0.0.43-3", | ||
"version": "0.0.43-4", | ||
"description": "Matrix Puppeting Bridge library", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -18,2 +18,6 @@ /* | ||
// tslint:disable no-magic-numbers | ||
const PRESENCE_SYNC_TIMEOUT = 1000 * 25; // synapse has a timeout of 30s, an extra 5s gives some slack | ||
// tslint:enable no-magic-numbers | ||
const log = new Log("PresenceHandler"); | ||
@@ -27,2 +31,3 @@ | ||
status?: string; | ||
last_sent: number; | ||
} | ||
@@ -83,2 +88,3 @@ | ||
presence, | ||
last_sent: Date.now(), | ||
}; | ||
@@ -91,2 +97,3 @@ this.presenceQueue.push(p); | ||
this.presenceQueue[index].presence = presence; | ||
this.presenceQueue[index].last_sent = Date.now(); | ||
// do this async in the BG for live updates | ||
@@ -108,2 +115,3 @@ // tslint:disable-next-line:no-floating-promises | ||
status, | ||
last_sent: Date.now(), | ||
}; | ||
@@ -118,2 +126,3 @@ this.presenceQueue.push(p); | ||
this.presenceQueue[index].status = status; | ||
this.presenceQueue[index].last_sent = Date.now(); | ||
// do this async in the BG for live updates | ||
@@ -155,7 +164,14 @@ // tslint:disable-next-line:no-floating-promises | ||
if (info) { | ||
await this.setMatrixPresence(info); | ||
if (info.presence !== "offline") { | ||
const now = Date.now(); | ||
if ((now - info.last_sent) > PRESENCE_SYNC_TIMEOUT) { | ||
await this.setMatrixPresence(info); | ||
if (info.presence !== "offline") { | ||
info.last_sent = now; | ||
this.presenceQueue.push(info); | ||
} else { | ||
log.verbose(`Dropping ${info.mxid} from the presence queue.`); | ||
} | ||
} else { | ||
this.presenceQueue.push(info); | ||
} else { | ||
log.verbose(`Dropping ${info.mxid} from the presence queue.`); | ||
log.silly(`Not updating presence for ${info.mxid}, still fresh enough`); | ||
} | ||
@@ -162,0 +178,0 @@ } |
826300
21157