Skip to content

feat: read/unread status #1376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
84ce9ad
feat: read/unread status
chris13524 Jan 31, 2024
f1b598f
feat: add read state changes
Elyniss Feb 6, 2024
39183e0
chore: move features
Elyniss Feb 6, 2024
629c142
chore: refactor
Elyniss Feb 6, 2024
05b460e
Apply suggestions from code review
Elyniss Feb 6, 2024
13130ae
Merge pull request #1381 from WalletConnect/fea/web3inbox-read-unred/…
Elyniss Feb 7, 2024
f465b0a
chore: rename
Elyniss Feb 7, 2024
619a2e8
Merge pull request #1396 from WalletConnect/fea/web3inbox-read-unred/…
Elyniss Feb 7, 2024
f39a87f
chore: add api for read unread (#1383)
devceline Feb 7, 2024
be82275
fix: read unread in usage, and backwards-compatible parameters
chris13524 Feb 8, 2024
5286a03
Max sizes
chris13524 Feb 8, 2024
e96aa08
Merge pull request #1405 from WalletConnect/fix/web3inbox-read-unread…
chris13524 Feb 8, 2024
c1a4910
fix: add unreadCount
chris13524 Feb 8, 2024
442f9d3
feat: unread count
chris13524 Feb 8, 2024
a2a18a0
Merge branch 'main' of https://github.com/WalletConnect/walletconnect…
chris13524 Mar 18, 2024
f693a7d
fix: mark all notifications as read, remove mark as unread
chris13524 Mar 18, 2024
1187c9a
fix: remove "returned"
chris13524 Mar 19, 2024
910905f
feat: mark all as read endpoint
chris13524 Mar 20, 2024
1efc3d2
fix: syntax
chris13524 Mar 20, 2024
2d8c80f
fix: add rate limit for mark-all-as-read endpoint
chris13524 Mar 21, 2024
220a082
Update docs/web3inbox/frontend-integration/api.mdx
devceline Apr 16, 2024
8f53bbc
Update docs/web3inbox/frontend-integration/api.mdx
devceline Apr 16, 2024
b097f62
Apply suggestions from code review
devceline Apr 16, 2024
2a432d6
Update docs/web3inbox/frontend-integration/api.mdx
devceline Apr 16, 2024
ed951e7
chore: remove Web3Wallet changes
chris13524 Apr 16, 2024
23a99d7
fix: fmt
chris13524 Apr 16, 2024
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
9 changes: 8 additions & 1 deletion docs/api/notify/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,14 @@ const accountSubscriptions = notifyClient.getActiveSubscriptions({

```javascript
// Will return all past Notify messages for the provided subscription topic, keyed by messageId.
const messageHistory = notifyClient.getNotificationHistory({ topic, limit: 10, startingAfter: "notification-id" })
const messageHistory = notifyClient.getNotificationHistory({ topic, limit: 10, startingAfter: "notification-id", unreadFirst: true })
```

#### Marking notification as read

```javascript
// Will mark the 2 specific notifications as read
const messageHistory = notifyClient.markNotificationsAsRead({ topic, notificationIds: ["notification-1", "notification-2" ] })
```

</PlatformTabItem>
Expand Down
1 change: 1 addition & 0 deletions docs/web3inbox/about.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Some of the key features of the Web3Inbox SDK include:
- **Device push notifications:** Push notifications to the user's wallet (if it supports Notify API) or the [Web3Inbox.com app](https://app.web3inbox.com).
- **Notifications history:** Messages are stored and can be accessed from any device.
- **Spam protection/subscription control.**
- **Tracking read status across devices.**

## How do users receive notifications?

Expand Down
50 changes: 46 additions & 4 deletions docs/web3inbox/frontend-integration/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -298,27 +298,45 @@ Get notifications
// watch notifications of current account's subscription to current dapp
const notificationsPerPage = 5
const isInfiniteScroll = true
const unreadFirst = true

const { data: notifications, nextPage } = useNotifications(
const { data: notifications, nextPage, markAllReturnedNotificationsAsRead, markNotificationsAsRead } = useNotifications(
notificationsPerPage,
isInfiniteScroll
isInfiniteScroll,
unreadFirst
)

// marking a single notification as read
notifications[0].markAsRead();

// mark all notifications currently in `notifications` returned array as read
markAllReturnedNotificationsAsRead();

// mark specific notifications as read
markNotificationsAsRead(notifications.slice(2).map(n => n.id))

```

#### References

- **notificationsPerPage:** Number representing how many notifications to get per fetch
- **isInfiniteScroll:** Whether or not to keep already fetched notifications when getting next page
- **unreadFirst:** Whether or not unread messages should be sorted at the top, regardless of timestamp
- **notifications:** Array of notifications, of type
- **notification.markAsRead:** Mark the notification as read
- **markAllReturnedNotificationsAsRead**: Mark currently fetched notifications as read. *This does not mark all notifications as read, just the ones that have been fetched and returned here.*.
- **markNotificationsAsRead**: Takes an array of notification IDs and marks them as read

```ts
{
title: string;
sentAt: number;
body: string;
id: string;
isRead: boolean;
url: string | null;
type: string;
markAsRead: () => Promise<void>
}
```

Expand All @@ -336,29 +354,53 @@ const notificationsPage = client.getNotificationHistory({

const notificationsPerPage = 5
const isInfiniteScroll = true
const unreadFirst = true

let notifications = []

const { nextPage } = client.pageNotifications(
const onUpdate = ({notifications: fetchedNotifications}: GetNotificationsReturn) => {
notifications = fetchedNotifications
}

const { nextPage, markAllReturnedNotificationsAsRead, markNotificationAsRead } = client.pageNotifications(
notificationsPerPage,
isInfiniteScroll
isInfiniteScroll,
unreadFirst,
)(onUpdate)


// marking a single notification as read
notifications[0].markAsRead();

// mark all notifications currently in `notifications` returned array as read
markAllReturnedNotificationsAsRead();

// mark specific notifications as read
markNotificationsAsRead(notifications.slice(2).map(n => n.id))
```

#### References

- **notificationsPerPage:** Number representing how many notifications to get per fetch
- **isInfiniteScroll:** Whether or not to keep already fetched notifications when getting next page
- **unreadFirst:** Whether or not unread messages should be sorted at the top, regardless of timestamp
- **onUpdate:**: A callback that will be called whenever notifications get updated
- **nextPage:**: A function to be called to fetch the next page of notifications
- **notifications:** Array of notifications, of type
- **notification.markAsRead:** Mark the notification as read
- **markAllReturnedNotificationsAsRead**: Mark currently fetched notifications as read. *This does not mark all notifications as read, just the ones that have been fetched and returned here.*.
- **markNotificationsAsRead**: Takes an array of notification IDs and marks them as read

```ts
{
title: string;
sentAt: number;
body: string;
id: string;
isRead: boolean;
url: string | null;
type: string;
markAsRead: () => Promise<void>
}
```

Expand Down
53 changes: 53 additions & 0 deletions docs/web3wallet/notify/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Links to sections on this page. Some sections are platform specific and are only
Change allowed notification types sent by dapp
- [Fetching available notification types](#fetching-available-notification-types):
Get latest notification types
- [Updating messages read state](#updating-messages-read-state):
Marking messages as read or unread across all devices
- [Unsubscribe from a dapp](#unsubscribe-from-a-dapp):
Opt-out from receiving notifications from a dapp
- [Account logout](#account-logout):
Expand All @@ -45,6 +47,9 @@ section are:

To check the full list of platform specific instructions for your preferred platform, go to [Extra (Platform Specific)](#extra-platform-specific) and select your platform.




## Initialization

<CloudBanner />
Expand Down Expand Up @@ -553,6 +558,50 @@ const notificationTypes = notifyClient.getActiveSubscriptions({ account }).filte
</PlatformTabItem>
</PlatformTabs>


## Updating messages read state

Updating a messages read state allows the user to know that they already looked at and seen the message. The state of being read is also synced across all devices where the user can see the notification.

This method could be used in several ways in your UI, for example the user may click a button to mark the notification as read. Or you may automatically mark the notification is read when the notification is within the viewport. How you choose implement this is up to you.

<PlatformTabs activeOptions={["ios","android", "react-native"]}>
<PlatformTabItem value="ios">
</PlatformTabItem>
<PlatformTabItem value="android">


```kotlin
val topic: String = // active subscription topic
val notificationIds: List<String> = // List of notification ids to mark as read
val read: Boolean = // Read state to set the notifications to

val params = Notify.Params.UpdateNotificationsReadState(topic, notificationIds, read)

NotifyClient.updateNotificationsReadState(
params,
onSuccess = {
// callback for when the change notifications read state request was successful
},
onError = { error ->
// callback for when the change notifications read state request has failed
}
)
}
```

</PlatformTabItem>
<PlatformTabItem value="react-native">
```typescript
notifyClient.updateNotificationsReadState({
topic: string,
notificationIds: ["notification-id1", "notification-id2"],
read: true
})
```
</PlatformTabItem>
</PlatformTabs>

## Unsubscribe from a dapp

To opt-out of receiving notifications from a dap, a user can decide to unsubscribe from dapp.
Expand Down Expand Up @@ -765,6 +814,10 @@ val walletDelegate = object : NotifyClient.Delegate {
override fun onError(error: Notify.Model.Error) {
// Triggered when there's an error inside the SDK
}

override fun onNotifyNotificationsChanged(notifyNotificationsChanged: Notify.Event.NotificationsChanged) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing JS version of this, but I think we should de-scope notifications changed events: https://walletconnect.slack.com/archives/C044SKFKELR/p1710787967715679

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we should remove this: WalletConnect/walletconnect-specs#191 (comment)

// Triggered when a state was changed in the notifications
}
}

NotifyClient.setDelegate(walletDelegate)
Expand Down