Skip to content

Commit 7f6654a

Browse files
feat: add unread messages count supscriotion
MOB-4510
1 parent 29a1319 commit 7f6654a

File tree

15 files changed

+243
-11
lines changed

15 files changed

+243
-11
lines changed

android/src/main/java/com/glia/widgets/ionic/GliaSdk.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.glia.widgets.ionic;
22

3-
import static java.util.Locale.filter;
4-
53
import android.app.Activity;
64
import android.util.Log;
75

@@ -44,6 +42,16 @@ public String echo(String value) {
4442
return value;
4543
}
4644

45+
private final EventEmitter eventEmitter;
46+
47+
public interface EventEmitter {
48+
void notify(String eventName, JSObject params);
49+
}
50+
51+
public GliaSdk(EventEmitter eventEmitter) {
52+
this.eventEmitter = eventEmitter;
53+
}
54+
4755
public void configure(PluginCall call, Activity activity) {
4856

4957
JSObject apiKey = call.getObject("apiKey");
@@ -98,7 +106,7 @@ public void configure(PluginCall call, Activity activity) {
98106
() -> {
99107
configureQueueIds = jsArrayToArrayList(queueIds);
100108

101-
call.resolve();
109+
subscribeToUnreadMessageCount(call);
102110
},
103111
exception -> {
104112
call.reject(exception.getMessage());
@@ -454,6 +462,20 @@ public void subscribeToPushNotificationTypes(PluginCall call, Activity activity)
454462
call.resolve();
455463
}
456464

465+
public void subscribeToUnreadMessageCount(PluginCall call) {
466+
try {
467+
GliaWidgets.getSecureConversations().subscribeToUnreadMessageCount(count -> {
468+
JSObject params = new JSObject();
469+
params.put("count", count);
470+
// Emit the event to the JS side
471+
eventEmitter.notify("gliaWidgetsUnreadMessageCountChanged", params);
472+
});
473+
call.resolve();
474+
} catch (Exception e) {
475+
call.reject("SUBSCRIPTION_ERROR", "Failed to subscribe to unread message count: " + e.getMessage(), e);
476+
}
477+
}
478+
457479
public ArrayList<String> jsArrayToArrayList(JSArray jsArray) {
458480
if (jsArray == null) {
459481
return new ArrayList<>();

android/src/main/java/com/glia/widgets/ionic/GliaSdkPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@CapacitorPlugin(name = "GliaSdk")
1010
public class GliaSdkPlugin extends Plugin {
1111

12-
private GliaSdk implementation = new GliaSdk();
12+
private final GliaSdk implementation = new GliaSdk(this::notifyListeners);
1313

1414
@PluginMethod
1515
public void echo(PluginCall call) {

dist/docs.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,52 @@
367367
"docs": "Ends the current engagement.",
368368
"complexTypes": [],
369369
"slug": "endengagement"
370+
},
371+
{
372+
"name": "subscribeToUnreadMessageCount",
373+
"signature": "(callback: UnreadMessageCountCallback) => void",
374+
"parameters": [
375+
{
376+
"name": "callback",
377+
"docs": "- A callback function that will be invoked with the updated unread message count.",
378+
"type": "UnreadMessageCountCallback"
379+
}
380+
],
381+
"returns": "void",
382+
"tags": [
383+
{
384+
"name": "param",
385+
"text": "callback - A callback function that will be invoked with the updated unread message count."
386+
}
387+
],
388+
"docs": "Subscribes to updates of the unread message count.\n\nThis method allows you to receive updates whenever the unread message count for\nSecure Conversations changes. It does not count live chat messages.\nThe provided callback will be triggered with the updated count.",
389+
"complexTypes": [
390+
"UnreadMessageCountCallback"
391+
],
392+
"slug": "subscribetounreadmessagecount"
393+
},
394+
{
395+
"name": "unsubscribeFromUnreadMessageCount",
396+
"signature": "(callback: UnreadMessageCountCallback) => void",
397+
"parameters": [
398+
{
399+
"name": "callback",
400+
"docs": "- The same callback function instance that was previously subscribed to receive updates.",
401+
"type": "UnreadMessageCountCallback"
402+
}
403+
],
404+
"returns": "void",
405+
"tags": [
406+
{
407+
"name": "param",
408+
"text": "callback - The same callback function instance that was previously subscribed to receive updates."
409+
}
410+
],
411+
"docs": "Unsubscribes from updates of the unread message count.\n\nThis method stops receiving updates for the unread message count for the provided callback.",
412+
"complexTypes": [
413+
"UnreadMessageCountCallback"
414+
],
415+
"slug": "unsubscribefromunreadmessagecount"
370416
}
371417
],
372418
"properties": []
@@ -783,6 +829,17 @@
783829
"complexTypes": []
784830
}
785831
]
832+
},
833+
{
834+
"name": "UnreadMessageCountCallback",
835+
"slug": "unreadmessagecountcallback",
836+
"docs": "Callback function type for unread message count updates.",
837+
"types": [
838+
{
839+
"text": "(count: number): void",
840+
"complexTypes": []
841+
}
842+
]
786843
}
787844
],
788845
"pluginConfigs": []

dist/esm/definitions.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ export declare const PushNotificationsIOS: Readonly<{
303303
PRODUCTION: string;
304304
}>;
305305
export declare type PushNotificationsIOS = (typeof PushNotificationsIOS)[keyof typeof PushNotificationsIOS];
306+
/**
307+
* Callback function type for unread message count updates.
308+
* @param count - The current unread message count for Secure Conversations.
309+
*/
310+
export declare type UnreadMessageCountCallback = (count: number) => void;
306311
export interface GliaSdk {
307312
/**
308313
* Configures GliaWidgets SDK.
@@ -479,4 +484,22 @@ export interface GliaSdk {
479484
* Ends the current engagement.
480485
*/
481486
endEngagement(): Promise<void>;
487+
/**
488+
* Subscribes to updates of the unread message count.
489+
*
490+
* This method allows you to receive updates whenever the unread message count for
491+
* Secure Conversations changes. It does not count live chat messages.
492+
* The provided callback will be triggered with the updated count.
493+
*
494+
* @param callback - A callback function that will be invoked with the updated unread message count.
495+
*/
496+
subscribeToUnreadMessageCount(callback: UnreadMessageCountCallback): void;
497+
/**
498+
* Unsubscribes from updates of the unread message count.
499+
*
500+
* This method stops receiving updates for the unread message count for the provided callback.
501+
*
502+
* @param callback - The same callback function instance that was previously subscribed to receive updates.
503+
*/
504+
unsubscribeFromUnreadMessageCount(callback: UnreadMessageCountCallback): void;
482505
}

dist/esm/definitions.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/plugin.cjs.js

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/plugin.cjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/plugin.js

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)