Skip to content

Commit

Permalink
Revert "remove client from serializable objects" (#372)
Browse files Browse the repository at this point in the history
* Revert "remove client from serializable objects"

This reverts commit 46765c4.

* fix github action
  • Loading branch information
nplasterer authored Feb 3, 2025
1 parent 65be7d1 commit 7627c87
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Message> {
return when (this) {
is Group -> group.streamMessages()
Expand Down
24 changes: 12 additions & 12 deletions library/src/main/java/org/xmtp/android/library/Conversations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ data class Conversations(
messageDisappearingSettings = messageDisappearingSettings
)
)
return Group(client.inboxId, group)
return Group(client, group)
}

suspend fun newGroupWithInboxIds(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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(
Expand All @@ -262,7 +262,7 @@ data class Conversations(
)

return ffiGroups.map {
Group(client.inboxId, it.conversation(), it.lastMessage())
Group(client, it.conversation(), it.lastMessage())
}
}

Expand All @@ -285,7 +285,7 @@ data class Conversations(
)

return ffiDms.map {
Dm(client.inboxId, it.conversation(), it.lastMessage())
Dm(client, it.conversation(), it.lastMessage())
}
}

Expand Down Expand Up @@ -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()))
}
}

Expand All @@ -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)))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/org/xmtp/android/library/Dm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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<Member> {
Expand Down
6 changes: 3 additions & 3 deletions library/src/main/java/org/xmtp/android/library/Group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down Expand Up @@ -215,7 +215,7 @@ class Group(
}

suspend fun isCreator(): Boolean {
return metadata().creatorInboxId() == clientInboxId
return metadata().creatorInboxId() == client.inboxId
}

suspend fun addMembers(addresses: List<String>) {
Expand Down Expand Up @@ -256,7 +256,7 @@ class Group(

suspend fun peerInboxIds(): List<String> {
val ids = members().map { it.inboxId }.toMutableList()
ids.remove(clientInboxId)
ids.remove(client.inboxId)
return ids
}

Expand Down

0 comments on commit 7627c87

Please sign in to comment.