Skip to content

Commit

Permalink
Merge pull request #324 from CleverTap/develop
Browse files Browse the repository at this point in the history
[WEB-3373] Fixed Web Inbox MarkAsRead API for Custom Web Inbox Implementation
  • Loading branch information
singhkunal2050 authored Dec 19, 2024
2 parents 327454c + f2b7f42 commit 09391fc
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 29 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@kkyusuftk @singhkunal2050
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.

## [1.11.14] 17th Dec, 2024
- Fixed Custom Web Inbox APIs

## [1.11.13] 12th Dec, 2024
- Fixed web push soft prompt bug

Expand Down
46 changes: 31 additions & 15 deletions clevertap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clevertap.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clevertap.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clevertap-web-sdk",
"version": "1.11.13",
"version": "1.11.14",
"description": "",
"main": "clevertap.js",
"scripts": {
Expand Down
36 changes: 25 additions & 11 deletions src/clevertap.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,12 @@ export default class CleverTap {

// Get Inbox Unread Message Count
this.getInboxMessageUnreadCount = () => {
if ($ct.inbox) {
return $ct.inbox.unviewedCounter
} else {
this.#logger.debug('No unread messages')
try {
const unreadMessages = this.getUnreadInboxMessages()
const result = Object.keys(unreadMessages).length
return result
} catch (e) {
this.#logger.error('Error in getInboxMessageUnreadCount' + e)
}
}

Expand All @@ -232,10 +234,20 @@ export default class CleverTap {

// Get only Unread messages
this.getUnreadInboxMessages = () => {
if ($ct.inbox) {
return $ct.inbox.unviewedMessages
} else {
this.#logger.debug('No unread messages')
try {
const messages = getInboxMessages()
const result = {}

if (Object.keys(messages).length > 0) {
for (const message in messages) {
if (messages[message].viewed === 0) {
result[message] = messages[message]
}
}
}
return result
} catch (e) {
this.#logger.error('Error in getUnreadInboxMessages' + e)
}
}

Expand Down Expand Up @@ -281,9 +293,11 @@ export default class CleverTap {
- Remove the unread marker, update the viewed flag, decrement the bage Count
- renderNotificationViewed */
this.markReadInboxMessage = (messageId) => {
const unreadMsg = $ct.inbox.unviewedMessages
const messages = getInboxMessages()
if ((messageId !== null || messageId !== '') && unreadMsg.hasOwnProperty(messageId)) {
if ((messageId !== null || messageId !== '') && messages.hasOwnProperty(messageId)) {
if (messages[messageId].viewed === 1) {
return this.#logger.error('Message already viewed' + messageId)
}
const ctInbox = document.querySelector('ct-web-inbox')
if (ctInbox) {
const el = ctInbox.shadowRoot.getElementById(messageId)
Expand Down Expand Up @@ -321,8 +335,8 @@ export default class CleverTap {
- renderNotificationViewed, update the badge count and style
*/
this.markReadAllInboxMessage = () => {
const unreadMsg = $ct.inbox.unviewedMessages
const messages = getInboxMessages()
const unreadMsg = this.getUnreadInboxMessages()
if (Object.keys(unreadMsg).length > 0) {
const msgIds = Object.keys(unreadMsg)
msgIds.forEach(key => {
Expand Down

0 comments on commit 09391fc

Please sign in to comment.