Skip to content

Commit c879e14

Browse files
xavier-lcXavier Lozano Carreras
andauthored
🤖 Merge PR DefinitelyTyped#74641 Smooch: Add off method by @xavier-lc
Co-authored-by: Xavier Lozano Carreras <xavier.lozano.carreras@a8c.com>
1 parent 0374b10 commit c879e14

File tree

3 files changed

+144
-1
lines changed

3 files changed

+144
-1
lines changed

types/smooch/index.d.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,104 @@ declare namespace Smooch {
288288
*/
289289
function on(event: "typing:stop", callback: (data: ConversationData) => void): void;
290290
// tslint:enable:unified-signatures
291+
292+
// tslint:disable:unified-signatures
293+
/**
294+
* Removes a specific handler for the "ready" event, or all handlers if no callback is provided.
295+
*/
296+
function off(event: "ready", callback?: () => void): void;
297+
/**
298+
* Removes a specific handler for the "destroy" event, or all handlers if no callback is provided.
299+
*/
300+
function off(event: "destroy", callback?: () => void): void;
301+
/**
302+
* Removes a specific handler for the "participant:added" event, or all handlers if no callback is provided.
303+
*/
304+
function off(
305+
event: "participant:added",
306+
callback?: (participant: ConversationParticipant, data: ConversationData) => void,
307+
): void;
308+
/**
309+
* Removes a specific handler for the "participant:removed" event, or all handlers if no callback is provided.
310+
*/
311+
function off(
312+
event: "participant:removed",
313+
callback?: (participant: ConversationParticipant, data: ConversationData) => void,
314+
): void;
315+
/**
316+
* Removes a specific handler for the "conversation:added" event, or all handlers if no callback is provided.
317+
*/
318+
function off(
319+
event: "conversation:added",
320+
callback?: (participants: ConversationParticipant[], data: ConversationData) => void,
321+
): void;
322+
/**
323+
* Removes a specific handler for the "conversation:read" event, or all handlers if no callback is provided.
324+
*/
325+
function off(
326+
event: "conversation:read",
327+
callback?: (payload: ConversationReadEventPayload, data: ConversationData) => void,
328+
): void;
329+
/**
330+
* Removes a specific handler for the "conversation:removed" event, or all handlers if no callback is provided.
331+
*/
332+
function off(event: "conversation:removed", callback?: (data: ConversationData) => void): void;
333+
/**
334+
* Removes a specific handler for the "message:received" event, or all handlers if no callback is provided.
335+
*/
336+
function off(event: "message:received", callback?: (message: Message, data: ConversationData) => void): void;
337+
/**
338+
* Removes a specific handler for the "message:sent" event, or all handlers if no callback is provided.
339+
*/
340+
function off(event: "message:sent", callback?: (message: Message, data: ConversationData) => void): void;
341+
/**
342+
* Removes a specific handler for the "message" event, or all handlers if no callback is provided.
343+
*/
344+
function off(event: "message", callback?: (message: Message, data: ConversationData) => void): void;
345+
/**
346+
* Removes a specific handler for the "unreadCount" event, or all handlers if no callback is provided.
347+
*/
348+
function off(event: "unreadCount", callback?: (unreadCount: number, data: ConversationData) => void): void;
349+
/**
350+
* Removes a specific handler for the "widget:opened" event, or all handlers if no callback is provided.
351+
*/
352+
function off(event: "widget:opened", callback?: () => void): void;
353+
/**
354+
* Removes a specific handler for the "widget:closed" event, or all handlers if no callback is provided.
355+
*/
356+
function off(event: "widget:closed", callback?: () => void): void;
357+
/**
358+
* Removes a specific handler for the "log:debug" event, or all handlers if no callback is provided.
359+
*/
360+
function off(event: "log:debug", callback?: (e: DebugLog) => void): void;
361+
/**
362+
* Removes a specific handler for the "connected" event, or all handlers if no callback is provided.
363+
*/
364+
function off(event: "connected", callback?: (data: ConversationData) => void): void;
365+
/**
366+
* Removes a specific handler for the "disconnected" event, or all handlers if no callback is provided.
367+
*/
368+
function off(event: "disconnected", callback?: (data: ConversationData) => void): void;
369+
/**
370+
* Removes a specific handler for the "reconnecting" event, or all handlers if no callback is provided.
371+
*/
372+
function off(event: "reconnecting", callback?: (data: ConversationData) => void): void;
373+
/**
374+
* Removes a specific handler for the "typing:start" event, or all handlers if no callback is provided.
375+
*/
376+
function off(
377+
event: "typing:start",
378+
callback?: (data: ConversationData & { avatarUrl: string; name: string }) => void,
379+
): void;
380+
/**
381+
* Removes a specific handler for the "typing:stop" event, or all handlers if no callback is provided.
382+
*/
383+
function off(event: "typing:stop", callback?: (data: ConversationData) => void): void;
384+
/**
385+
* Removes all handlers for all events.
386+
*/
387+
function off(): void;
388+
// tslint:enable:unified-signatures
291389
}
292390

