fb-messenger-e2ee 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +45 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -13
- package/dist/index.d.ts +44 -13
- package/dist/index.js +45 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3976,8 +3976,8 @@ init_cjs_shims();
|
|
|
3976
3976
|
var MessageBuilder = class {
|
|
3977
3977
|
content;
|
|
3978
3978
|
replyTo;
|
|
3979
|
-
setReply(
|
|
3980
|
-
this.replyTo =
|
|
3979
|
+
setReply(replyTo) {
|
|
3980
|
+
this.replyTo = replyTo;
|
|
3981
3981
|
return this;
|
|
3982
3982
|
}
|
|
3983
3983
|
getReply() {
|
|
@@ -4201,7 +4201,7 @@ function encodeMessageApplication(consumerAppBytes, replyTo) {
|
|
|
4201
4201
|
const appPayload = new ProtoWriter().bytes(4, payloadSubProto).build();
|
|
4202
4202
|
let metadataWriter = new ProtoWriter().bytes(8, frankingKey).varint(9, 0);
|
|
4203
4203
|
if (replyTo) {
|
|
4204
|
-
const quoted = new ProtoWriter().string(1, replyTo.
|
|
4204
|
+
const quoted = new ProtoWriter().string(1, replyTo.messageId).string(2, replyTo.chatJid).string(3, replyTo.senderJid).build();
|
|
4205
4205
|
metadataWriter = metadataWriter.bytes(10, quoted);
|
|
4206
4206
|
}
|
|
4207
4207
|
const metadata = metadataWriter.build();
|
|
@@ -5573,7 +5573,16 @@ var E2EEClient = class {
|
|
|
5573
5573
|
async buildDMTextFanoutPayloads(opts) {
|
|
5574
5574
|
const builder = new MessageBuilder().setText(opts.text);
|
|
5575
5575
|
if (opts.replyToId && opts.replyToSenderJid) {
|
|
5576
|
-
|
|
5576
|
+
const replyTo = {
|
|
5577
|
+
messageId: opts.replyToId,
|
|
5578
|
+
// chatJid = remoteJID: the thread/chat that holds the quoted message
|
|
5579
|
+
// For DM, this is the peer's bare JID (toJid).
|
|
5580
|
+
chatJid: opts.toJid,
|
|
5581
|
+
// senderJid = participant: who sent the original message.
|
|
5582
|
+
// Caller must supply the correct sender JID via replyToSenderJid.
|
|
5583
|
+
senderJid: opts.replyToSenderJid
|
|
5584
|
+
};
|
|
5585
|
+
builder.setReply(replyTo);
|
|
5577
5586
|
}
|
|
5578
5587
|
const consumerApp = builder.build();
|
|
5579
5588
|
const { messageApp, frankingTag } = encodeMessageApplication(consumerApp, builder.getReply());
|
|
@@ -5608,7 +5617,14 @@ var E2EEClient = class {
|
|
|
5608
5617
|
async encryptGroupText(groupJid, selfJid, text, messageId, replyToId, replyToSenderJid) {
|
|
5609
5618
|
const builder = new MessageBuilder().setText(text);
|
|
5610
5619
|
if (replyToId && replyToSenderJid) {
|
|
5611
|
-
|
|
5620
|
+
const replyTo = {
|
|
5621
|
+
messageId: replyToId,
|
|
5622
|
+
// chatJid = remoteJID: for a group message, this is the group JID
|
|
5623
|
+
chatJid: groupJid,
|
|
5624
|
+
// participant: the specific member who sent the original message
|
|
5625
|
+
senderJid: replyToSenderJid
|
|
5626
|
+
};
|
|
5627
|
+
builder.setReply(replyTo);
|
|
5612
5628
|
}
|
|
5613
5629
|
const consumerApp = builder.build();
|
|
5614
5630
|
const { messageApp, frankingTag } = encodeMessageApplication(consumerApp, builder.getReply());
|
|
@@ -8208,15 +8224,25 @@ var ClientController = class {
|
|
|
8208
8224
|
if (this.e2eeConnected && isE2EE) {
|
|
8209
8225
|
let messageId;
|
|
8210
8226
|
if (isGroup) {
|
|
8211
|
-
messageId = await this.sendE2EEGroupText(
|
|
8227
|
+
messageId = await this.sendE2EEGroupText(
|
|
8228
|
+
input.threadId,
|
|
8229
|
+
input.text,
|
|
8230
|
+
input.replyToMessageId,
|
|
8231
|
+
input.replyToSenderJid
|
|
8232
|
+
);
|
|
8212
8233
|
} else {
|
|
8213
|
-
messageId = await this.sendE2EEText(
|
|
8234
|
+
messageId = await this.sendE2EEText(
|
|
8235
|
+
input.threadId,
|
|
8236
|
+
input.text,
|
|
8237
|
+
input.replyToMessageId,
|
|
8238
|
+
input.replyToSenderJid
|
|
8239
|
+
);
|
|
8214
8240
|
}
|
|
8215
8241
|
return { messageId, timestampMs: now() };
|
|
8216
8242
|
}
|
|
8217
8243
|
return this.messagingService.sendText(this.requireApi(), input);
|
|
8218
8244
|
}
|
|
8219
|
-
async sendE2EEText(threadId, text, replyToMessageId) {
|
|
8245
|
+
async sendE2EEText(threadId, text, replyToMessageId, replyToSenderJid) {
|
|
8220
8246
|
if (!this.e2eeSocket) throw new Error("E2EE not connected");
|
|
8221
8247
|
const e2eeClient = this.e2eeService.getClient();
|
|
8222
8248
|
const selfJid = this.getSelfE2EEJid();
|
|
@@ -8228,7 +8254,9 @@ var ClientController = class {
|
|
|
8228
8254
|
text,
|
|
8229
8255
|
isGroup: false,
|
|
8230
8256
|
replyToId: replyToMessageId,
|
|
8231
|
-
|
|
8257
|
+
// For DM: participant = sender of original msg. If caller knows who sent it, use that;
|
|
8258
|
+
// otherwise fall back to the peer's JID (correct for messages they sent to us).
|
|
8259
|
+
replyToSenderJid: replyToMessageId ? replyToSenderJid ?? toJid : void 0
|
|
8232
8260
|
});
|
|
8233
8261
|
const participantNodes = [];
|
|
8234
8262
|
const deviceJids = uniqueJids(await this.e2eeHandler.getDeviceList([toJid, toBareMessengerJid(selfJid)]));
|
|
@@ -8274,7 +8302,7 @@ var ClientController = class {
|
|
|
8274
8302
|
logger.info("ClientController", `E2EE DM message sent to ${toJid} with ${participantNodes.length} devices`);
|
|
8275
8303
|
return messageId;
|
|
8276
8304
|
}
|
|
8277
|
-
async sendE2EEGroupText(groupJid, text, replyToMessageId) {
|
|
8305
|
+
async sendE2EEGroupText(groupJid, text, replyToMessageId, replyToSenderJid) {
|
|
8278
8306
|
if (!this.e2eeSocket) throw new Error("E2EE not connected");
|
|
8279
8307
|
const e2eeClient = this.e2eeService.getClient();
|
|
8280
8308
|
const selfJid = this.getSelfE2EEJid();
|
|
@@ -8290,7 +8318,8 @@ var ClientController = class {
|
|
|
8290
8318
|
text,
|
|
8291
8319
|
messageId,
|
|
8292
8320
|
replyToMessageId,
|
|
8293
|
-
|
|
8321
|
+
replyToSenderJid
|
|
8322
|
+
// pass through — undefined when not replying
|
|
8294
8323
|
);
|
|
8295
8324
|
const participantNodes = [];
|
|
8296
8325
|
for (const deviceJid of deviceJids) {
|
|
@@ -8630,7 +8659,11 @@ var ClientController = class {
|
|
|
8630
8659
|
const consumerApp = buildMessage(media.mediaFields);
|
|
8631
8660
|
const { messageApp, frankingTag } = e2eeClient.buildMessageApplication(
|
|
8632
8661
|
consumerApp,
|
|
8633
|
-
input.replyToMessageId ? {
|
|
8662
|
+
input.replyToMessageId ? {
|
|
8663
|
+
messageId: input.replyToMessageId,
|
|
8664
|
+
chatJid: toJid,
|
|
8665
|
+
senderJid: input.replyToSenderJid ?? toJid
|
|
8666
|
+
} : void 0
|
|
8634
8667
|
);
|
|
8635
8668
|
const devicePayload = e2eeClient.buildMessageTransport({ messageApp });
|
|
8636
8669
|
const selfDevicePayload = e2eeClient.buildMessageTransport({
|