Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Socket/messages-recv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@

await delay(5000)

if (!await placeholderResendCache.get(messageKey?.id!)) {
if (!(await placeholderResendCache.get(messageKey?.id!))) {
logger.debug({ messageKey }, 'message received while resend requested')
return 'RESOLVED'
}
Expand Down Expand Up @@ -185,7 +185,7 @@

let data: any
try {
data = JSON.parse(mexNode.content.toString())

Check warning on line 188 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
} catch (error) {
logger.error({ err: error, node }, 'Failed to parse mex newsletter notification')
return
Expand Down Expand Up @@ -281,7 +281,7 @@
if (settingsNode) {
const update: Record<string, any> = {}
const nameNode = getBinaryNodeChild(settingsNode, 'name')
if (nameNode?.content) update.name = nameNode.content.toString()

Check warning on line 284 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type

const descriptionNode = getBinaryNodeChild(settingsNode, 'description')
if (descriptionNode?.content) update.description = descriptionNode.content.toString()
Expand Down Expand Up @@ -429,12 +429,12 @@
let shouldRecreateSession = false
let recreateReason = ''

if (enableAutoSessionRecreation && messageRetryManager) {
if (enableAutoSessionRecreation && messageRetryManager && retryCount > 1) {
try {
// Check if we have a session with this JID
const sessionId = signalRepository.jidToSignalProtocolAddress(fromJid)
const hasSession = await signalRepository.validateSession(fromJid)
const result = messageRetryManager.shouldRecreateSession(fromJid, retryCount, hasSession.exists)
const result = messageRetryManager.shouldRecreateSession(fromJid, hasSession.exists)
shouldRecreateSession = result.recreate
recreateReason = result.reason

Expand Down Expand Up @@ -987,12 +987,12 @@
let shouldRecreateSession = false
let recreateReason = ''

if (enableAutoSessionRecreation && messageRetryManager) {
if (enableAutoSessionRecreation && messageRetryManager && retryCount > 1) {
try {
const sessionId = signalRepository.jidToSignalProtocolAddress(participant)

const hasSession = await signalRepository.validateSession(participant)
const result = messageRetryManager.shouldRecreateSession(participant, retryCount, hasSession.exists)
const result = messageRetryManager.shouldRecreateSession(participant, hasSession.exists)
shouldRecreateSession = result.recreate
recreateReason = result.reason

Expand Down Expand Up @@ -1177,7 +1177,7 @@

const encNode = getBinaryNodeChild(node, 'enc')
// TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
if (encNode && encNode.attrs.type === 'msmsg') {
if (encNode?.attrs.type === 'msmsg') {
logger.debug({ key: node.attrs.key }, 'ignored msmsg')
await sendMessageAck(node, NACK_REASONS.MissingMessageSecret)
return
Expand Down
7 changes: 1 addition & 6 deletions src/Utils/message-retry-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class MessageRetryManager {
/**
* Check if a session should be recreated based on retry count and history
*/
shouldRecreateSession(jid: string, retryCount: number, hasSession: boolean): { reason: string; recreate: boolean } {
shouldRecreateSession(jid: string, hasSession: boolean): { reason: string; recreate: boolean } {
// If we don't have a session, always recreate
if (!hasSession) {
this.sessionRecreateHistory.set(jid, Date.now())
Expand All @@ -120,11 +120,6 @@ export class MessageRetryManager {
}
}

// Only consider recreation if retry count > 1
if (retryCount < 2) {
return { reason: '', recreate: false }
}

const now = Date.now()
const prevTime = this.sessionRecreateHistory.get(jid)

Expand Down
Loading