web: announce available presence when relay starts
This commit is contained in:
@@ -153,6 +153,7 @@ describe("provider-web", () => {
|
|||||||
|
|
||||||
const listener = await monitorWebInbox({ verbose: false, onMessage });
|
const listener = await monitorWebInbox({ verbose: false, onMessage });
|
||||||
const sock = getLastSocket();
|
const sock = getLastSocket();
|
||||||
|
expect(sock.sendPresenceUpdate).toHaveBeenCalledWith("available");
|
||||||
const upsert = {
|
const upsert = {
|
||||||
type: "notify",
|
type: "notify",
|
||||||
messages: [
|
messages: [
|
||||||
@@ -174,10 +175,8 @@ describe("provider-web", () => {
|
|||||||
expect(sock.readMessages).toHaveBeenCalledWith([
|
expect(sock.readMessages).toHaveBeenCalledWith([
|
||||||
{ remoteJid: "999@s.whatsapp.net", id: "abc", participant: undefined, fromMe: false },
|
{ remoteJid: "999@s.whatsapp.net", id: "abc", participant: undefined, fromMe: false },
|
||||||
]);
|
]);
|
||||||
expect(sock.sendPresenceUpdate).toHaveBeenCalledWith(
|
expect(sock.sendPresenceUpdate).toHaveBeenCalledWith("available");
|
||||||
"composing",
|
expect(sock.sendPresenceUpdate).toHaveBeenCalledWith("composing", "999@s.whatsapp.net");
|
||||||
"999@s.whatsapp.net",
|
|
||||||
);
|
|
||||||
expect(sock.sendMessage).toHaveBeenCalledWith("999@s.whatsapp.net", {
|
expect(sock.sendMessage).toHaveBeenCalledWith("999@s.whatsapp.net", {
|
||||||
text: "pong",
|
text: "pong",
|
||||||
});
|
});
|
||||||
@@ -218,6 +217,7 @@ describe("provider-web", () => {
|
|||||||
fromMe: false,
|
fromMe: false,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
expect(sock.sendPresenceUpdate).toHaveBeenCalledWith("available");
|
||||||
await listener.close();
|
await listener.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -243,6 +243,13 @@ export async function monitorWebInbox(options: {
|
|||||||
}) {
|
}) {
|
||||||
const sock = await createWaSocket(false, options.verbose);
|
const sock = await createWaSocket(false, options.verbose);
|
||||||
await waitForWaConnection(sock);
|
await waitForWaConnection(sock);
|
||||||
|
try {
|
||||||
|
// Advertise that the relay is online right after connecting.
|
||||||
|
await sock.sendPresenceUpdate("available");
|
||||||
|
if (isVerbose()) logVerbose("Sent global 'available' presence on connect");
|
||||||
|
} catch (err) {
|
||||||
|
logVerbose(`Failed to send 'available' presence on connect: ${String(err)}`);
|
||||||
|
}
|
||||||
const selfJid = sock.user?.id;
|
const selfJid = sock.user?.id;
|
||||||
const selfE164 = selfJid ? jidToE164(selfJid) : null;
|
const selfE164 = selfJid ? jidToE164(selfJid) : null;
|
||||||
const seen = new Set<string>();
|
const seen = new Set<string>();
|
||||||
|
|||||||
Reference in New Issue
Block a user