Skip to content

Commit 510c581

Browse files
committed
refactor: integrate IterableApi methods in IterableInboxDataModel
1 parent 72d066a commit 510c581

2 files changed

Lines changed: 28 additions & 17 deletions

File tree

src/core/classes/IterableApi.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type { IterableInAppCloseSource } from '../../inApp/enums/IterableInAppCl
1212
import type { IterableInAppDeleteSource } from '../../inApp/enums/IterableInAppDeleteSource';
1313
import type { IterableHtmlInAppContent } from '../../inApp/classes/IterableHtmlInAppContent';
1414
import type { IterableInAppShowResponse } from '../../inApp/enums/IterableInAppShowResponse';
15+
import type { IterableInboxImpressionRowInfo } from '../../inbox/types/IterableInboxImpressionRowInfo';
1516

1617
export class IterableApi {
1718
static logger: IterableLogger = defaultLogger;
@@ -340,4 +341,19 @@ export class IterableApi {
340341
IterableApi.logger.log('passAlongAuthToken: ', authToken);
341342
return RNIterableAPI.passAlongAuthToken(authToken);
342343
}
344+
345+
static startSession(visibleRows: IterableInboxImpressionRowInfo[]) {
346+
IterableApi.logger.log('startSession: ', visibleRows);
347+
return RNIterableAPI.startSession(visibleRows);
348+
}
349+
350+
static endSession() {
351+
IterableApi.logger.log('endSession');
352+
return RNIterableAPI.endSession();
353+
}
354+
355+
static updateVisibleRows(visibleRows: IterableInboxImpressionRowInfo[] = []) {
356+
IterableApi.logger.log('updateVisibleRows: ', visibleRows);
357+
return RNIterableAPI.updateVisibleRows(visibleRows);
358+
}
343359
}

src/inbox/classes/IterableInboxDataModel.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { RNIterableAPI } from '../../api';
2-
import { Iterable } from '../../core/classes/Iterable';
1+
import { IterableApi } from '../../core/classes/IterableApi';
32
import {
43
IterableHtmlInAppContent,
54
IterableInAppDeleteSource,
@@ -94,11 +93,7 @@ export class IterableInboxDataModel {
9493
* @returns A promise that resolves to the HTML content of the specified message.
9594
*/
9695
getHtmlContentForMessageId(id: string): Promise<IterableHtmlInAppContent> {
97-
Iterable?.logger?.log(
98-
'IterableInboxDataModel.getHtmlContentForItem messageId: ' + id
99-
);
100-
101-
return RNIterableAPI.getHtmlInAppContentForMessage(id).then(
96+
return IterableApi.getHtmlInAppContentForMessage(id).then(
10297
(content: IterableHtmlInAppContentRaw) => {
10398
return IterableHtmlInAppContent.fromDict(content);
10499
}
@@ -111,9 +106,7 @@ export class IterableInboxDataModel {
111106
* @param id - The unique identifier of the message to be marked as read.
112107
*/
113108
setMessageAsRead(id: string) {
114-
Iterable?.logger?.log('IterableInboxDataModel.setMessageAsRead');
115-
116-
RNIterableAPI.setReadForMessage(id, true);
109+
return IterableApi.setReadForMessage(id, true);
117110
}
118111

119112
/**
@@ -123,9 +116,11 @@ export class IterableInboxDataModel {
123116
* @param deleteSource - The source from which the delete action is initiated.
124117
*/
125118
deleteItemById(id: string, deleteSource: IterableInAppDeleteSource) {
126-
Iterable?.logger?.log('IterableInboxDataModel.deleteItemById');
127-
128-
RNIterableAPI.removeMessage(id, IterableInAppLocation.inbox, deleteSource);
119+
return IterableApi.removeMessage(
120+
id,
121+
IterableInAppLocation.inbox,
122+
deleteSource
123+
);
129124
}
130125

131126
/**
@@ -135,7 +130,7 @@ export class IterableInboxDataModel {
135130
* If the fetch operation fails, the promise resolves to an empty array.
136131
*/
137132
async refresh(): Promise<IterableInboxRowViewModel[]> {
138-
return RNIterableAPI.getInboxMessages().then(
133+
return IterableApi.getInboxMessages().then(
139134
(messages: IterableInAppMessage[]) => {
140135
return this.processMessages(messages);
141136
},
@@ -151,7 +146,7 @@ export class IterableInboxDataModel {
151146
* @param visibleRows - An array of `IterableInboxImpressionRowInfo` objects representing the rows that are currently visible.
152147
*/
153148
startSession(visibleRows: IterableInboxImpressionRowInfo[] = []) {
154-
RNIterableAPI.startSession(visibleRows as unknown as { [key: string]: string | number | boolean }[]);
149+
return IterableApi.startSession(visibleRows);
155150
}
156151

157152
/**
@@ -162,7 +157,7 @@ export class IterableInboxDataModel {
162157
*/
163158
async endSession(visibleRows: IterableInboxImpressionRowInfo[] = []) {
164159
await this.updateVisibleRows(visibleRows);
165-
RNIterableAPI.endSession();
160+
return IterableApi.endSession();
166161
}
167162

168163
/**
@@ -178,7 +173,7 @@ export class IterableInboxDataModel {
178173
* Defaults to an empty array if not provided.
179174
*/
180175
updateVisibleRows(visibleRows: IterableInboxImpressionRowInfo[] = []) {
181-
RNIterableAPI.updateVisibleRows(visibleRows as unknown as { [key: string]: string | number | boolean }[]);
176+
return IterableApi.updateVisibleRows(visibleRows);
182177
}
183178

184179
/**

0 commit comments

Comments
 (0)