-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #517 from xmtp/np/v3-only-dms
feat: V3 only dms
- Loading branch information
Showing
25 changed files
with
1,943 additions
and
319 deletions.
There are no files selected for viewing
363 changes: 300 additions & 63 deletions
363
android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt
Large diffs are not rendered by default.
Oops, something went wrong.
28 changes: 21 additions & 7 deletions
28
...id/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ConversationContainerWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DmWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package expo.modules.xmtpreactnativesdk.wrappers | ||
|
||
import com.google.gson.GsonBuilder | ||
import com.google.gson.JsonParser | ||
import expo.modules.xmtpreactnativesdk.wrappers.ConsentWrapper.Companion.consentStateToString | ||
import org.xmtp.android.library.Client | ||
import org.xmtp.android.library.Dm | ||
import org.xmtp.android.library.Group | ||
|
||
class DmWrapper { | ||
companion object { | ||
suspend fun encodeToObj( | ||
client: Client, | ||
dm: Dm, | ||
dmParams: ConversationParamsWrapper = ConversationParamsWrapper(), | ||
): Map<String, Any> { | ||
return buildMap { | ||
put("clientAddress", client.address) | ||
put("id", dm.id) | ||
put("createdAt", dm.createdAt.time) | ||
put("version", "DM") | ||
put("topic", dm.topic) | ||
put("peerInboxId", dm.peerInboxId()) | ||
if (dmParams.members) { | ||
put("members", dm.members().map { MemberWrapper.encode(it) }) | ||
} | ||
if (dmParams.creatorInboxId) put("creatorInboxId", dm.creatorInboxId()) | ||
if (dmParams.consentState) { | ||
put("consentState", consentStateToString(dm.consentState())) | ||
} | ||
if (dmParams.lastMessage) { | ||
val lastMessage = dm.decryptedMessages(limit = 1).firstOrNull() | ||
if (lastMessage != null) { | ||
put("lastMessage", DecodedMessageWrapper.encode(lastMessage)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
suspend fun encode( | ||
client: Client, | ||
dm: Dm, | ||
dmParams: ConversationParamsWrapper = ConversationParamsWrapper(), | ||
): String { | ||
val gson = GsonBuilder().create() | ||
val obj = encodeToObj(client, dm, dmParams) | ||
return gson.toJson(obj) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.