Skip to content

Commit c7d5e46

Browse files
committed
DROID-4115 fixes
1 parent aaf0641 commit c7d5e46

File tree

3 files changed

+80
-12
lines changed

3 files changed

+80
-12
lines changed

app/src/main/java/com/anytypeio/anytype/ui/chats/ChatFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class ChatFragment : Fragment() {
331331
),
332332
spaceIconView = spaceIconView,
333333
onSave = { newName ->
334-
// TODO: Implement save logic in ViewModel
334+
vm.onChatInfoSaved(newName)
335335
showChatInfoScreen = false
336336
chatInfoData = null
337337
},

feature-chats/src/main/java/com/anytypeio/anytype/feature_chats/presentation/ChatViewModel.kt

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.anytypeio.anytype.core_models.ext.EMPTY_STRING_VALUE
2323
import com.anytypeio.anytype.core_models.multiplayer.SpaceAccessType
2424
import com.anytypeio.anytype.core_models.multiplayer.SpaceInviteLinkAccessLevel
2525
import com.anytypeio.anytype.core_models.multiplayer.SpaceMemberPermissions
26+
import com.anytypeio.anytype.core_models.multiplayer.SpaceUxType
2627
import com.anytypeio.anytype.core_models.primitives.Space
2728
import com.anytypeio.anytype.core_models.primitives.SpaceId
2829
import com.anytypeio.anytype.core_models.syncStatus
@@ -51,6 +52,7 @@ import com.anytypeio.anytype.domain.multiplayer.SpaceViewSubscriptionContainer
5152
import com.anytypeio.anytype.domain.multiplayer.UserPermissionProvider
5253
import com.anytypeio.anytype.domain.notifications.NotificationBuilder
5354
import com.anytypeio.anytype.domain.`object`.GetObject
55+
import com.anytypeio.anytype.domain.`object`.SetObjectDetails
5456
import com.anytypeio.anytype.domain.objects.CreateObjectFromUrl
5557
import com.anytypeio.anytype.domain.objects.ObjectWatcher
5658
import com.anytypeio.anytype.domain.objects.SetObjectListIsArchived
@@ -129,7 +131,8 @@ class ChatViewModel @Inject constructor(
129131
private val spaceInviteLinkStore: SpaceInviteLinkStore,
130132
private val getCurrentInviteAccessLevel: GetCurrentInviteAccessLevel,
131133
private val pinObjectAsWidgetDelegate: PinObjectAsWidgetDelegate,
132-
private val setObjectListIsArchived: SetObjectListIsArchived
134+
private val setObjectListIsArchived: SetObjectListIsArchived,
135+
private val setObjectDetails: SetObjectDetails
133136
) : BaseViewModel(),
134137
ExitToVaultDelegate by exitToVaultDelegate,
135138
PinObjectAsWidgetDelegate by pinObjectAsWidgetDelegate {
@@ -197,15 +200,40 @@ class ChatViewModel @Inject constructor(
197200
spaceViews
198201
.observe(
199202
vmParams.space
200-
).map { view ->
203+
).collect { view ->
201204
val isMuted = NotificationStateCalculator.calculateMutedState(view)
202-
HeaderView.Default(
203-
title = view.name.orEmpty(),
204-
icon = view.spaceIcon(builder = urlBuilder),
205-
isMuted = isMuted
206-
)
207-
}.collect {
208-
header.value = it
205+
206+
if (view.spaceUxType == SpaceUxType.CHAT) {
207+
// For chat spaces, use space name and icon
208+
header.value = HeaderView.Default(
209+
title = view.name.orEmpty(),
210+
icon = view.spaceIcon(builder = urlBuilder),
211+
isMuted = isMuted
212+
)
213+
} else {
214+
// For non-chat spaces, fetch the object name
215+
getObject.async(
216+
GetObject.Params(
217+
target = vmParams.ctx,
218+
space = vmParams.space
219+
)
220+
).onSuccess { objectView ->
221+
val wrapper = ObjectWrapper.Basic(objectView.details[vmParams.ctx].orEmpty())
222+
header.value = HeaderView.Default(
223+
title = wrapper.name.orEmpty(),
224+
icon = view.spaceIcon(builder = urlBuilder),
225+
isMuted = isMuted
226+
)
227+
}.onFailure {
228+
Timber.e(it, "Failed to fetch object for chat header")
229+
// Fallback to space name
230+
header.value = HeaderView.Default(
231+
title = view.name.orEmpty(),
232+
icon = view.spaceIcon(builder = urlBuilder),
233+
isMuted = isMuted
234+
)
235+
}
236+
}
209237
}
210238
}
211239

@@ -1559,6 +1587,43 @@ class ChatViewModel @Inject constructor(
15591587
// TODO: Implement copy link functionality
15601588
}
15611589

1590+
fun onChatInfoSaved(newName: String) {
1591+
viewModelScope.launch {
1592+
val spaceView = spaceViews.get(vmParams.space)
1593+
if (spaceView == null) {
1594+
Timber.e("Space view not available")
1595+
sendToast("Failed to update chat name")
1596+
return@launch
1597+
}
1598+
1599+
val targetId = if (spaceView.spaceUxType == SpaceUxType.CHAT) {
1600+
// For chat spaces, update the space view object
1601+
spaceView.id
1602+
} else {
1603+
// For non-chat spaces, update the chat object
1604+
vmParams.ctx
1605+
}
1606+
1607+
setObjectDetails.async(
1608+
SetObjectDetails.Params(
1609+
ctx = targetId,
1610+
details = mapOf(Relations.NAME to newName)
1611+
)
1612+
).onSuccess {
1613+
Timber.d("Successfully updated chat name to: $newName")
1614+
// Update local state
1615+
val currentHeader = header.value
1616+
if (currentHeader is HeaderView.Default) {
1617+
header.value = currentHeader.copy(title = newName)
1618+
}
1619+
sendToast("Chat name updated")
1620+
}.onFailure { e ->
1621+
Timber.e(e, "Error while updating chat name")
1622+
sendToast("Failed to update chat name")
1623+
}
1624+
}
1625+
}
1626+
15621627
fun onMoveToBin() {
15631628
showMoveToBinDialog.value = true
15641629
}

feature-chats/src/main/java/com/anytypeio/anytype/feature_chats/presentation/ChatViewModelFactory.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.anytypeio.anytype.domain.multiplayer.UserPermissionProvider
2323
import com.anytypeio.anytype.domain.notifications.NotificationBuilder
2424
import com.anytypeio.anytype.domain.`object`.GetObject
2525
import com.anytypeio.anytype.domain.objects.CreateObjectFromUrl
26+
import com.anytypeio.anytype.domain.`object`.SetObjectDetails
2627
import com.anytypeio.anytype.domain.objects.ObjectWatcher
2728
import com.anytypeio.anytype.domain.objects.SetObjectListIsArchived
2829
import com.anytypeio.anytype.domain.objects.StoreOfObjectTypes
@@ -65,7 +66,8 @@ class ChatViewModelFactory @Inject constructor(
6566
private val spaceInviteLinkStore: SpaceInviteLinkStore,
6667
private val getCurrentInviteAccessLevel: GetCurrentInviteAccessLevel,
6768
private val pinObjectAsWidgetDelegate: PinObjectAsWidgetDelegate,
68-
private val setObjectListIsArchived: SetObjectListIsArchived
69+
private val setObjectListIsArchived: SetObjectListIsArchived,
70+
private val setObjectDetails: SetObjectDetails
6971
) : ViewModelProvider.Factory {
7072
@Suppress("UNCHECKED_CAST")
7173
override fun <T : ViewModel> create(modelClass: Class<T>): T = ChatViewModel(
@@ -99,6 +101,7 @@ class ChatViewModelFactory @Inject constructor(
99101
spaceInviteLinkStore = spaceInviteLinkStore,
100102
getCurrentInviteAccessLevel = getCurrentInviteAccessLevel,
101103
pinObjectAsWidgetDelegate = pinObjectAsWidgetDelegate,
102-
setObjectListIsArchived = setObjectListIsArchived
104+
setObjectListIsArchived = setObjectListIsArchived,
105+
setObjectDetails = setObjectDetails
103106
) as T
104107
}

0 commit comments

Comments
 (0)