未验证 提交 00e482eb 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓) 提交者: GitHub

Merge pull request #1308 from lijiarui/0612

add room event
...@@ -7,6 +7,9 @@ import test from 'blue-tape' ...@@ -7,6 +7,9 @@ import test from 'blue-tape'
import { import {
PadchatPureFunctionHelper as pfHelper, PadchatPureFunctionHelper as pfHelper,
RoomJoinType,
RoomLeaveType,
RoomTopicType,
} from './pure-function-helper' } from './pure-function-helper'
import { import {
...@@ -315,6 +318,60 @@ test('messageRawPayloadParser', async t => { ...@@ -315,6 +318,60 @@ test('messageRawPayloadParser', async t => {
t.deepEqual(payload, EXPECTED_MESSAGE_PAYLOAD_STATUS_NOTIFY, 'should parse status notify message payload') t.deepEqual(payload, EXPECTED_MESSAGE_PAYLOAD_STATUS_NOTIFY, 'should parse status notify message payload')
}) })
t.test('roomJoinMessageParser', async t => {
const PADCHAT_MESSAGE_PAYLOAD_ROOM_JOIN: PadchatMessagePayload = {
content: '"李卓桓"邀请"Huan LI++"加入了群聊',
continue: 1,
description: '',
from_user: '5354656522@chatroom',
msg_id: '1303222499352704462',
msg_source: '',
msg_type: 5,
status: 1,
sub_type: 10000,
timestamp: 1528657265,
to_user: 'wxid_a8d806dzznm822',
uin: 1211516682,
}
const EXPECTED_MESSAGE_PAYLOAD_ROOM_JOIN: RoomJoinType = {
inviteeNameList: ['Huan LI++'],
inviterName: '李卓桓',
roomId: '5354656522@chatroom',
}
const payload = pfHelper.roomJoinMessageParser(PADCHAT_MESSAGE_PAYLOAD_ROOM_JOIN)
// console.log('payload:', payload)
t.deepEqual(payload, EXPECTED_MESSAGE_PAYLOAD_ROOM_JOIN, 'should parse room join message payload')
})
t.test('roomLeaveMessageParser', async t => {
const PADCHAT_MESSAGE_PAYLOAD_ROOM_LEAVE: PadchatMessagePayload = {
content: '你将"Huan LI++"移出了群聊',
continue: 1,
description: '',
from_user: '5354656522@chatroom',
msg_id: '7593234909679768634',
msg_source: '',
msg_type: 5,
status: 1,
sub_type: 10000,
timestamp: 1528657235,
to_user: 'lizhuohuan',
uin: 4763975,
}
const EXPECTED_MESSAGE_PAYLOAD_ROOM_LEAVE: RoomLeaveType = {
leaverNameList: ['Huan LI++'],
removerName: '',
roomId: '5354656522@chatroom',
}
const payload = pfHelper.roomJoinMessageParser(PADCHAT_MESSAGE_PAYLOAD_ROOM_LEAVE)
// console.log('payload:', payload)
t.deepEqual(payload, EXPECTED_MESSAGE_PAYLOAD_ROOM_LEAVE, 'should parse room leave message payload')
})
}) })
// test('friendRequestRawPayloadParser', async t => { // test('friendRequestRawPayloadParser', async t => {
......
...@@ -41,6 +41,24 @@ import { ...@@ -41,6 +41,24 @@ import {
// PadchatRoomMemberPayload, // PadchatRoomMemberPayload,
} from './padchat-schemas' } from './padchat-schemas'
export interface RoomJoinType {
inviteeNameList : string[],
inviterName : string,
roomId : string,
}
export interface RoomLeaveType {
leaverNameList : string[],
removerName : string,
roomId : string,
}
export interface RoomTopicType {
changeName : string,
topic : string,
roomId : string,
}
export class PadchatPureFunctionHelper { export class PadchatPureFunctionHelper {
private constructor() { private constructor() {
throw new Error('should not be instanciated. use static methods only.') throw new Error('should not be instanciated. use static methods only.')
...@@ -404,6 +422,10 @@ export class PadchatPureFunctionHelper { ...@@ -404,6 +422,10 @@ export class PadchatPureFunctionHelper {
const decodedObject: T = JSON.parse(decodedText) const decodedObject: T = JSON.parse(decodedText)
return decodedObject return decodedObject
} }
public static roomJoinMessageParser(rawPayload: PadchatMessagePayload): RoomJoinType {
const content = rawPayload.content
}
} }
export default PadchatPureFunctionHelper export default PadchatPureFunctionHelper
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册