diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ffb7a7d3..f8b26f14 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,7 +21,7 @@ jobs: java-version: '17' - name: Gradle Run ktlint run: ./gradlew ktlintCheck --continue - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 name: Upload ktlint report if: ${{ failure() }} with: @@ -30,7 +30,7 @@ jobs: - name: Gradle Android lint library run: ./gradlew :library:lintDebug - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 name: Upload library lint report if: ${{ failure() }} with: diff --git a/library/src/main/java/org/xmtp/android/library/Client.kt b/library/src/main/java/org/xmtp/android/library/Client.kt index 64e6215f..64a92ad1 100644 --- a/library/src/main/java/org/xmtp/android/library/Client.kt +++ b/library/src/main/java/org/xmtp/android/library/Client.kt @@ -315,7 +315,7 @@ class Client() { fun findGroup(groupId: String): Group? { return try { - Group(this.inboxId, ffiClient.conversation(groupId.hexToByteArray())) + Group(this, ffiClient.conversation(groupId.hexToByteArray())) } catch (e: Exception) { null } @@ -325,8 +325,8 @@ class Client() { return try { val conversation = ffiClient.conversation(conversationId.hexToByteArray()) when (conversation.conversationType()) { - FfiConversationType.GROUP -> Conversation.Group(Group(this.inboxId, conversation)) - FfiConversationType.DM -> Conversation.Dm(Dm(this.inboxId, conversation)) + FfiConversationType.GROUP -> Conversation.Group(Group(this, conversation)) + FfiConversationType.DM -> Conversation.Dm(Dm(this, conversation)) else -> null } } catch (e: Exception) { @@ -341,8 +341,8 @@ class Client() { return try { val conversation = ffiClient.conversation(conversationId.hexToByteArray()) when (conversation.conversationType()) { - FfiConversationType.GROUP -> Conversation.Group(Group(this.inboxId, conversation)) - FfiConversationType.DM -> Conversation.Dm(Dm(this.inboxId, conversation)) + FfiConversationType.GROUP -> Conversation.Group(Group(this, conversation)) + FfiConversationType.DM -> Conversation.Dm(Dm(this, conversation)) else -> null } } catch (e: Exception) { @@ -352,7 +352,7 @@ class Client() { fun findDmByInboxId(inboxId: String): Dm? { return try { - Dm(this.inboxId, ffiClient.dmConversation(inboxId)) + Dm(this, ffiClient.dmConversation(inboxId)) } catch (e: Exception) { null } diff --git a/library/src/main/java/org/xmtp/android/library/Conversation.kt b/library/src/main/java/org/xmtp/android/library/Conversation.kt index 7eb756c6..a1156449 100644 --- a/library/src/main/java/org/xmtp/android/library/Conversation.kt +++ b/library/src/main/java/org/xmtp/android/library/Conversation.kt @@ -154,6 +154,14 @@ sealed class Conversation { } } + val client: Client + get() { + return when (this) { + is Group -> group.client + is Dm -> dm.client + } + } + fun streamMessages(): Flow { return when (this) { is Group -> group.streamMessages() diff --git a/library/src/main/java/org/xmtp/android/library/Conversations.kt b/library/src/main/java/org/xmtp/android/library/Conversations.kt index 72d4cb78..27355ff5 100644 --- a/library/src/main/java/org/xmtp/android/library/Conversations.kt +++ b/library/src/main/java/org/xmtp/android/library/Conversations.kt @@ -43,8 +43,8 @@ data class Conversations( suspend fun fromWelcome(envelopeBytes: ByteArray): Conversation { val conversation = ffiConversations.processStreamedWelcomeMessage(envelopeBytes) return when (conversation.conversationType()) { - FfiConversationType.DM -> Conversation.Dm(Dm(client.inboxId, conversation)) - else -> Conversation.Group(Group(client.inboxId, conversation)) + FfiConversationType.DM -> Conversation.Dm(Dm(client, conversation)) + else -> Conversation.Group(Group(client, conversation)) } } @@ -123,7 +123,7 @@ data class Conversations( messageDisappearingSettings = messageDisappearingSettings ) ) - return Group(client.inboxId, group) + return Group(client, group) } suspend fun newGroupWithInboxIds( @@ -195,7 +195,7 @@ data class Conversations( messageDisappearingSettings = messageDisappearingSettings ) ) - return Group(client.inboxId, group) + return Group(client, group) } // Sync from the network the latest list of conversations @@ -227,7 +227,7 @@ data class Conversations( throw XMTPException("${falseAddresses.joinToString()} not on network") } val dmConversation = ffiConversations.findOrCreateDm(peerAddress.lowercase()) - return Dm(client.inboxId, dmConversation) + return Dm(client, dmConversation) } suspend fun newConversationWithInboxId(peerInboxId: String): Conversation { @@ -240,7 +240,7 @@ data class Conversations( throw XMTPException("Recipient is sender") } val dmConversation = ffiConversations.findOrCreateDmByInboxId(peerInboxId.lowercase()) - return Dm(client.inboxId, dmConversation) + return Dm(client, dmConversation) } fun listGroups( @@ -262,7 +262,7 @@ data class Conversations( ) return ffiGroups.map { - Group(client.inboxId, it.conversation(), it.lastMessage()) + Group(client, it.conversation(), it.lastMessage()) } } @@ -285,7 +285,7 @@ data class Conversations( ) return ffiDms.map { - Dm(client.inboxId, it.conversation(), it.lastMessage()) + Dm(client, it.conversation(), it.lastMessage()) } } @@ -314,13 +314,13 @@ data class Conversations( return when (conversation().conversationType()) { FfiConversationType.DM -> Conversation.Dm( Dm( - client.inboxId, + client, conversation(), lastMessage() ) ) - else -> Conversation.Group(Group(client.inboxId, conversation(), lastMessage())) + else -> Conversation.Group(Group(client, conversation(), lastMessage())) } } @@ -333,13 +333,13 @@ data class Conversations( FfiConversationType.DM -> trySend( Conversation.Dm( Dm( - client.inboxId, + client, conversation ) ) ) - else -> trySend(Conversation.Group(Group(client.inboxId, conversation))) + else -> trySend(Conversation.Group(Group(client, conversation))) } } } diff --git a/library/src/main/java/org/xmtp/android/library/Dm.kt b/library/src/main/java/org/xmtp/android/library/Dm.kt index af007e26..d69a4682 100644 --- a/library/src/main/java/org/xmtp/android/library/Dm.kt +++ b/library/src/main/java/org/xmtp/android/library/Dm.kt @@ -22,7 +22,7 @@ import uniffi.xmtpv3.FfiMessageCallback import uniffi.xmtpv3.FfiSubscribeException import java.util.Date -class Dm(private val clientInboxId: String, private val libXMTPGroup: FfiConversation, private val ffiLastMessage: FfiMessage? = null) { +class Dm(val client: Client, private val libXMTPGroup: FfiConversation, private val ffiLastMessage: FfiMessage? = null) { val id: String get() = libXMTPGroup.id().toHex() @@ -172,7 +172,7 @@ class Dm(private val clientInboxId: String, private val libXMTPGroup: FfiConvers } suspend fun isCreator(): Boolean { - return metadata().creatorInboxId() == clientInboxId + return metadata().creatorInboxId() == client.inboxId } suspend fun members(): List { diff --git a/library/src/main/java/org/xmtp/android/library/Group.kt b/library/src/main/java/org/xmtp/android/library/Group.kt index 3c60ae69..776b2617 100644 --- a/library/src/main/java/org/xmtp/android/library/Group.kt +++ b/library/src/main/java/org/xmtp/android/library/Group.kt @@ -29,7 +29,7 @@ import uniffi.xmtpv3.FfiSubscribeException import java.util.Date class Group( - private val clientInboxId: String, + val client: Client, private val libXMTPGroup: FfiConversation, private val ffiLastMessage: FfiMessage? = null, ) { @@ -215,7 +215,7 @@ class Group( } suspend fun isCreator(): Boolean { - return metadata().creatorInboxId() == clientInboxId + return metadata().creatorInboxId() == client.inboxId } suspend fun addMembers(addresses: List) { @@ -256,7 +256,7 @@ class Group( suspend fun peerInboxIds(): List { val ids = members().map { it.inboxId }.toMutableList() - ids.remove(clientInboxId) + ids.remove(client.inboxId) return ids }