Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
case PadplusMessageType.StatusNotify:
case PadplusMessageType.SysNotice:
type = MessageType.Unknown
break
default:
throw new Error('unsupported type: ' + PadplusMessageType[rawType] + '(' + rawType + ')')
}
return type
}
*
* 4. Set Text
*/
if (isRoomId(rawPayload.fromUserName)) {
const startIndex = rawPayload.content.indexOf(':\n')
text = rawPayload.content.slice(startIndex !== -1 ? startIndex + 2 : 0)
} else {
text = rawPayload.content
}
if (type === MessageType.Recalled) {
const recalledPayload = await recalledPayloadParser(rawPayload)
const pattern = [
/"(.+)" 撤回了一条消息/,
/"(.+)" has recalled a message./,
]
const patternSelf = [
/你撤回了一条消息/,
/You recalled a message/,
]
if (recalledPayload) {
const isRecalled = pattern.some(regex => regex.test(recalledPayload.replaceMsg))
const isRecalledSelf = patternSelf.some(regex => regex.test(recalledPayload.replaceMsg))
if (isRecalled || isRecalledSelf) {
text = recalledPayload.newMsgId
if (isRecalledSelf) {
sandbox.stub(puppet, 'messagePayload').callsFake(async (id) => {
await new Promise(resolve => setImmediate(resolve))
if (id === EXPECTED_RECALL_MESSAGE_ID) {
return {
id: EXPECTED_RECALL_MESSAGE_ID,
text: EXPECTED_RECALLED_MESSAGE_ID,
timestamp: EXPECTED_MESSAGE_TIMESTAMP,
type: MessageType.Recalled,
} as MessagePayload
} else {
return {
fromId: EXPECTED_FROM_CONTACT_ID,
id: EXPECTED_RECALLED_MESSAGE_ID,
roomId: EXPECTED_ROOM_ID,
text: '',
timestamp: EXPECTED_MESSAGE_TIMESTAMP,
toId: EXPECTED_TO_CONTACT_ID,
type: MessageType.Text,
} as MessagePayload
}
})
sandbox.stub(puppet, 'roomPayload').callsFake(async () => {