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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@trycourier/courier-react-native",
"version": "5.6.17",
"version": "5.6.18",
"description": "Inbox, Push Notifications, and Preferences for React Native",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
40 changes: 34 additions & 6 deletions src/models/InboxAction.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Courier from '..';

export class InboxAction {
readonly content?: string | null;
readonly href?: string | null;
Expand All @@ -13,17 +15,43 @@ export class InboxAction {
this.data = data;
}

/**
* The id Courier uses to attribute a click to this action.
*
* It travels on the action rather than on the message, so a click is recorded against the
* button the user actually pressed. A template that opts out of tracking arrives without one.
*/
get trackingId(): string | undefined {
const value = this.data?.trackingId;
return typeof value === 'string' && value.length > 0 ? value : undefined;
}

/**
* Reports a click on this action.
*
* `CourierInboxView` already does this for you — the native inbox reports the click when an
* action is pressed. Call this yourself when you render your own action buttons. A no-op when
* the action carries no tracking id.
* @param messageId - The ID of the message this action belongs to.
*/
async markAsClicked(messageId: string): Promise<void> {
const trackingId = this.trackingId;

if (!trackingId) {
return;
}

const client = await Courier.shared.getClient();
await client?.inbox.click({ messageId, trackingId });
}

static fromJson(jsonString: string): InboxAction {
try {
const parsed = JSON.parse(jsonString);
return new InboxAction(
parsed.content,
parsed.href,
parsed.data
);
return new InboxAction(parsed.content, parsed.href, parsed.data);
} catch (error) {
console.log(`Error parsing action: ${error}`);
throw error;
}
}
}
}
Loading