293391
type Nullable<T> = { [P in keyof T]: T[P] | null };

types/smooch/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/smooch",
4-
"version": "5.3.9999",
4+
"version": "5.6.9999",
55
"projects": [
66
"https://github.com/zendesk/sunshine-conversations-web"
77
],

types/smooch/smooch-tests.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,51 @@ Smooch.on("reconnecting", (data: ConversationData) => {});
2121
Smooch.on("typing:start", (data: ConversationData) => {});
2222
Smooch.on("typing:stop", (data: ConversationData) => {});
2323

24+
// off - remove a specific handler
25+
Smooch.off("ready", () => {});
26+
Smooch.off("destroy", () => {});
27+
Smooch.off("participant:added", (participant: ConversationParticipant, data: ConversationData) => {});
28+
Smooch.off("participant:removed", (participant: ConversationParticipant, data: ConversationData) => {});
29+
Smooch.off("conversation:added", (participants: ConversationParticipant[], data: ConversationData) => {});
30+
Smooch.off("conversation:read", (payload: ConversationReadEventPayload, data: ConversationData) => {});
31+
Smooch.off("conversation:removed", (data: ConversationData) => {});
32+
Smooch.off("message:received", (message: Message, data: ConversationData) => {});
33+
Smooch.off("message:sent", (message: Message, data: ConversationData) => {});
34+
Smooch.off("message", (message: Message, data: ConversationData) => {});
35+
Smooch.off("unreadCount", (unreadCount: number, data: ConversationData) => {});
36+
Smooch.off("widget:opened", () => {});
37+
Smooch.off("widget:closed", () => {});
38+
Smooch.off("log:debug", (e: DebugLog) => {});
39+
Smooch.off("connected", (data: ConversationData) => {});
40+
Smooch.off("disconnected", (data: ConversationData) => {});
41+
Smooch.off("reconnecting", (data: ConversationData) => {});
42+
Smooch.off("typing:start", (data: ConversationData) => {});
43+
Smooch.off("typing:stop", (data: ConversationData) => {});
44+
45+
// off - remove all handlers for a specific event
46+
Smooch.off("ready");
47+
Smooch.off("destroy");
48+
Smooch.off("participant:added");
49+
Smooch.off("participant:removed");
50+
Smooch.off("conversation:added");
51+
Smooch.off("conversation:read");
52+
Smooch.off("conversation:removed");
53+
Smooch.off("message:received");
54+
Smooch.off("message:sent");
55+
Smooch.off("message");
56+
Smooch.off("unreadCount");
57+
Smooch.off("widget:opened");
58+
Smooch.off("widget:closed");
59+
Smooch.off("log:debug");
60+
Smooch.off("connected");
61+
Smooch.off("disconnected");
62+
Smooch.off("reconnecting");
63+
Smooch.off("typing:start");
64+
Smooch.off("typing:stop");
65+
66+
// off - remove all handlers for all events
67+
Smooch.off();
68+
2469
// InitOptions must always have integrationId
2570
// @ts-expect-error
2671
Smooch.init({});

0 commit comments

Comments
 (0)