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

fix typing, and all unit tests are PASSED! :D

上级 a6391351
...@@ -89,6 +89,8 @@ export class PuppetMock extends Puppet { ...@@ -89,6 +89,8 @@ export class PuppetMock extends Puppet {
type : MessageType.Text, type : MessageType.Text,
text : 'mock text', text : 'mock text',
timestamp : Date.now(), timestamp : Date.now(),
fromId : 'xxx',
toId : 'xxx',
}) })
setInterval(() => { setInterval(() => {
......
...@@ -365,17 +365,33 @@ export class PuppetPuppeteer extends Puppet { ...@@ -365,17 +365,33 @@ export class PuppetPuppeteer extends Puppet {
const type: MessageType = this.messageTypeFromWeb(rawPayload.MsgType) const type: MessageType = this.messageTypeFromWeb(rawPayload.MsgType)
const payload: MessagePayload = { const payloadBase = {
id, id,
type, type,
fromId, fromId,
filename, filename,
toId,
roomId,
text, text,
timestamp, timestamp,
} }
let payload: MessagePayload
if (toId) {
payload = {
...payloadBase,
toId,
roomId,
}
} else if (roomId) {
payload = {
...payloadBase,
toId,
roomId,
}
} else {
throw new Error('neither roomId nor toId')
}
return payload return payload
} }
......
...@@ -89,6 +89,7 @@ test('constructor()', async t => { ...@@ -89,6 +89,7 @@ test('constructor()', async t => {
type : Message.Type.Text, type : Message.Type.Text,
fromId : EXPECTED.from, fromId : EXPECTED.from,
timestamp : Date.now(), timestamp : Date.now(),
toId : 'toId',
} }
return payload return payload
}) })
......
...@@ -8,15 +8,25 @@ export enum MessageType { ...@@ -8,15 +8,25 @@ export enum MessageType {
Video, Video,
} }
export interface MessagePayload { export interface MessagePayloadBase {
id : string, id : string,
type : MessageType, type : MessageType,
filename? : string, filename? : string,
fromId? : string, fromId : string,
roomId? : null | string,
text? : string, text? : string,
timestamp : number, // milliseconds timestamp : number, // milliseconds
toId? : null | string, // if to is not set, then room must be set }
export interface MessagePayloadRoom {
roomId : null | string,
toId? : null | string, // if to is not set, then room must be set
} }
export interface MessagePayloadTo {
roomId? : null | string,
toId : null | string, // if to is not set, then room must be set
}
export type MessagePayload = MessagePayloadBase & (MessagePayloadRoom | MessagePayloadTo)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册