Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
type = MessageType.Audio
// console.log(rawPayload)
break
case PadchatMessageType.Emoticon:
type = MessageType.Emoticon
// console.log(rawPayload)
break
case PadchatMessageType.App:
type = MessageType.Attachment
// console.log(rawPayload)
break
case PadchatMessageType.Video:
type = MessageType.Video
// console.log(rawPayload)
break
case PadchatMessageType.Sys:
type = MessageType.Unknown
break
case PadchatMessageType.ShareCard:
type = MessageType.Contact
break
case PadchatMessageType.Recalled:
case PadchatMessageType.StatusNotify:
case PadchatMessageType.SysNotice:
type = MessageType.Unknown
break
type = MessageType.Emoticon
// console.log(rawPayload)
break
case PadplusMessageType.App:
type = MessageType.Attachment
// console.log(rawPayload)
break
case PadplusMessageType.Location:
type = MessageType.Location
// console.log(rawPayload)
break
case PadplusMessageType.Video:
type = MessageType.Video
// console.log(rawPayload)
break
case PadplusMessageType.Sys:
type = MessageType.Unknown
break
case PadplusMessageType.ShareCard:
type = MessageType.Contact
break
case PadplusMessageType.VoipMsg:
case PadplusMessageType.Recalled:
type = MessageType.Recalled
break
const type = messageType(rawPayload.sub_type)
const payloadBase = {
id : rawPayload.msg_id,
timestamp : rawPayload.timestamp, // Padchat message timestamp is seconds
type : type,
} as {
id : string,
timestamp : number,
type : MessageType,
filename? : string,
}
if ( type === MessageType.Image
|| type === MessageType.Audio
|| type === MessageType.Video
|| type === MessageType.Attachment
) {
payloadBase.filename = messageFileName(rawPayload) || undefined
}
let fromId: undefined | string = undefined
let roomId: undefined | string = undefined
let toId: undefined | string = undefined
let text: undefined | string = undefined
/**
* 1. Set Room Id
*/
if (isRoomId(rawPayload.from_user)) {
roomId = rawPayload.from_user
export function webMessageType(webMsgType: WebMessageType): MessageType {
switch (webMsgType) {
case WebMessageType.TEXT:
return MessageType.Text
case WebMessageType.EMOTICON:
case WebMessageType.IMAGE:
return MessageType.Image
case WebMessageType.VOICE:
return MessageType.Audio
case WebMessageType.MICROVIDEO:
case WebMessageType.VIDEO:
return MessageType.Video
case WebMessageType.TEXT:
return MessageType.Text
/**
* Treat those Types as TEXT
*
* Friendship is a SYS message
* FIXME: should we use better message type at here???
*/
case WebMessageType.SYS:
case WebMessageType.APP:
return MessageType.Text
// VERIFYMSG = 37,
// POSSIBLEFRIEND_MSG = 40,
rawPayload: WebMessageRawPayload,
): MessageType {
switch (rawPayload.MsgType) {
case WebMessageType.TEXT:
return MessageType.Text
case WebMessageType.EMOTICON:
case WebMessageType.IMAGE:
return MessageType.Image
case WebMessageType.VOICE:
return MessageType.Audio
case WebMessageType.MICROVIDEO:
case WebMessageType.VIDEO:
return MessageType.Video
case WebMessageType.TEXT:
return MessageType.Text
/**
* Treat those Types as TEXT
*
* FriendRequest is a SYS message
* FIXME: should we use better message type at here???
*/
case WebMessageType.SYS:
case WebMessageType.APP:
return MessageType.Text
// VERIFYMSG = 37,
// POSSIBLEFRIEND_MSG = 40,
const payloadBase = {
id : rawPayload.msgId,
timestamp : rawPayload.createTime / 1000, // Padplus message timestamp is seconds
type,
} as {
id : string,
timestamp : number,
type : MessageType,
filename? : string,
url? : string,
}
if (type === MessageType.Image
|| type === MessageType.Audio
|| type === MessageType.Video
|| type === MessageType.Attachment
) {
payloadBase.filename = messageFileName(rawPayload) || undefined
}
if (type === MessageType.Emoticon) {
payloadBase.url = rawPayload.url
}
let fromId: undefined | string
let roomId: undefined | string
let toId: undefined | string
let text: undefined | string
let mentionIdList: undefined | string[]