Skip to content

Commit

Permalink
add method for getting all topics even for duplicate dms
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jan 8, 2025
1 parent 9c2ec6c commit 4d3f435
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions example/src/main/java/org/xmtp/android/example/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class MainViewModel : ViewModel() {
viewModelScope.launch(Dispatchers.IO) {
val listItems = mutableListOf<MainListItem>()
try {
val conversations = ClientManager.client.conversations.list()
val subscriptions = conversations.map {
val conversations = ClientManager.client.conversations
val subscriptions = conversations.allTopics().map {
val hmacKeysResult = ClientManager.client.conversations.getHmacKeys()
val hmacKeys = hmacKeysResult.hmacKeysMap
val result = hmacKeys[it.topic]?.valuesList?.map { hmacKey ->
val result = hmacKeys[it]?.valuesList?.map { hmacKey ->
Service.Subscription.HmacKey.newBuilder().also { sub_key ->
sub_key.key = hmacKey.hmacKey
sub_key.thirtyDayPeriodsSinceEpoch = hmacKey.thirtyDayPeriodsSinceEpoch
Expand All @@ -58,7 +58,7 @@ class MainViewModel : ViewModel() {

Service.Subscription.newBuilder().also { sub ->
sub.addAllHmacKeys(result)
sub.topic = it.topic
sub.topic = it
sub.isSilent = false
}.build()
}.toMutableList()
Expand All @@ -71,7 +71,7 @@ class MainViewModel : ViewModel() {

PushNotificationTokenManager.xmtpPush.subscribeWithMetadata(subscriptions)
listItems.addAll(
conversations.map { conversation ->
conversations.list().map { conversation ->
val lastMessage = fetchMostRecentMessage(conversation)
MainListItem.ConversationItem(
id = conversation.topic,
Expand Down
13 changes: 13 additions & 0 deletions library/src/main/java/org/xmtp/android/library/Conversations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,17 @@ data class Conversations(
}
return hmacKeysResponse.build()
}

fun allTopics(): List<String> {
val conversations = ffiConversations.list(
FfiListConversationsOptions(
null,
null,
null,
null,
includeDuplicateDms = true
)
)
return conversations.map { Topic.groupMessage(it.conversation().id().toHex()).description }
}
}

0 comments on commit 4d3f435

Please sign in to comment.