Skip to content

Commit

Permalink
Merge pull request #116 from xmtp/np/read-receipts
Browse files Browse the repository at this point in the history
Read Receipts
  • Loading branch information
nplasterer authored Sep 15, 2023
2 parents df4dbba + e0e33b3 commit 9b91a9a
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 9 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ repositories {
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation "org.xmtp:android:0.6.2"
implementation "org.xmtp:android:0.6.3"
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.facebook.react:react-native:0.71.3'
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import org.xmtp.android.library.codecs.ContentTypeReaction
import org.xmtp.android.library.codecs.ContentTypeText
import org.xmtp.android.library.codecs.AttachmentCodec
import org.xmtp.android.library.codecs.Attachment
import org.xmtp.android.library.codecs.ContentTypeReadReceipt
import org.xmtp.android.library.codecs.ContentTypeRemoteAttachment
import org.xmtp.android.library.codecs.ContentTypeReply
import org.xmtp.android.library.codecs.ReactionAction
import org.xmtp.android.library.codecs.ReactionSchema
import org.xmtp.android.library.codecs.ReactionCodec
import org.xmtp.android.library.codecs.Reaction
import org.xmtp.android.library.codecs.ReadReceipt
import org.xmtp.android.library.codecs.ReadReceiptCodec
import org.xmtp.android.library.codecs.RemoteAttachment
import org.xmtp.android.library.codecs.RemoteAttachmentCodec
import org.xmtp.android.library.codecs.Reply
Expand Down Expand Up @@ -48,6 +51,7 @@ class ContentJson(
Client.register(ReactionCodec())
Client.register(RemoteAttachmentCodec())
Client.register(ReplyCodec())
Client.register(ReadReceiptCodec())
// TODO:
//Client.register(CompositeCodec())
}
Expand Down Expand Up @@ -100,6 +104,8 @@ class ContentJson(
content = nested.content,
contentType = nested.type,
))
} else if (obj.has("readReceipt")) {
return ContentJson(ContentTypeReadReceipt, ReadReceipt)
} else {
throw Exception("Unknown content type")
}
Expand Down Expand Up @@ -153,6 +159,10 @@ class ContentJson(
)
)

ContentTypeReadReceipt.id -> mapOf(
"readReceipt" to ""
)

else -> mapOf(
"unknown" to mapOf(
"contentTypeId" to type.description
Expand Down
12 changes: 6 additions & 6 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PODS:
- BigInt (5.0.0)
- boost (1.76.0)
- Connect-Swift (0.7.0):
- Connect-Swift (0.8.0):
- SwiftProtobuf (~> 1.23.0)
- DoubleConversion (1.1.6)
- EXApplication (5.1.1):
Expand Down Expand Up @@ -415,15 +415,15 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.5.4-alpha0):
- XMTP (0.5.7-alpha0):
- Connect-Swift
- GzipSwift
- web3.swift
- XMTPRust (= 0.3.1-beta0)
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- XMTP (= 0.5.4-alpha0)
- XMTP (= 0.5.7-alpha0)
- XMTPRust (0.3.1-beta0)
- Yoga (1.14.0)

Expand Down Expand Up @@ -617,7 +617,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8
boost: 57d2868c099736d80fcd648bf211b4431e51a558
Connect-Swift: 3b305e8305a8b88a33be087dad207d84aad57dd2
Connect-Swift: ed4000df7d6cdd794f2530e844e649a672d032ee
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
EXApplication: d8f53a7eee90a870a75656280e8d4b85726ea903
EXConstants: f348da07e21b23d2b085e270d7b74f282df1a7d9
Expand Down Expand Up @@ -680,8 +680,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: b70d65f419fbfe61a2d58003456ca5da58e337d6
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 8e220d6c064c293911d88adb08087b90d06c22c5
XMTPReactNative: cfa66e30fa730f3b5f6cb4fed64eb3d11552e4b6
XMTP: 1b584f662fff8f006987dba2d5b1c9cacc929966
XMTPReactNative: a8057fb0fa8ab1decf2f70414a7359b2b194055c
XMTPRust: 78f65f77b1454392980da244961777aee955652f
Yoga: 065f0b74dba4832d6e328238de46eb72c5de9556

Expand Down
35 changes: 35 additions & 0 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,38 @@ test("remote attachments should work", async () => {
}
return true;
});

test("can send read receipts", async () => {
const bob = await XMTP.Client.createRandom({ env: "local" });
await delayToPropogate();
const alice = await XMTP.Client.createRandom({ env: "local" });
await delayToPropogate();
if (bob.address === alice.address) {
throw new Error("bob and alice should be different");
}

const bobConversation = await bob.conversations.newConversation(
alice.address
);
await delayToPropogate();

const aliceConversation = (await alice.conversations.list())[0];
if (!aliceConversation) {
throw new Error("aliceConversation should exist");
}

await bobConversation.send({ readReceipt: {}});

const bobMessages = await bobConversation.messages();

if (bobMessages.length < 1) {
throw Error("No message");
}

if (bobMessages[0].contentTypeId !== "xmtp.org/readReceipt:1.0") {
throw Error("Unexpected message content " + bobMessages[0].content);
}

return true;
});

7 changes: 6 additions & 1 deletion ios/Wrappers/DecodedMessageWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ struct ContentJson {
ReactionCodec(),
AttachmentCodec(),
ReplyCodec(),
RemoteAttachmentCodec()
RemoteAttachmentCodec(),
ReadReceiptCodec()
// TODO:
//CompositeCodec(),
]
Expand Down Expand Up @@ -102,6 +103,8 @@ struct ContentJson {
content.filename = metadata.filename
content.contentLength = metadata.contentLength
return ContentJson(type: ContentTypeRemoteAttachment, content: content)
} else if let readReceipt = obj["readReceipt"] as? [String: Any] {
return ContentJson(type: ContentTypeReadReceipt, content: ReadReceipt())
} else {
throw Error.unknownContentType
}
Expand Down Expand Up @@ -151,6 +154,8 @@ struct ContentJson {
"scheme": "https://",
"url": remoteAttachment.url
]]
case ContentTypeReadReceipt.id where content is XMTP.ReadReceipt:
return ["readReceipt": ""]
default:
return ["unknown": ["contentTypeId": type.description]]
}
Expand Down
2 changes: 1 addition & 1 deletion ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Pod::Spec.new do |s|

s.source_files = "**/*.{h,m,swift}"
s.dependency "MessagePacker"
s.dependency "XMTP", "= 0.5.4-alpha0"
s.dependency "XMTP", "= 0.5.7-alpha0"
end
3 changes: 3 additions & 0 deletions src/XMTP.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export type UnknownContent = {
contentTypeId: string;
};

export type ReadReceiptContent = object;

export type ReplyContent = {
reference: string;
content: MessageContent;
Expand Down Expand Up @@ -84,6 +86,7 @@ export type MessageContent = {
reaction?: ReactionContent;
attachment?: StaticAttachmentContent;
remoteAttachment?: RemoteAttachmentContent;
readReceipt?: ReadReceiptContent;
};

export type DecodedMessage = {
Expand Down

0 comments on commit 9b91a9a

Please sign in to comment.