Skip to content

Commit

Permalink
Merge pull request #704 from xmtp/notifications_update
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriguespe committed May 22, 2024
2 parents a5a1b4a + dd28028 commit 972c68d
Show file tree
Hide file tree
Showing 15 changed files with 503 additions and 227 deletions.
Binary file modified docs/build/img/notif-diagram.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 33 additions & 1 deletion docs/build/messages/custom.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import TabItem from "@theme/TabItem";

:::caution

Be aware that your custom content type may not be automatically recognized or supported by other applications, which could result in it being overlooked or only its fallback text being displayed.
Be aware that your custom content type may not be automatically recognized or supported by other apps, which could result in the other apps overlooking or only displaying the fallback text for your custom content type.

:::

Expand Down Expand Up @@ -86,6 +86,12 @@ export class ContentTypeMultiplyNumberCodec
)}`
// return undefined to indicate that this content type should not be displayed if it's not supported by a client
}

// Set to true to enable push notifications for interoperable content types.
// Receiving clients must handle this field appropriately.
shouldPush(): boolean {
return true;
}
}
```

Expand Down Expand Up @@ -150,6 +156,11 @@ export class ContentTypeMultiplyNumberCodec
)}`
// return undefined to indicate that this content type should not be displayed if it's not supported by a client
}

// This method is optional and can be used to determine if the content type should have a push notification
shouldPush() {
return true;
}
}

export const multiplyNumbersContentTypeConfig: ContentTypeConfiguration = {
Expand Down Expand Up @@ -220,6 +231,11 @@ data class MultiplyNumberCodec(
override fun fallback(content: NumberPair): String? {
return "Error: This app does not support numbers."
}

// This method is optional and can be used to determine if the content type should have a push notification
override fun shouldPush(): Boolean {
return true;
}
}
```

Expand Down Expand Up @@ -269,6 +285,12 @@ public struct MultiplyNumbersCodec: ContentCodec {
public func fallback(content: MultiplyNumbers) throws -> String? {
return "MultiplyNumbersCodec is not supported"
}


// This method is optional and can be used to determine if the content type should have a push notification
public func shouldPush() -> Bool {
return true;
}
}
```

Expand Down Expand Up @@ -334,6 +356,11 @@ class MultiplyNumbersCodec extends Codec<MultiplyNumbers> {
@override
// Fallback function in case the codec is not supported
String fallback(MultiplyNumbers content) => "MultiplyNumbersCodec is not supported";
// This method is optional and can be used to determine if the content type should have a push notification
@override
bool shouldPush() => true;
}
```

Expand Down Expand Up @@ -393,6 +420,11 @@ class ContentTypeMultiplyNumberCodec
fallback(content: MultiplyNumbers): string {
return `MultiplyNumbersCodec is not supported`
}

// This method is optional and can be used to determine if the content type should trigger a push notification
shouldPush(): boolean {
return true;
}
}
```
Expand Down
4 changes: 4 additions & 0 deletions docs/build/messages/reaction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,7 @@ _To handle unsupported content types, refer to the [fallback](/docs/build/messag
## Display the reaction

Generally, reactions should be interpreted as emoji. So, "smile" would translate to 😄 in UI clients. That being said, how you ultimately choose to render a reaction in your app is up to you.

## Notifications and reactions

Reactions have `shouldPush` set to `false`, which means that reactions do not trigger push notifications as long as the notification server respects this flag.
4 changes: 4 additions & 0 deletions docs/build/messages/read-receipt.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ if (message.contentTypeId === "xmtp.org/readReceipt:1.0") {

_`ReadReceipts` have an `undefined` or `nil` fallback, indicating the message is not expected to be displayed. Refer to [how handle unsupported content types](/docs/build/messages/#handle-an-unsupported-content-type-error) section._

## Notifications and read receipts

Read receipts have `shouldPush` set to `false`, which means that read receipts do not trigger push notifications as long as the notification server respects this flag.

## Use a read receipt

Generally, a read receipt indicator should be displayed under the message it's associated with. The indicator can include a timestamp. Ultimately, how you choose to display a read receipt indicator is completely up to you.
Expand Down
186 changes: 0 additions & 186 deletions docs/build/notifications.md

This file was deleted.

6 changes: 6 additions & 0 deletions docs/build/notifications/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"label": "Notifications",
"position": 20,
"collapsible": false,
"collapsed": false
}

0 comments on commit 972c68d

Please sign in to comment.