Skip to content

Commit

Permalink
messages-send,tsconfig: add poll message attributes + fix tsconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
PurpShell committed Oct 18, 2024
1 parent 18ac07d commit 34cfa92
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/Socket/messages-send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
tag: 'message',
attrs: {
id: msgId!,
type: 'text',
type: getMessageType(message),
...(additionalAttributes || {})
},
content: binaryNodeContent
Expand Down Expand Up @@ -577,6 +577,15 @@ export const makeMessagesSocket = (config: SocketConfig) => {
return msgId
}


const getMessageType = (message: proto.IMessage) => {
if(message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3) {
return 'poll'
}

return 'text'
}

const getMediaType = (message: proto.IMessage) => {
if(message.imageMessage) {
return 'image'
Expand Down Expand Up @@ -760,7 +769,9 @@ export const makeMessagesSocket = (config: SocketConfig) => {
const isDeleteMsg = 'delete' in content && !!content.delete
const isEditMsg = 'edit' in content && !!content.edit
const isPinMsg = 'pin' in content && !!content.pin
const isPollMessage = 'poll' in content && !!content.poll
const additionalAttributes: BinaryNodeAttributes = { }
const additionalNodes: BinaryNode[] = []
// required for delete
if(isDeleteMsg) {
// if the chat is a group, and I am not the author, then delete the message as an admin
Expand All @@ -773,13 +784,20 @@ export const makeMessagesSocket = (config: SocketConfig) => {
additionalAttributes.edit = '1'
} else if(isPinMsg) {
additionalAttributes.edit = '2'
} else if(isPollMessage) {
additionalNodes.push({
tag: 'meta',
attrs: {
polltype: 'creation'
},
} as BinaryNode)
}

if('cachedGroupMetadata' in options) {
console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.')
}

await relayMessage(jid, fullMsg.message!, { messageId: fullMsg.key.id!, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList })
await relayMessage(jid, fullMsg.message!, { messageId: fullMsg.key.id!, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList, additionalNodes })
if(config.emitOwnEvents) {
process.nextTick(() => {
processingMutex.mutex(() => (
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"compilerOptions": {
"target": "es2018",
"module": "CommonJS",
"moduleResolution": "NodeNext",
"experimentalDecorators": true,
"allowJs": false,
"checkJs": false,
Expand Down

0 comments on commit 34cfa92

Please sign in to comment.