-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
243 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
/** | ||
* Serializes a chat object | ||
* @param rawChat Chat object | ||
* @returns {Chat} | ||
*/ | ||
export const serializeChatObj = (obj) => { | ||
if (obj == undefined) { | ||
return null; | ||
} | ||
return Object.assign(window.API.serializeRawObj(obj), { | ||
kind: obj.kind, | ||
isGroup: obj.isGroup, | ||
contact: obj['contact'] | ||
? window.API.serializeContactObj(obj['contact']) | ||
: null, | ||
groupMetadata: obj['groupMetadata'] | ||
? window.API.serializeRawObj(obj['groupMetadata']) | ||
: null, | ||
presence: obj['presence'] | ||
? window.API.serializeRawObj(obj['presence']) | ||
: null, | ||
msgs: null, | ||
isOnline: obj.__x_presence.attributes.isOnline || null, | ||
lastSeen: | ||
obj && | ||
obj.previewMessage && | ||
obj.previewMessage.__x_ephemeralStartTimestamp | ||
? obj.previewMessage.__x_ephemeralStartTimestamp * 1000 | ||
: null, | ||
}); | ||
}; | ||
if (obj == undefined) { | ||
return null; | ||
} | ||
return Object.assign(window.API.serializeRawObj(obj), { | ||
kind: obj?.kind, | ||
isGroup: obj?.isGroup, | ||
contact: obj?.contact | ||
? window.API.serializeContactObj(obj?.contact) | ||
: null, | ||
groupMetadata: obj?.groupMetadata | ||
? window.API.serializeRawObj(obj?.groupMetadata) | ||
: null, | ||
presence: obj?.presence | ||
? window.API.serializeRawObj(obj?.presence) | ||
: null, | ||
msgs: null, | ||
tcToken: null, | ||
isOnline: obj?.__x_presence?.attributes?.isOnline || null, | ||
lastSeen: obj?.previewMessage?.__x_ephemeralStartTimestamp | ||
? obj.previewMessage.__x_ephemeralStartTimestamp * 1000 | ||
: null, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,31 @@ | ||
/** | ||
* Function to serialize contact object | ||
* @param {*} obj | ||
* @returns | ||
*/ | ||
export const serializeContactObj = (obj) => { | ||
if (obj === undefined) { | ||
if (obj == undefined) { | ||
return null; | ||
} | ||
|
||
const serializedObj = window.API.serializeRawObj(obj); | ||
|
||
if (!obj.profilePicThumb && obj.id && window.Store.ProfilePicThumb) { | ||
obj.profilePicThumb = window.Store.ProfilePicThumb.get(obj.id); | ||
if (!obj.profilePicThumb && obj.id && Store.ProfilePicThumb) { | ||
obj.profilePicThumb = Store.ProfilePicThumb.get(obj.id); | ||
} | ||
|
||
return { | ||
...serializedObj, | ||
formattedName: obj.formattedName, | ||
displayName: obj.displayName, | ||
formattedShortName: obj.formattedShortName, | ||
formattedShortNameWithNonBreakingSpaces: | ||
obj.formattedShortNameWithNonBreakingSpaces, | ||
isHighLevelVerified: obj.isHighLevelVerified, | ||
isMe: obj.isMe, | ||
mentionName: obj.mentionName, | ||
notifyName: obj.notifyName, | ||
isMyContact: obj.isMyContact, | ||
isPSA: obj.isPSA, | ||
isUser: obj?.isUser ?? obj.id?.server === 'c.us' ? true : false, | ||
isVerified: obj.isVerified, | ||
isWAContact: obj.isWAContact, | ||
profilePicThumbObj: obj.profilePicThumb | ||
? API.serializeProfilePicThumb(obj.profilePicThumb) | ||
return Object.assign(window.API.serializeRawObj(obj), { | ||
revisionNumber: obj?.revisionNumber, | ||
is_contact: obj?.isAddressBookContact, | ||
profilePicThumbObj: obj?.profilePicThumb | ||
? API.serializeProfilePicThumb(obj?.profilePicThumb) | ||
: {}, | ||
statusMute: obj.statusMute, | ||
msgs: null, | ||
}; | ||
isBusiness: obj?.isBusiness, | ||
isEnterprise: obj?.isEnterprise, | ||
isSmb: obj?.isSmb, | ||
labels: obj?.labels, | ||
locale: obj?.locale, | ||
name: obj?.name, | ||
pendingAction: obj?.pendingAction, | ||
shortName: obj?.shortName, | ||
verifiedName: obj?.verifiedName, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,109 @@ | ||
export const serializeMessageObj = (obj) => { | ||
/** | ||
* Function to serialize a message object | ||
* @param {*} obj | ||
* @param {*} groupInfo | ||
* @returns | ||
*/ | ||
export const serializeMessageObj = async (obj, groupInfo = true) => { | ||
if (obj === undefined) { | ||
return null; | ||
} | ||
const _chat = obj['chat'] ? await API.serializeChatObj(obj['chat']) : {}; | ||
let objGroup = null; | ||
if (groupInfo) { | ||
let chats = await API.getAllChats(); | ||
objGroup = | ||
obj?.to?.server === 'g.us' || obj?.from?.server === 'g.us' | ||
? chats.find((chat) => chat?.id?._serialized === obj?.from?._serialized) | ||
.contact | ||
: null; | ||
} | ||
|
||
const serializedObj = window.API.serializeRawObj(obj); | ||
|
||
const chat = obj.chat ? API.serializeChatObj(obj.chat) : {}; | ||
if (obj.quotedMsg) obj.quotedMsgObj(); | ||
const serializeAds = obj?.ctwaContext | ||
? { | ||
conversionSource: obj?.ctwaContext?.conversionSource, | ||
description: obj?.ctwaContext?.description, | ||
isSuspiciousLink: obj?.ctwaContext?.isSuspiciousLink, | ||
mediaType: obj?.ctwaContext?.mediaType, | ||
mediaUrl: obj?.ctwaContext?.mediaUrl, | ||
sourceUrl: obj?.ctwaContext?.sourceUrl, | ||
thumbnail: obj?.ctwaContext?.thumbnail, | ||
thumbnailUrl: obj?.ctwaContext?.thumbnailUrl, | ||
title: obj?.ctwaContext?.title, | ||
} | ||
: undefined; | ||
|
||
return { | ||
...serializedObj, | ||
id: obj.id._serialized, | ||
from: obj.from._serialized, | ||
quotedParticipant: obj.quotedParticipant ? obj.quotedParticipant._serialized : undefined, | ||
author: obj.author ? obj.author._serialized : undefined, | ||
chatId: obj.id && obj.id.remote ? obj.id.remote : obj.chatId && obj.chatId._serialized ? obj.chatId._serialized : undefined, | ||
to: obj.to ? obj.to._serialized : undefined, | ||
isSentByMe: obj.isSentByMe, | ||
fromMe: obj.id.fromMe, | ||
sender: obj.senderObj ? API.serializeContactObj(obj.senderObj) : null, | ||
timestamp: obj.t, | ||
content: obj.body, | ||
body: obj.body, | ||
isGroupMsg: obj.isGroupMsg, | ||
isLink: obj.isLink, | ||
isMMS: obj.isMMS, | ||
isMedia: obj.isMedia, | ||
isNotification: obj.isNotification, | ||
isPSA: obj.isPSA, | ||
type: obj.type, | ||
chat: chat, | ||
isOnline: chat.isOnline, | ||
lastSeen: chat.lastSeen, | ||
quotedMsgObj: obj.quotedMsg, | ||
quotedStanzaId: obj.quotedStanzaID ? obj.quotedStanzaID : undefined, | ||
mediaData: window.API.serializeRawObj(obj.mediaData), | ||
caption: obj.caption, | ||
deprecatedMms3Url: obj.deprecatedMms3Url, | ||
directPath: obj.directPath, | ||
encFilehash: obj.encFilehash, | ||
filehash: obj.filehash, | ||
filename: obj.filename, | ||
mimetype: obj.mimetype, | ||
clientUrl: obj.clientUrl, | ||
mediaKey: obj.mediaKey, | ||
size: obj.size, | ||
t: obj.t, | ||
isNewMsg: obj.isNewMsg, | ||
linkPreview: obj.linkPreview, | ||
text: obj.text, | ||
height: obj.height, | ||
width: obj.width, | ||
self: obj.self, | ||
initialPageSize: obj.initialPageSize, | ||
lat: obj.lat ? obj.lat : undefined, | ||
lng: obj.lng ? obj.lng : undefined, | ||
ack: obj.ack, | ||
scanLengths: undefined, | ||
scansSidecar: undefined, | ||
streamingSidecar: undefined, | ||
waveform: undefined, | ||
replyButtons: undefined, | ||
dynamicReplyButtons: undefined, | ||
buttons: undefined, | ||
hydratedButtons: undefined, | ||
isGroupMsg: obj?.to?.server === 'g.us' || obj?.from?.server === 'g.us', | ||
groupInfo: (obj?.to?.server === 'g.us' || obj?.from?.server === 'g.us') ? chats.find((chat) => chat.id._serialized === obj.from._serialized).contact : null | ||
...window.API.serializeRawObj(obj), | ||
id: obj?.id?._serialized, | ||
msgKey: obj?.id, | ||
from: obj?.from?._serialized, | ||
quotedParticipant: obj?.quotedParticipant?._serialized | ||
? obj?.quotedParticipant?._serialized | ||
: undefined, | ||
author: obj?.author?._serialized ? obj?.author?._serialized : undefined, | ||
chatId: obj?.id?.remote | ||
? obj?.id?.remote | ||
: obj?.chatId?._serialized | ||
? obj?.chatId?._serialized | ||
: undefined, | ||
to: obj?.to?._serialized ? obj?.to?._serialized : undefined, | ||
fromMe: obj?.id?.fromMe, | ||
sender: obj?.senderObj | ||
? await API.serializeContactObj(obj?.senderObj) | ||
: null, | ||
timestamp: obj?.t, | ||
description: obj?.description, | ||
content: obj?.body, | ||
body: obj?.body, | ||
isLink: obj?.isLink, | ||
isMMS: obj?.isMMS, | ||
isMedia: obj?.isMedia, | ||
isNotification: obj?.isNotification, | ||
isPSA: obj?.isPSA, | ||
type: obj?.type, | ||
chat: _chat, | ||
isOnline: _chat?.isOnline, | ||
lastSeen: _chat?.lastSeen, | ||
quotedMsgObj: obj?.quotedMsg, | ||
quotedStanzaId: obj?.quotedStanzaID ? obj?.quotedStanzaID : undefined, | ||
mediaData: window.API.serializeRawObj(obj?.mediaData), | ||
caption: obj?.caption, | ||
deprecatedMms3Url: obj?.deprecatedMms3Url, | ||
directPath: obj?.directPath, | ||
encFilehash: obj?.encFilehash, | ||
filehash: obj?.filehash, | ||
filename: obj?.filename, | ||
mimetype: obj?.mimetype, | ||
clientUrl: obj?.clientUrl, | ||
mediaKey: obj?.mediaKey, | ||
size: obj?.size, | ||
t: obj?.t, | ||
isNewMsg: obj?.isNewMsg, | ||
linkPreview: obj?.linkPreview, | ||
text: obj?.text, | ||
height: obj?.height, | ||
width: obj?.width, | ||
self: obj?.self, | ||
initialPageSize: obj?.initialPageSize, | ||
lat: obj?.lat ? obj.lat : undefined, | ||
lng: obj?.lng ? obj.lng : undefined, | ||
ack: obj?.ack, | ||
scanLengths: null, | ||
scansSidecar: null, | ||
streamingSidecar: null, | ||
waveform: null, | ||
replyButtons: obj?.replyButtons, | ||
dynamicReplyButtons: obj?.dynamicReplyButtons, | ||
buttons: obj?.buttons, | ||
hydratedButtons: obj?.hydratedButtons, | ||
subtype: obj?.subtype, | ||
thumbnail: obj?.thumbnail, | ||
isGroupMsg: | ||
obj?.to?.server === 'g.us' || obj?.from?.server === 'g.us' ? true : false, | ||
groupInfo: objGroup, | ||
title: obj?.title, | ||
ctwaContext: serializeAds, | ||
messageSecret: obj?.messageSecret && undefined, | ||
}; | ||
}; |
Oops, something went wrong.