Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/utils/use-multi-file-auth-state-prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export default async function useMultiFileAuthStatePrisma(
ids.map(async (id) => {
let value = await readData(`${type}-${id}`);
if (type === 'app-state-sync-key' && value) {
value = proto.Message.AppStateSyncKeyData.create(value);
value = proto.Message.AppStateSyncKeyData.fromObject(value);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider extracting the AppStateSyncKey deserialization into a shared helper to avoid duplication across providers.

This AppStateSyncKeyData.fromObject logic is now duplicated in the Prisma, file-based, and Redis implementations. Pulling it into a shared helper (e.g., deserializeAppStateSyncKey(type, value)) would keep behavior consistent if the proto or conversion changes and simplify handling future edge cases like versioned payloads across all providers.

Suggested implementation:

              let value = await readData(`${type}-${id}`);
              value = deserializeAppStateSyncKey(type, value);

              data[id] = value;

To fully implement the suggestion, you should also:

  1. Add an import for the shared helper at the top of this file:

    • import { deserializeAppStateSyncKey } from './app-state-sync-key';
      (adjust the relative path to match your existing utils structure, e.g. ../utils/app-state-sync-key if appropriate).
  2. Create a shared helper module (e.g. src/utils/app-state-sync-key.ts) with behavior like:

    import { proto } from '@adiwajshing/baileys'; // or wherever proto comes from
    
    export function deserializeAppStateSyncKey(type: string, value: any) {
      if (type === 'app-state-sync-key' && value) {
        return proto.Message.AppStateSyncKeyData.fromObject(value);
      }
    
      return value;
    }
  3. Update the file-based and Redis implementations to also use this helper instead of inlining:

    value = deserializeAppStateSyncKey(type, value);

    at the corresponding locations where proto.Message.AppStateSyncKeyData.fromObject(value) is currently used.

These changes will centralize the AppStateSyncKey deserialization logic and keep behavior consistent across all providers.

}

data[id] = value;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/use-multi-file-auth-state-provider-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class AuthStateProvider {
ids.map(async (id) => {
let value = await readData(`${type}-${id}`);
if (type === 'app-state-sync-key' && value) {
value = proto.Message.AppStateSyncKeyData.create(value);
value = proto.Message.AppStateSyncKeyData.fromObject(value);
}

data[id] = value;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/use-multi-file-auth-state-redis-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function useMultiFileAuthStateRedisDb(
ids.map(async (id) => {
let value = await readData(`${type}-${id}`);
if (type === 'app-state-sync-key' && value) {
value = proto.Message.AppStateSyncKeyData.create(value);
value = proto.Message.AppStateSyncKeyData.fromObject(value);
}

data[id] = value;
Expand Down