Compare commits

...

2 Commits

Author SHA1 Message Date
Avently 56b9d73234 adapt code 2024-08-01 17:22:21 +09:00
Avently acba0b4a7d android, desktop: chats context enhancements 2024-08-01 17:09:26 +09:00
4 changed files with 9 additions and 9 deletions
@@ -194,8 +194,8 @@ object ChatModel {
}
}
suspend fun <T> withChats(action: suspend ChatsContext.() -> T): T = updatingChatsMutex.withLock {
chatsContext.action()
suspend fun <T> withChats(action: suspend ChatsContext.(ChatsContext) -> T): T = updatingChatsMutex.withLock {
chatsContext.action(chatsContext)
}
class ChatsContext {
@@ -793,9 +793,9 @@ suspend fun save(applyToMode: DefaultThemeMode?, newTheme: ThemeModeOverride?, c
private fun setContactAlias(chat: Chat, localAlias: String, chatModel: ChatModel) = withBGApi {
val chatRh = chat.remoteHostId
chatModel.controller.apiSetContactAlias(chatRh, chat.chatInfo.apiId, localAlias)?.let {
chatModel.controller.apiSetContactAlias(chatRh, chat.chatInfo.apiId, localAlias)?.let { contact ->
withChats {
updateContact(chatRh, it)
updateContact(chatRh, contact)
}
}
}
@@ -69,12 +69,12 @@ fun GroupMemberInfoView(
developerTools,
connectionCode,
getContactChat = { chatModel.getContactChat(it) },
openDirectChat = {
openDirectChat = { contactId ->
withBGApi {
val c = chatModel.controller.apiGetChat(rhId, ChatType.Direct, it)
val c = chatModel.controller.apiGetChat(rhId, ChatType.Direct, contactId)
if (c != null) {
withChats {
if (chatModel.getContactChat(it) == null) {
if (chatModel.getContactChat(contactId) == null) {
addChat(c)
}
chatModel.chatItemStatuses.clear()
@@ -186,9 +186,9 @@ fun DeleteButton(onClick: () -> Unit) {
}
private fun setContactAlias(rhId: Long?, contactConnection: PendingContactConnection, localAlias: String, chatModel: ChatModel) = withBGApi {
chatModel.controller.apiSetConnectionAlias(rhId, contactConnection.pccConnId, localAlias)?.let {
chatModel.controller.apiSetConnectionAlias(rhId, contactConnection.pccConnId, localAlias)?.let { connection ->
withChats {
updateContactConnection(rhId, it)
updateContactConnection(rhId, connection)
}
}
}