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

make lint happy

上级 cfed8e63
......@@ -94,6 +94,7 @@
"node": ">= 8.5"
},
"dependencies": {
"array-flatten": "^2.1.1",
"bl": "^2.0.0",
"brolog": "^1.6.3",
"clone-class": "^0.6.11",
......
......@@ -45,7 +45,7 @@ import {
MessagePayload,
MessageType,
} from './puppet/'
import { Agent } from 'http';
/**
* All wechat messages will be encapsulated as a Message.
*
......
......@@ -6,12 +6,12 @@ import test from 'blue-tape'
import { MemoryCard } from 'memory-card'
import { Bridge } from './bridge'
import { PadchatManager } from './padchat-manager'
import {
WECHATY_PUPPET_PADCHAT_ENDPOINT,
} from './config'
class BridgeTest extends Bridge {
class PadchatManagerTest extends PadchatManager {
public async initCache(token: string, selfId: string) {
return super.initCache(
token,
......@@ -29,7 +29,7 @@ test('smoke testing', async t => {
})
test('bridge cache should be release and can be re-init again.', async t => {
const bridge = new BridgeTest({
const bridge = new PadchatManagerTest({
memory : new MemoryCard(),
token : 'mock token',
endpoint : WECHATY_PUPPET_PADCHAT_ENDPOINT,
......@@ -45,7 +45,7 @@ test('bridge cache should be release and can be re-init again.', async t => {
})
test('bridge should can be restart() after a start()', async t => {
const bridge = new Bridge({
const bridge = new PadchatManager({
memory : new MemoryCard(),
token : 'mock token',
endpoint : WECHATY_PUPPET_PADCHAT_ENDPOINT,
......
......@@ -21,7 +21,8 @@ import path from 'path'
// import fs from 'fs'
// import cuid from 'cuid'
import LRU from 'lru-cache'
import LRU from 'lru-cache'
import flatten from 'array-flatten'
import {
FileBox,
......@@ -258,50 +259,7 @@ export class PuppetPadchat extends Puppet {
break
case PadchatMessageType.Sys:
console.log('sys message:', rawPayload)
const roomJoin = roomJoinEventMessageParser(rawPayload)
if (roomJoin) {
const inviteeNameList = roomJoin.inviteeNameList
const inviterName = roomJoin.inviterName
const roomId = roomJoin.roomId
const inviteeIdList = await Promise.all(
inviteeNameList.map(inviteeName => this.roomMemberSearch(roomId, inviteeName))
)
const inviterId = await this.roomMemberSearch(roomId, inviterName)
this.emit('room-join', roomId, inviteeIdList, inviterId)
}
const roomLeave = roomLeaveEventMessageParser(rawPayload)
if (roomLeave) {
const leaverNameList = roomLeave.leaverNameList
const removerName = roomLeave.removerName
const roomId = roomLeave.roomId
const leaverIdList = await Promise.all(
leaverNameList.map(leaverName => this.roomMemberSearch(roomId, leaverName))
)
const removerId = await this.roomMemberSearch(roomId, removerName)
this.emit('room-leave', roomId, leaverIdList, removerId)
}
const roomTopic = roomTopicEventMessageParser(rawPayload)
if (roomTopic) {
const changerName = roomTopic.changerName
const newTopic = roomTopic.topic
const roomId = roomTopic.roomId
const roomPayload = await this.roomPayload(roomId)
const oldTopic = roomPayload.topic
const changerId = await this.roomMemberSearch(roomId, changerName)
this.emit('room-topic', roomId, newTopic, oldTopic, changerId)
}
await this.onPadchatMessageSys(rawPayload)
break
case PadchatMessageType.App:
......@@ -322,6 +280,84 @@ export class PuppetPadchat extends Puppet {
}
}
protected async onPadchatMessageSys(rawPayload: PadchatMessagePayload) {
log.verbose('PuppetPadchat', 'onPadchatMessageSys({id=%s})')
/**
* 1. Look for room join event
*/
const roomJoin = roomJoinEventMessageParser(rawPayload)
if (roomJoin) {
const inviteeNameList = roomJoin.inviteeNameList
const inviterName = roomJoin.inviterName
const roomId = roomJoin.roomId
const inviteeIdList = flatten<string>(
await Promise.all(
inviteeNameList.map(
inviteeName => this.roomMemberSearch(roomId, inviteeName),
),
),
)
const inviterIdList = await this.roomMemberSearch(roomId, inviterName)
if (inviterIdList.length < 1) {
throw new Error('no inviterId found')
} else if (inviterIdList.length > 1) {
log.warn('PuppetPadchat', 'onPadchatMessage() case PadchatMesssageSys: inviterId found more than 1, use the first one.')
}
const inviterId = inviterIdList[0]
this.emit('room-join', roomId, inviteeIdList, inviterId)
}
/**
* 2. Look for room leave event
*/
const roomLeave = roomLeaveEventMessageParser(rawPayload)
if (roomLeave) {
const leaverNameList = roomLeave.leaverNameList
const removerName = roomLeave.removerName
const roomId = roomLeave.roomId
const leaverIdList = flatten<string>(
await Promise.all(
leaverNameList.map(
leaverName => this.roomMemberSearch(roomId, leaverName),
),
),
)
const removerIdList = await this.roomMemberSearch(roomId, removerName)
if (removerIdList.length < 1) {
throw new Error('no removerId found')
} else if (removerIdList.length > 1) {
log.warn('PuppetPadchat', 'onPadchatMessage() case PadchatMesssageSys: removerId found more than 1, use the first one.')
}
const removerId = removerIdList[0]
this.emit('room-leave', roomId, leaverIdList, removerId)
}
/**
* 3. Look for room topic event
*/
const roomTopic = roomTopicEventMessageParser(rawPayload)
if (roomTopic) {
const changerName = roomTopic.changerName
const newTopic = roomTopic.topic
const roomId = roomTopic.roomId
const roomPayload = await this.roomPayload(roomId)
const oldTopic = roomPayload.topic
const changerIdList = await this.roomMemberSearch(roomId, changerName)
if (changerIdList.length < 1) {
throw new Error('no changerId found')
} else if (changerIdList.length > 1) {
log.warn('PuppetPadchat', 'onPadchatMessage() case PadchatMesssageSys: changerId found more than 1, use the first one.')
}
const changerId = changerIdList[0]
this.emit('room-topic', roomId, newTopic, oldTopic, changerId)
}
}
public async stop(): Promise<void> {
log.verbose('PuppetPadchat', 'stop()')
......
......@@ -5,4 +5,6 @@
import test from 'blue-tape'
// test('xx)
test('smoke testing', async t => {
t.skip('tbw')
})
import { PadchatMessagePayload } from '../padchat-schemas'
export function friendRequestEventMessageParser(rawPayload: PadchatMessagePayload) {
return rawPayload
// // const reList = regexConfig.friendConfirm
// // let found = false
......
......@@ -7,7 +7,7 @@ import test from 'blue-tape'
import { padchatDecode } from './padchat-decode'
t.test('padchatDecode() uri decode with +', async t => {
test('padchatDecode() uri decode with +', async t => {
const JSON_TEXT = '%7B%22big_head%22%3A%22http%3A%2F%2Fwx.qlogo.cn%2Fmmhead%2FP3UGRtJrgyEMkmOExtdq1xpGcic2z1b5wZuicFibfHNPnYttF9n9ZzE2Q%2F0%22%2C%22bit_mask%22%3A4294967295%2C%22bit_value%22%3A2051%2C%22chatroom_id%22%3A0%2C%22chatroom_owner%22%3A%22%22%2C%22city%22%3A%22San+Francisco%22%2C%22continue%22%3A1%2C%22country%22%3A%22US%22%2C%22id%22%3A0%2C%22img_flag%22%3A1%2C%22intro%22%3A%22%22%2C%22label%22%3A%22%22%2C%22level%22%3A7%2C%22max_member_count%22%3A0%2C%22member_count%22%3A0%2C%22msg_type%22%3A2%2C%22nick_name%22%3A%22Huan+LI%2B%2B%22%2C%22provincia%22%3A%22California%22%2C%22py_initial%22%3A%22HUANLI%22%2C%22quan_pin%22%3A%22HuanLI%22%2C%22remark%22%3A%22%22%2C%22remark_py_initial%22%3A%22%22%2C%22remark_quan_pin%22%3A%22%22%2C%22sex%22%3A1%2C%22signature%22%3A%22angel+invester%2C+serial+entrepreneur+with+tech+background.%22%2C%22small_head%22%3A%22http%3A%2F%2Fwx.qlogo.cn%2Fmmhead%2FP3UGRtJrgyEMkmOExtdq1xpGcic2z1b5wZuicFibfHNPnYttF9n9ZzE2Q%2F132%22%2C%22source%22%3A14%2C%22status%22%3A1%2C%22stranger%22%3A%22v1_7f8c54ac5a1b1bcec9a7ccfae9b0a9564373a1559d2e545d2d2b5a3708e61928b2fc43c009b7512a75d53b312422d6e6%40stranger%22%2C%22uin%22%3A1211516682%2C%22user_name%22%3A%22wxid_5zj4i5htp9ih22%22%7D'
const EXPECTED_OBJ = { big_head: 'http://wx.qlogo.cn/mmhead/P3UGRtJrgyEMkmOExtdq1xpGcic2z1b5wZuicFibfHNPnYttF9n9ZzE2Q/0', bit_mask: 4294967295, bit_value: 2051, chatroom_id: 0, chatroom_owner: '', city: 'San Francisco', continue: 1, country: 'US', id: 0, img_flag: 1, intro: '', label: '', level: 7, max_member_count: 0, member_count: 0, msg_type: 2, nick_name: 'Huan LI++', provincia: 'California', py_initial: 'HUANLI', quan_pin: 'HuanLI', remark: '', remark_py_initial: '', remark_quan_pin: '', sex: 1, signature: 'angel invester, serial entrepreneur with tech background.', small_head: 'http://wx.qlogo.cn/mmhead/P3UGRtJrgyEMkmOExtdq1xpGcic2z1b5wZuicFibfHNPnYttF9n9ZzE2Q/132', source: 14, status: 1, stranger: 'v1_7f8c54ac5a1b1bcec9a7ccfae9b0a9564373a1559d2e545d2d2b5a3708e61928b2fc43c009b7512a75d53b312422d6e6@stranger', uin: 1211516682, user_name: 'wxid_5zj4i5htp9ih22' }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册