Skip to content
Merged
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
98 changes: 98 additions & 0 deletions types/smooch/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,104 @@ declare namespace Smooch {
*/
function on(event: "typing:stop", callback: (data: ConversationData) => void): void;
// tslint:enable:unified-signatures

// tslint:disable:unified-signatures
/**
* Removes a specific handler for the "ready" event, or all handlers if no callback is provided.
*/
function off(event: "ready", callback?: () => void): void;
/**
* Removes a specific handler for the "destroy" event, or all handlers if no callback is provided.
*/
function off(event: "destroy", callback?: () => void): void;
/**
* Removes a specific handler for the "participant:added" event, or all handlers if no callback is provided.
*/
function off(
event: "participant:added",
callback?: (participant: ConversationParticipant, data: ConversationData) => void,
): void;
/**
* Removes a specific handler for the "participant:removed" event, or all handlers if no callback is provided.
*/
function off(
event: "participant:removed",
callback?: (participant: ConversationParticipant, data: ConversationData) => void,
): void;
/**
* Removes a specific handler for the "conversation:added" event, or all handlers if no callback is provided.
*/
function off(
event: "conversation:added",
callback?: (participants: ConversationParticipant[], data: ConversationData) => void,
): void;
/**
* Removes a specific handler for the "conversation:read" event, or all handlers if no callback is provided.
*/
function off(
event: "conversation:read",
callback?: (payload: ConversationReadEventPayload, data: ConversationData) => void,
): void;
/**
* Removes a specific handler for the "conversation:removed" event, or all handlers if no callback is provided.
*/
function off(event: "conversation:removed", callback?: (data: ConversationData) => void): void;
/**
* Removes a specific handler for the "message:received" event, or all handlers if no callback is provided.
*/
function off(event: "message:received", callback?: (message: Message, data: ConversationData) => void): void;
/**
* Removes a specific handler for the "message:sent" event, or all handlers if no callback is provided.
*/
function off(event: "message:sent", callback?: (message: Message, data: ConversationData) => void): void;
/**
* Removes a specific handler for the "message" event, or all handlers if no callback is provided.
*/
function off(event: "message", callback?: (message: Message, data: ConversationData) => void): void;
/**
* Removes a specific handler for the "unreadCount" event, or all handlers if no callback is provided.
*/
function off(event: "unreadCount", callback?: (unreadCount: number, data: ConversationData) => void): void;
/**
* Removes a specific handler for the "widget:opened" event, or all handlers if no callback is provided.
*/
function off(event: "widget:opened", callback?: () => void): void;
/**
* Removes a specific handler for the "widget:closed" event, or all handlers if no callback is provided.
*/
function off(event: "widget:closed", callback?: () => void): void;
/**
* Removes a specific handler for the "log:debug" event, or all handlers if no callback is provided.
*/
function off(event: "log:debug", callback?: (e: DebugLog) => void): void;
/**
* Removes a specific handler for the "connected" event, or all handlers if no callback is provided.
*/
function off(event: "connected", callback?: (data: ConversationData) => void): void;
/**
* Removes a specific handler for the "disconnected" event, or all handlers if no callback is provided.
*/
function off(event: "disconnected", callback?: (data: ConversationData) => void): void;
/**
* Removes a specific handler for the "reconnecting" event, or all handlers if no callback is provided.
*/
function off(event: "reconnecting", callback?: (data: ConversationData) => void): void;
/**
* Removes a specific handler for the "typing:start" event, or all handlers if no callback is provided.
*/
function off(
event: "typing:start",
callback?: (data: ConversationData & { avatarUrl: string; name: string }) => void,
): void;
/**
* Removes a specific handler for the "typing:stop" event, or all handlers if no callback is provided.
*/
function off(event: "typing:stop", callback?: (data: ConversationData) => void): void;
/**
* Removes all handlers for all events.
*/
function off(): void;
// tslint:enable:unified-signatures
}

type Nullable<T> = { [P in keyof T]: T[P] | null };
Expand Down
2 changes: 1 addition & 1 deletion types/smooch/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/smooch",
"version": "5.3.9999",
"version": "5.6.9999",
"projects": [
"https://github.com/zendesk/sunshine-conversations-web"
],
Expand Down
45 changes: 45 additions & 0 deletions types/smooch/smooch-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,51 @@ Smooch.on("reconnecting", (data: ConversationData) => {});
Smooch.on("typing:start", (data: ConversationData) => {});
Smooch.on("typing:stop", (data: ConversationData) => {});

// off - remove a specific handler
Smooch.off("ready", () => {});
Smooch.off("destroy", () => {});
Smooch.off("participant:added", (participant: ConversationParticipant, data: ConversationData) => {});
Smooch.off("participant:removed", (participant: ConversationParticipant, data: ConversationData) => {});
Smooch.off("conversation:added", (participants: ConversationParticipant[], data: ConversationData) => {});
Smooch.off("conversation:read", (payload: ConversationReadEventPayload, data: ConversationData) => {});
Smooch.off("conversation:removed", (data: ConversationData) => {});
Smooch.off("message:received", (message: Message, data: ConversationData) => {});
Smooch.off("message:sent", (message: Message, data: ConversationData) => {});
Smooch.off("message", (message: Message, data: ConversationData) => {});
Smooch.off("unreadCount", (unreadCount: number, data: ConversationData) => {});
Smooch.off("widget:opened", () => {});
Smooch.off("widget:closed", () => {});
Smooch.off("log:debug", (e: DebugLog) => {});
Smooch.off("connected", (data: ConversationData) => {});
Smooch.off("disconnected", (data: ConversationData) => {});
Smooch.off("reconnecting", (data: ConversationData) => {});
Smooch.off("typing:start", (data: ConversationData) => {});
Smooch.off("typing:stop", (data: ConversationData) => {});

// off - remove all handlers for a specific event
Smooch.off("ready");
Smooch.off("destroy");
Smooch.off("participant:added");
Smooch.off("participant:removed");
Smooch.off("conversation:added");
Smooch.off("conversation:read");
Smooch.off("conversation:removed");
Smooch.off("message:received");
Smooch.off("message:sent");
Smooch.off("message");
Smooch.off("unreadCount");
Smooch.off("widget:opened");
Smooch.off("widget:closed");
Smooch.off("log:debug");
Smooch.off("connected");
Smooch.off("disconnected");
Smooch.off("reconnecting");
Smooch.off("typing:start");
Smooch.off("typing:stop");

// off - remove all handlers for all events
Smooch.off();

// InitOptions must always have integrationId
// @ts-expect-error
Smooch.init({});
Expand Down