Skip to content

Commit 5e02d6b

Browse files
committed
add: support for @lid
1 parent 2da0e39 commit 5e02d6b

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- AlterTable
2+
ALTER TABLE "Message" ADD COLUMN "keyLid" VARCHAR(100),
3+
ADD COLUMN "keyParticipantLid" VARCHAR(100),
4+
ALTER COLUMN "keyRemoteJid" DROP NOT NULL;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Please do not edit this file manually
2-
# It should be added in your version-control system (i.e. Git)
3-
provider = "postgresql"
2+
# It should be added in your version-control system (e.g., Git)
3+
provider = "postgresql"

prisma/schema.prisma

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,23 @@ enum DeviceMessage {
8888
}
8989

9090
model Message {
91-
id Int @id @default(autoincrement())
92-
keyId String @db.VarChar(100)
93-
keyRemoteJid String @db.VarChar(100)
94-
keyFromMe Boolean @db.Boolean
95-
keyParticipant String? @db.VarChar(100)
96-
pushName String? @db.VarChar(100)
97-
messageType String @db.VarChar(100)
98-
content Json @db.JsonB
99-
messageTimestamp Int @db.Integer
100-
device DeviceMessage
101-
isGroup Boolean? @db.Boolean
102-
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
103-
instanceId Int
104-
MessageUpdate MessageUpdate[]
105-
Media Media?
91+
id Int @id @default(autoincrement())
92+
keyId String @db.VarChar(100)
93+
keyRemoteJid String? @db.VarChar(100)
94+
keyLid String? @db.VarChar(100)
95+
keyFromMe Boolean @db.Boolean
96+
keyParticipant String? @db.VarChar(100)
97+
keyParticipantLid String? @db.VarChar(100)
98+
pushName String? @db.VarChar(100)
99+
messageType String @db.VarChar(100)
100+
content Json @db.JsonB
101+
messageTimestamp Int @db.Integer
102+
device DeviceMessage
103+
isGroup Boolean? @db.Boolean
104+
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
105+
instanceId Int
106+
MessageUpdate MessageUpdate[]
107+
Media Media?
106108
107109
@@index([keyId], name: "keyId")
108110
}

src/whatsapp/services/whatsapp.service.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ import makeWASocket, {
6969
WAMessage,
7070
WAMessageUpdate,
7171
WASocket,
72-
WAVersion,
7372
} from '@whiskeysockets/baileys';
7473
import {
7574
ConfigService,
@@ -847,10 +846,12 @@ export class WAStartupService {
847846

848847
messagesRaw.push({
849848
keyId: m.key.id,
850-
keyRemoteJid: this.normalizeJid(m.key),
851849
keyFromMe: m.key.fromMe,
852850
pushName: m?.pushName || m.key.remoteJid.split('@')[0],
853-
keyParticipant: m?.participant || this.normalizeParticipant(m.key),
851+
keyRemoteJid: m.key?.remoteJid,
852+
keyLid: m.key?.['senderLid'] || m.key?.['senderPn'],
853+
keyParticipant: m?.participant || m.key?.participant,
854+
keyParticipantLid: m.key?.['participantLid'] || m.key?.['participantPn'],
854855
messageType,
855856
content: m.message[messageType] as PrismType.Prisma.JsonValue,
856857
messageTimestamp: timestamp,
@@ -926,11 +927,13 @@ export class WAStartupService {
926927

927928
const messageRaw = {
928929
keyId: received.key.id,
929-
keyRemoteJid: this.normalizeJid(received.key),
930930
keyFromMe: received.key.fromMe,
931931
pushName: received.pushName,
932-
keyParticipant:
933-
received?.participant || this.normalizeParticipant(received.key),
932+
keyRemoteJid: received.key?.remoteJid,
933+
keyLid: received.key?.['senderLid'] || received.key?.['senderPn'],
934+
keyParticipant: received?.participant || received.key?.participant,
935+
keyParticipantLid:
936+
received.key?.['participantLid'] || received.key?.['participantPn'],
934937
messageType,
935938
content: JSON.parse(
936939
JSON.stringify(received.message[messageType]),
@@ -1238,14 +1241,6 @@ export class WAStartupService {
12381241
}
12391242
}
12401243

1241-
private normalizeJid(key: proto.IMessageKey) {
1242-
return key?.remoteJid || key?.['remoteJidAlt'] || key?.['lid'];
1243-
}
1244-
1245-
private normalizeParticipant(key: proto.IMessageKey) {
1246-
return key?.participant || key?.['participantAlt'];
1247-
}
1248-
12491244
private createJid(number: string): string {
12501245
if (
12511246
number.includes('@g.us') ||
@@ -2078,7 +2073,7 @@ export class WAStartupService {
20782073
for await (const number of data.numbers) {
20792074
const jid = this.createJid(number);
20802075
if (isLidUser(jid)) {
2081-
onWhatsapp.push(new OnWhatsAppDto(jid, !!true, jid));
2076+
onWhatsapp.push(new OnWhatsAppDto(jid, true, jid));
20822077
}
20832078
if (isJidGroup(jid)) {
20842079
const group = await this.findGroup({ groupJid: jid }, 'inner');

0 commit comments

Comments
 (0)