@smartico/public-api 0.0.298 → 0.0.300

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.
@@ -769,6 +769,27 @@ The "onUpdate" callback will be triggered when the user receives a new message.
769
769
 
770
770
  ___
771
771
 
772
+ ### getInboxUnreadCount
773
+
774
+ ▸ **getInboxUnreadCount**(`params?`): `Promise`\<`number`\>
775
+
776
+ Returns inbox unread count.
777
+
778
+ **Visitor mode: not supported**
779
+
780
+ #### Parameters
781
+
782
+ | Name | Type |
783
+ | :------ | :------ |
784
+ | `params` | `Object` |
785
+ | `params.onUpdate?` | (`unread_count`: `number`) => `void` |
786
+
787
+ #### Returns
788
+
789
+ `Promise`\<`number`\>
790
+
791
+ ___
792
+
772
793
  ### getInboxMessageBody
773
794
 
774
795
  ▸ **getInboxMessageBody**(`messageGuid`): `Promise`\<[`TInboxMessageBody`](../interfaces/TInboxMessageBody.md)\>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartico/public-api",
3
- "version": "0.0.298",
3
+ "version": "0.0.300",
4
4
  "description": "Smartico public API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1118,6 +1118,15 @@ class SmarticoAPI {
1118
1118
  return InboxMessagesTransform((await this.getInboxMessages(user_ext_id, limit, offset, favoriteOnly, categoryId)).log);
1119
1119
  }
1120
1120
 
1121
+ public async getInboxUnreadCountT(
1122
+ user_ext_id: string,
1123
+ ): Promise<number> {
1124
+ const limit = 1;
1125
+ const offset = 0;
1126
+
1127
+ return (await this.getInboxMessages(user_ext_id, limit, offset, false, null)).unread_count;
1128
+ }
1129
+
1121
1130
  public async getInboxMessageBody(messageGuid: string): Promise<InboxMessageBody> {
1122
1131
  const getMessageBody = async (messageGuid: string): Promise<InboxMessageBody> => {
1123
1132
  const inboxCdnUrl = this.tracker.getLabelSetting(PublicLabelSettings.INBOX_PUBLIC_CDN);
@@ -90,6 +90,7 @@ enum onUpdateContextKey {
90
90
  Raffles = 'raffles',
91
91
  JackpotEligibleGames = 'jackpotEligibleGames',
92
92
  CurrentLevel = 'currentLevel',
93
+ InboxUnreadCount = 'inboxUnreadCount',
93
94
  }
94
95
 
95
96
  /** @group General API */
@@ -102,7 +103,6 @@ export class WSAPI {
102
103
  OCache.clearAll();
103
104
  if (this.api.tracker) {
104
105
  const on = this.api.tracker.on;
105
- const triggerExternalCallback = this.api.tracker.triggerExternalCallBack;
106
106
 
107
107
  on(ClassId.SAW_SPINS_COUNT_PUSH, (data: SAWSpinsCountPush) => this.updateOnSpin(data));
108
108
  on(ClassId.SAW_SHOW_SPIN_PUSH, () => this.reloadMiniGameTemplate());
@@ -138,14 +138,15 @@ export class WSAPI {
138
138
  OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.Raffles);
139
139
  });
140
140
  on(ClassId.GET_INBOX_MESSAGES_RESPONSE, (res) => {
141
- const unreadCountInProfile = this.api.tracker?.userPublicProps?.core_inbox_unread_count;
142
-
143
- if (res.unread_count && triggerExternalCallback && unreadCountInProfile !== res.unread_count) {
144
- triggerExternalCallback('props_change', {
145
- core_inbox_unread_count: res.unread_count,
146
- });
141
+ if (res.unread_count !== undefined && res.unread_count !== null) {
142
+ this.updateInboxUnreadCount(res.unread_count);
143
+ }
144
+ });
145
+ on(ClassId.CLIENT_PUBLIC_PROPERTIES_CHANGED_EVENT, (data: { props: { core_inbox_unread_count: number } }) => {
146
+ if (data?.props?.core_inbox_unread_count !== undefined && data?.props?.core_inbox_unread_count !== null) {
147
+ this.updateInboxUnreadCount(data.props.core_inbox_unread_count);
147
148
  }
148
- })
149
+ });
149
150
  }
150
151
  }
151
152
 
@@ -829,6 +830,24 @@ export class WSAPI {
829
830
  return await this.api.getInboxMessagesT(null, from, to, onlyFavorite, categoryId);
830
831
  }
831
832
 
833
+ /**
834
+ * Returns inbox unread count.
835
+ *
836
+ * **Visitor mode: not supported**
837
+ * @param params
838
+ */
839
+ public async getInboxUnreadCount({ onUpdate }: { onUpdate?: (unread_count: number) => void } = {}): Promise<number> {
840
+ if (onUpdate) {
841
+ this.onUpdateCallback.set(onUpdateContextKey.InboxUnreadCount, onUpdate);
842
+ }
843
+ return OCache.use(
844
+ onUpdateContextKey.InboxUnreadCount,
845
+ ECacheContext.WSAPI,
846
+ () => this.api.getInboxUnreadCountT(null),
847
+ CACHE_DATA_SEC,
848
+ );
849
+ }
850
+
832
851
  /**
833
852
  * Returns the message body of the specified message guid.
834
853
  *
@@ -963,6 +982,10 @@ export class WSAPI {
963
982
  this.updateEntity(onUpdateContextKey.StoreItems, payload);
964
983
  }
965
984
 
985
+ private async updateInboxUnreadCount(count: number) {
986
+ this.updateEntity(onUpdateContextKey.InboxUnreadCount, count);
987
+ }
988
+
966
989
  private async updateInboxMessages() {
967
990
  const payload = await this.api.getInboxMessagesT(null);
968
991
  this.updateEntity(onUpdateContextKey.InboxMessages, payload);