提交 21b0884b 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

Add Message.age() to return messge age in seconds

上级 b9a35903
......@@ -97,9 +97,8 @@ bot
return
}
const msgAge = Date.now() - msg.date().getTime()
if (msgAge > 1000 * 60) {
log.info('Bot', 'on(message) skip message older(%d) than 60 seconds: %s', Math.floor(msgAge / 1000), msg)
if (msg.age() > 60) {
log.info('Bot', 'on(message) skip message older(%d) than 60 seconds: %s', msg.age(), msg)
return
}
......
......@@ -45,6 +45,7 @@ import {
MessagePayload,
MessageType,
} from './puppet/'
import { Agent } from 'http';
/**
* All wechat messages will be encapsulated as a Message.
*
......@@ -748,6 +749,17 @@ export class Message extends Accessory implements Sayable {
// (from seconds to milliseconds)
return new Date(1000 * this.payload.timestamp)
}
/**
* Message Age:
* in seconds.
*/
public age(): number {
const ageMilliseconds = Date.now() - this.date().getTime()
const ageSeconds = Math.floor(ageMilliseconds / 1000)
return ageSeconds
}
}
export default Message
......@@ -34,6 +34,8 @@ import {
RoomPayload,
RoomMemberPayload,
// RoomQueryFilter,
WATCHDOG_TIMEOUT,
} from '../puppet/'
import {
Puppet,
......@@ -68,6 +70,11 @@ export interface MockRoomRawPayload {
}
export class PuppetMock extends Puppet {
/**
* Watchdog Timeout in Seconds
* if set this value, the parent Puppet class will use it to init watchdog
*/
protected [WATCHDOG_TIMEOUT] = 30
constructor(
public options: PuppetOptions,
......
......@@ -795,9 +795,12 @@ export class Bridge extends PadchatRpc {
* add syncRoomMember task to the queue
*/
this.delayQueueExecutor.execute(
() => this.syncRoomMember(roomId),
() => {
this.syncRoomMember(roomId)
},
'syncRoomMember(' + roomId + ')',
)
log.silly('PuppetPadchatBridge', 'syncContactsAndRooms() added sync room(%s) task to delayQueueExecutor', roomId)
} else if (pfHelper.isContactId(syncContact.user_name)) {
/**
......
......@@ -99,6 +99,7 @@ export abstract class Puppet extends EventEmitter implements Sayable {
/**
* Watchdog Timeout in Seconds
* if set this value, the parent Puppet class will use it to init watchdog
*/
protected [WATCHDOG_TIMEOUT]?: number // Watchdog timeout, in seconds
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册