@trycourier/courier-react-native
Version:
Inbox, Push Notifications, and Preferences for React Native
62 lines • 1.8 kB
JavaScript
import Courier from "..";
export class InboxMessage {
constructor(messageId, title = null, body = null, preview = null, created = null, actions = null, data = null, read = null, opened = null, archived = null, subtitle = null, time = '', trackingIds = null) {
this.messageId = messageId;
this.title = title;
this.body = body;
this.preview = preview;
this.created = created;
this.actions = actions;
this.data = data;
this.read = read;
this.opened = opened;
this.archived = archived;
this.subtitle = subtitle;
this.time = time;
this.trackingIds = trackingIds;
}
get isRead() {
return this.read !== null;
}
get isOpened() {
return this.opened !== null;
}
get isArchived() {
return this.archived !== null;
}
static fromJson(jsonString) {
try {
const parsed = JSON.parse(jsonString);
return new InboxMessage(parsed.messageId, parsed.title, parsed.body, parsed.preview, parsed.created, parsed.actions, parsed.data, parsed.read, parsed.opened, parsed.archived, parsed.subtitle, parsed.time, parsed.trackingIds);
} catch (error) {
console.log(`Error parsing message: ${error}`);
throw error;
}
}
async markAsRead() {
await Courier.shared.readMessage({
messageId: this.messageId
});
}
async markAsUnread() {
await Courier.shared.unreadMessage({
messageId: this.messageId
});
}
async markAsArchived() {
await Courier.shared.archiveMessage({
messageId: this.messageId
});
}
async markAsOpened() {
await Courier.shared.openMessage({
messageId: this.messageId
});
}
async markAsClicked() {
await Courier.shared.clickMessage({
messageId: this.messageId
});
}
}
//# sourceMappingURL=InboxMessage.js.map