parent
f4739ad500
commit
d8be801b3b
|
@ -56,12 +56,33 @@ class PPfunMatrixBridge {
|
||||||
const arr = Array.from(this.echoSuppression);
|
const arr = Array.from(this.echoSuppression);
|
||||||
for (let i = 0; i < arr.length; i += 1) {
|
for (let i = 0; i < arr.length; i += 1) {
|
||||||
const [key, value] = arr[i];
|
const [key, value] = arr[i];
|
||||||
if (curTime - 30000 > value) {
|
if (curTime - 60000 > value[1]) {
|
||||||
this.echoSuppression.delete(key);
|
this.echoSuppression.delete(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addToEchoSuppression(uid, cid) {
|
||||||
|
const key = `${uid}:${cid}`;
|
||||||
|
const curTime = Date.now();
|
||||||
|
const uidMsgs = this.echoSuppression.get(key);
|
||||||
|
if (!uidMsgs) {
|
||||||
|
this.echoSuppression.set(key, [1, curTime]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uidMsgs[0] += 1;
|
||||||
|
uidMsgs[1] = curTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkEchoSuppression(uid, cid) {
|
||||||
|
const uidMsgs = this.echoSuppression.get(`${uid}:${cid}`);
|
||||||
|
if (uidMsgs && uidMsgs[0] > 0) {
|
||||||
|
uidMsgs[0] -= 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
recPPfun(name, uid, msg, cid) {
|
recPPfun(name, uid, msg, cid) {
|
||||||
const matrixRoom = this.pToMroomMap.get(cid);
|
const matrixRoom = this.pToMroomMap.get(cid);
|
||||||
if (!matrixRoom) {
|
if (!matrixRoom) {
|
||||||
|
@ -73,7 +94,7 @@ class PPfunMatrixBridge {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const parsedMsg = parseMsg(msg);
|
const parsedMsg = parseMsg(msg);
|
||||||
this.echoSuppression.set(`${uid}:${cid}`, Date.now());
|
this.addToEchoSuppression(uid, cid);
|
||||||
console.log(`PPFUN ${name}: ${parsedMsg}`);
|
console.log(`PPFUN ${name}: ${parsedMsg}`);
|
||||||
this.sendMatrix(
|
this.sendMatrix(
|
||||||
name,
|
name,
|
||||||
|
@ -158,7 +179,7 @@ class PPfunMatrixBridge {
|
||||||
&& userId.endsWith(this.domain))
|
&& userId.endsWith(this.domain))
|
||||||
? userId.slice(2 + this.prefix.length, -this.domain.length - 1)
|
? userId.slice(2 + this.prefix.length, -this.domain.length - 1)
|
||||||
: null;
|
: null;
|
||||||
if (this.echoSuppression.delete(`${uid}:${cid}`)) {
|
if (this.checkEchoSuppression(uid, cid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let name = this.idToNameMap.get(userId);
|
let name = this.idToNameMap.get(userId);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user