refactor!: use proto.Conversation's own chat mutation fields instead of baileys added

This commit is contained in:
Adhiraj Singh
2022-09-29 11:06:09 +05:30
parent bb983cd30d
commit e08dd10198
4 changed files with 7 additions and 13 deletions

View File

@@ -12,7 +12,7 @@ import makeOrderedDictionary from './make-ordered-dictionary'
type WASocket = ReturnType<typeof makeMDSocket>
export const waChatKey = (pin: boolean) => ({
key: (c: Chat) => (pin ? (c.pin ? '1' : '0') : '') + (c.archive ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
key: (c: Chat) => (pin ? (c.pinned ? '1' : '0') : '') + (c.archived ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
compare: (k1: string, k2: string) => k2.localeCompare (k1)
})

View File

@@ -33,13 +33,7 @@ export type WAPatchCreate = {
operation: proto.SyncdMutation.SyncdOperation
}
export type Chat = proto.IConversation & {
/** unix timestamp of date when mute ends, if applicable */
mute?: number | null
/** timestamp of when pinned */
pin?: number | null
archive?: boolean
}
export type Chat = proto.IConversation
/**
* the last messages in a chat, sorted reverse-chronologically. That is, the latest message should be first in the chat

View File

@@ -631,7 +631,7 @@ export const processSyncAction = (
[
{
id,
mute: action.muteAction?.muted ?
muteEndTime: action.muteAction?.muted ?
toNumber(action.muteAction!.muteEndTimestamp!) :
null
}
@@ -657,9 +657,9 @@ export const processSyncAction = (
// basically we don't need to fire an "archive" update if the chat is being marked unarchvied
// this only applies for the initial sync
if(isInitialSync && !archiveAction.archived) {
ev.emit('chats.update', [{ id, archive: false }])
ev.emit('chats.update', [{ id, archived: false }])
} else {
ev.emit('chats.update', [{ id, archive: !!archiveAction?.archived }])
ev.emit('chats.update', [{ id, archived: !!archiveAction?.archived }])
}
}
} else if(action?.markChatAsReadAction) {
@@ -692,7 +692,7 @@ export const processSyncAction = (
ev.emit('creds.update', { me: { ...me, name: action?.pushNameSetting?.name! } })
}
} else if(action?.pinAction) {
ev.emit('chats.update', [{ id, pin: action.pinAction?.pinned ? toNumber(action.timestamp!) : null }])
ev.emit('chats.update', [{ id, pinned: action.pinAction?.pinned ? toNumber(action.timestamp!) : null }])
} else if(action?.unarchiveChatsSetting) {
const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats
ev.emit('creds.update', { accountSettings: { unarchiveChats } })

View File

@@ -81,7 +81,7 @@ const processMessage = async(
}
if(accountSettings?.unarchiveChats) {
chat.archive = false
chat.archived = false
chat.readOnly = false
}
}