-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added conv and group implement common interface. stream all
- Loading branch information
1 parent
8282ee2
commit 7ca505e
Showing
9 changed files
with
254 additions
and
11 deletions.
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/IConversationWrapper.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,47 @@ | ||
package expo.modules.xmtpreactnativesdk.wrappers | ||
|
||
import android.util.Base64 | ||
import com.google.gson.GsonBuilder | ||
import org.xmtp.android.library.Client | ||
import org.xmtp.android.library.Conversation | ||
|
||
class IConversationWrapper { | ||
|
||
companion object { | ||
fun encodeToObj(client: Client, conversation: Conversation): Map<String, Any> { | ||
when (conversation.version) { | ||
Conversation.Version.GROUP -> { | ||
return mapOf( | ||
"clientAddress" to client.address, | ||
"id" to conversation.topic, | ||
"createdAt" to conversation.createdAt.time, | ||
"peerAddresses" to conversation.peerAddresses, | ||
"version" to "group", | ||
"topic" to conversation.topic | ||
) | ||
} | ||
else -> { | ||
val context = when (conversation.version) { | ||
Conversation.Version.V2 -> mapOf<String, Any>( | ||
"conversationID" to (conversation.conversationId ?: ""), | ||
// TODO: expose the context/metadata explicitly in xmtp-android | ||
"metadata" to conversation.toTopicData().invitation.context.metadataMap, | ||
) | ||
|
||
else -> mapOf() | ||
} | ||
return mapOf( | ||
"clientAddress" to client.address, | ||
"createdAt" to conversation.createdAt.time, | ||
"context" to context, | ||
"topic" to conversation.topic, | ||
"peerAddress" to conversation.peerAddress, | ||
"version" to if (conversation.version == Conversation.Version.V1) "v1" else "v2", | ||
"conversationID" to (conversation.conversationId ?: ""), | ||
"keyMaterial" to Base64.encodeToString(conversation.keyMaterial, Base64.NO_WRAP) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ContentTypeId } from './types/ContentCodec' | ||
import { DefaultContentTypes } from './types/DefaultContentType' | ||
import * as XMTP from '../index' | ||
|
||
export type SendOptions = { | ||
contentType?: ContentTypeId | ||
} | ||
|
||
export enum ConversationVersion { | ||
V1 = 'v1', | ||
V2 = 'v2', | ||
GROUP = 'group', | ||
} | ||
|
||
export interface IConversation<ContentTypes extends DefaultContentTypes> { | ||
client: XMTP.Client<ContentTypes> | ||
createdAt: number | ||
version: ConversationVersion | ||
topic: string | ||
isGroup(): boolean | ||
} |