mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-23 15:03:16 +00:00
unneeded updates and fixes
This commit is contained in:
1 parent
443f35831b
commit
e873a323a7
8 files changed
+50
-94
No files matched your search
+35
-36
@@ -670,10 +670,10 @@ object ChatModel {
|
||||
|
||||
fun markChatItemsRead(remoteHostId: Long?, chatInfo: ChatInfo, itemIds: List<Long>? = null) {
|
||||
val cInfo = chatInfo
|
||||
val markedRead = markItemsReadInCurrentChat(chatInfo, contentTag, itemIds)
|
||||
val markedRead = markItemsReadInCurrentChat(chatInfo, itemIds)
|
||||
// update preview
|
||||
val chatIdx = getChatIndex(remoteHostId, cInfo.id)
|
||||
if (chatIdx >= 0) {
|
||||
if (chatIdx >= 0 && contentTag == null) {
|
||||
val chat = chats[chatIdx]
|
||||
val lastId = chat.chatItems.lastOrNull()?.id
|
||||
if (lastId != null) {
|
||||
@@ -688,6 +688,39 @@ object ChatModel {
|
||||
}
|
||||
}
|
||||
|
||||
private fun markItemsReadInCurrentChat(chatInfo: ChatInfo, itemIds: List<Long>? = null): Int {
|
||||
val cInfo = chatInfo
|
||||
var markedRead = 0
|
||||
if (chatId.value == cInfo.id) {
|
||||
val items = chatItems.value
|
||||
var i = items.lastIndex
|
||||
val itemIdsFromRange = itemIds?.toMutableSet() ?: mutableSetOf()
|
||||
val markedReadIds = mutableSetOf<Long>()
|
||||
while (i >= 0) {
|
||||
val item = items[i]
|
||||
if (item.meta.itemStatus is CIStatus.RcvNew && (itemIds == null || itemIdsFromRange.contains(item.id))) {
|
||||
val newItem = item.withStatus(CIStatus.RcvRead())
|
||||
items[i] = newItem
|
||||
if (newItem.meta.itemLive != true && newItem.meta.itemTimed?.ttl != null) {
|
||||
items[i] = newItem.copy(meta = newItem.meta.copy(itemTimed = newItem.meta.itemTimed.copy(
|
||||
deleteAt = Clock.System.now() + newItem.meta.itemTimed.ttl.toDuration(DurationUnit.SECONDS)))
|
||||
)
|
||||
}
|
||||
markedReadIds.add(item.id)
|
||||
markedRead++
|
||||
if (itemIds != null) {
|
||||
itemIdsFromRange.remove(item.id)
|
||||
// already set all needed items as read, can finish the loop
|
||||
if (itemIdsFromRange.isEmpty()) break
|
||||
}
|
||||
}
|
||||
i--
|
||||
}
|
||||
chatItemsChangesListener?.read(if (itemIds != null) markedReadIds else null, items)
|
||||
}
|
||||
return markedRead
|
||||
}
|
||||
|
||||
private fun decreaseCounterInChat(rhId: Long?, chatId: ChatId) {
|
||||
val chatIndex = getChatIndex(rhId, chatId)
|
||||
if (chatIndex == -1) return
|
||||
@@ -814,40 +847,6 @@ object ChatModel {
|
||||
}
|
||||
}
|
||||
|
||||
private fun markItemsReadInCurrentChat(chatInfo: ChatInfo, contentTag: MsgContentTag?, itemIds: List<Long>? = null): Int {
|
||||
val cInfo = chatInfo
|
||||
var markedRead = 0
|
||||
if (chatId.value == cInfo.id) {
|
||||
val items = chatItemsForContent(contentTag).value
|
||||
var i = items.lastIndex
|
||||
val itemIdsFromRange = itemIds?.toMutableSet() ?: mutableSetOf()
|
||||
val markedReadIds = mutableSetOf<Long>()
|
||||
while (i >= 0) {
|
||||
val item = items[i]
|
||||
if (item.meta.itemStatus is CIStatus.RcvNew && (itemIds == null || itemIdsFromRange.contains(item.id))) {
|
||||
val newItem = item.withStatus(CIStatus.RcvRead())
|
||||
items[i] = newItem
|
||||
if (newItem.meta.itemLive != true && newItem.meta.itemTimed?.ttl != null) {
|
||||
items[i] = newItem.copy(meta = newItem.meta.copy(itemTimed = newItem.meta.itemTimed.copy(
|
||||
deleteAt = Clock.System.now() + newItem.meta.itemTimed.ttl.toDuration(DurationUnit.SECONDS)))
|
||||
)
|
||||
}
|
||||
markedReadIds.add(item.id)
|
||||
markedRead++
|
||||
if (itemIds != null) {
|
||||
itemIdsFromRange.remove(item.id)
|
||||
// already set all needed items as read, can finish the loop
|
||||
if (itemIdsFromRange.isEmpty()) break
|
||||
}
|
||||
}
|
||||
i--
|
||||
}
|
||||
// TODO LALAL
|
||||
chatsContext.chatItemsChangesListener?.read(if (itemIds != null) markedReadIds else null, items)
|
||||
}
|
||||
return markedRead
|
||||
}
|
||||
|
||||
fun increaseUnreadCounter(rhId: Long?, user: UserLike) {
|
||||
changeUnreadCounter(rhId, user, 1)
|
||||
}
|
||||
|
||||
-12
@@ -2634,9 +2634,6 @@ object ChatController {
|
||||
withChats {
|
||||
updateGroup(rhId, r.groupInfo)
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
updateGroup(rhId, r.groupInfo)
|
||||
}
|
||||
}
|
||||
is CR.DeletedMember ->
|
||||
if (active(r.user)) {
|
||||
@@ -2688,9 +2685,6 @@ object ChatController {
|
||||
withChats {
|
||||
updateGroup(rhId, r.groupInfo)
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
updateGroup(rhId, r.groupInfo)
|
||||
}
|
||||
}
|
||||
is CR.UserJoinedGroup ->
|
||||
if (active(r.user)) {
|
||||
@@ -2719,9 +2713,6 @@ object ChatController {
|
||||
withChats {
|
||||
updateGroup(rhId, r.toGroup)
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
updateGroup(rhId, r.toGroup)
|
||||
}
|
||||
}
|
||||
is CR.NewMemberContactReceivedInv ->
|
||||
if (active(r.user)) {
|
||||
@@ -3052,9 +3043,6 @@ object ChatController {
|
||||
withChats {
|
||||
updateGroup(rh, groupInfo)
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
updateGroup(rh, groupInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-5
@@ -1251,11 +1251,6 @@ suspend fun save(applyToMode: DefaultThemeMode?, newTheme: ThemeModeOverride?, c
|
||||
updateChatInfo(chat.remoteHostId, chat.chatInfo.copy(groupInfo = chat.chatInfo.groupInfo.copy(uiThemes = changedThemes)))
|
||||
}
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
if (chat.chatInfo is ChatInfo.Group) {
|
||||
updateChatInfo(chat.remoteHostId, chat.chatInfo.copy(groupInfo = chat.chatInfo.groupInfo.copy(uiThemes = changedThemes)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-20
@@ -396,10 +396,12 @@ fun ChatView(
|
||||
}
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
if (toChatItem != null) {
|
||||
upsertChatItem(chatRh, chatInfo, toChatItem)
|
||||
} else {
|
||||
removeChatItem(chatRh, chatInfo, deletedChatItem)
|
||||
if (deletedChatItem.content.msgContent is MsgContent.MCReport) {
|
||||
if (toChatItem != null) {
|
||||
upsertChatItem(chatRh, chatInfo, toChatItem)
|
||||
} else {
|
||||
removeChatItem(chatRh, chatInfo, deletedChatItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -584,10 +586,7 @@ fun ChatView(
|
||||
)
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
// It's important to call it on Main thread. Otherwise, composable crash occurs from time-to-time without useful stacktrace
|
||||
withContext(Dispatchers.Main) {
|
||||
markChatItemsRead(chatRh, chatInfo, itemsIds)
|
||||
}
|
||||
markChatItemsRead(chatRh, chatInfo, itemsIds)
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -606,10 +605,7 @@ fun ChatView(
|
||||
)
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
// It's important to call it on Main thread. Otherwise, composable crash occurs from time-to-time without useful stacktrace
|
||||
withContext(Dispatchers.Main) {
|
||||
markChatItemsRead(chatRh, chatInfo)
|
||||
}
|
||||
markChatItemsRead(chatRh, chatInfo)
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -2291,11 +2287,13 @@ private fun deleteMessages(chatRh: Long?, chatInfo: ChatInfo, itemIds: List<Long
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
for (di in deleted) {
|
||||
val toChatItem = di.toChatItem?.chatItem
|
||||
if (toChatItem != null) {
|
||||
upsertChatItem(chatRh, chatInfo, toChatItem)
|
||||
} else {
|
||||
removeChatItem(chatRh, chatInfo, di.deletedChatItem.chatItem)
|
||||
if (di.deletedChatItem.chatItem.content.msgContent is MsgContent.MCReport) {
|
||||
val toChatItem = di.toChatItem?.chatItem
|
||||
if (toChatItem != null) {
|
||||
upsertChatItem(chatRh, chatInfo, toChatItem)
|
||||
} else {
|
||||
removeChatItem(chatRh, chatInfo, di.deletedChatItem.chatItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2321,9 +2319,6 @@ private fun markUnreadChatAsRead(chatId: String) {
|
||||
replaceChat(chatRh, chat.id, chat.copy(chatStats = chat.chatStats.copy(unreadChat = false)))
|
||||
markChatTagRead(chat)
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
replaceChat(chatRh, chat.id, chat.copy(chatStats = chat.chatStats.copy(unreadChat = false)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-3
@@ -43,9 +43,6 @@ fun GroupProfileView(rhId: Long?, groupInfo: GroupInfo, chatModel: ChatModel, cl
|
||||
withChats {
|
||||
updateGroup(rhId, gInfo)
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
updateGroup(rhId, gInfo)
|
||||
}
|
||||
close.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
-3
@@ -54,9 +54,6 @@ fun GroupWelcomeView(m: ChatModel, rhId: Long?, groupInfo: GroupInfo, close: ()
|
||||
withChats {
|
||||
updateGroup(rhId, res)
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
updateGroup(rhId, res)
|
||||
}
|
||||
welcomeText.value = welcome ?: ""
|
||||
}
|
||||
afterSave()
|
||||
|
||||
-9
@@ -593,9 +593,6 @@ fun markChatRead(c: Chat) {
|
||||
replaceChat(chat.remoteHostId, chat.id, chat.copy(chatStats = chat.chatStats.copy(unreadChat = false)))
|
||||
markChatTagRead(chat)
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
replaceChat(chat.remoteHostId, chat.id, chat.copy(chatStats = chat.chatStats.copy(unreadChat = false)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -618,9 +615,6 @@ fun markChatUnread(chat: Chat, chatModel: ChatModel) {
|
||||
replaceChat(chat.remoteHostId, chat.id, chat.copy(chatStats = chat.chatStats.copy(unreadChat = true)))
|
||||
updateChatTagRead(chat, wasUnread)
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
replaceChat(chat.remoteHostId, chat.id, chat.copy(chatStats = chat.chatStats.copy(unreadChat = true)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -876,9 +870,6 @@ fun updateChatSettings(remoteHostId: Long?, chatInfo: ChatInfo, chatSettings: Ch
|
||||
withChats {
|
||||
updateChatInfo(remoteHostId, newChatInfo)
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
updateChatInfo(remoteHostId, newChatInfo)
|
||||
}
|
||||
if (chatSettings.enableNtfs != MsgFilter.All) {
|
||||
ntfManager.cancelNotificationsForChat(chatInfo.id)
|
||||
}
|
||||
|
||||
-6
@@ -426,9 +426,6 @@ private fun setTag(rhId: Long?, tagId: Long?, chat: Chat, close: () -> Unit) {
|
||||
withChats {
|
||||
updateGroup(rhId, group)
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
updateGroup(rhId, group)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {}
|
||||
@@ -466,9 +463,6 @@ private fun deleteTag(rhId: Long?, tag: ChatTag, saving: MutableState<Boolean>)
|
||||
withChats {
|
||||
updateGroup(rhId, group)
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
updateGroup(rhId, group)
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user