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

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

上级 a6391351
......@@ -89,6 +89,8 @@ export class PuppetMock extends Puppet {
type : MessageType.Text,
text : 'mock text',
timestamp : Date.now(),
fromId : 'xxx',
toId : 'xxx',
})
setInterval(() => {
......
......@@ -365,17 +365,33 @@ export class PuppetPuppeteer extends Puppet {
const type: MessageType = this.messageTypeFromWeb(rawPayload.MsgType)
const payload: MessagePayload = {
const payloadBase = {
id,
type,
fromId,
filename,
toId,
roomId,
text,
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
}
......
......@@ -89,6 +89,7 @@ test('constructor()', async t => {
type : Message.Type.Text,
fromId : EXPECTED.from,
timestamp : Date.now(),
toId : 'toId',
}
return payload
})
......
......@@ -8,15 +8,25 @@ export enum MessageType {
Video,
}
export interface MessagePayload {
export interface MessagePayloadBase {
id : string,
type : MessageType,
filename? : string,
fromId? : string,
roomId? : null | string,
fromId : string,
text? : string,
timestamp : number, // milliseconds
}
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.
先完成此消息的编辑!
想要评论请 注册