This commit is contained in:
Avently
2025-01-10 15:21:51 +07:00
parent 7ba0c189b4
commit 3fabeef49f
6 changed files with 99 additions and 31 deletions

View File

@@ -393,6 +393,13 @@ object ChatModel {
}
}
fun updateChatStats(rhId: Long?, chatId: ChatId, chatStats: Chat.ChatStats) {
val i = getChatIndex(rhId, chatId)
if (i >= 0) {
chats[i] = chats[i].copy(chatStats = chatStats)
}
}
suspend fun updateContactConnection(rhId: Long?, contactConnection: PendingContactConnection) = updateChat(rhId, ChatInfo.ContactConnection(contactConnection))
suspend fun updateContact(rhId: Long?, contact: Contact) = updateChat(rhId, ChatInfo.Direct(contact), addMissing = contact.directOrUsed)
@@ -792,6 +799,20 @@ object ChatModel {
changeUnreadCounterNoContentTag(rhId, user, -by)
}
fun decreaseGroupReportsCounter(rhId: Long?, chatId: ChatId, wasArchived: Boolean) {
return
val i = getChatIndex(rhId, chatId)
if (i >= 0) {
val chat = chats.value[i]
chats[i] = chat.copy(
chatStats = chat.chatStats.copy(
reportsCount = (chat.chatStats.reportsCount - 1).coerceAtLeast(0),
archivedReportsCount = if (wasArchived) chat.chatStats.archivedReportsCount + 1 else chat.chatStats.archivedReportsCount
)
)
}
}
private fun changeUnreadCounterNoContentTag(rhId: Long?, user: UserLike, by: Int) {
// updates anything only in main ChatView, not GroupReportsView or anything else from the future
if (contentTag != null) return

View File

@@ -2481,7 +2481,7 @@ object ChatController {
addChatItem(rhId, cInfo, cItem)
}
withReportsChatsIfOpen {
if (cItem.content.msgContent is MsgContent.MCReport) {
if (cItem.isReport) {
addChatItem(rhId, cInfo, cItem)
}
}
@@ -2512,7 +2512,7 @@ object ChatController {
updateChatItem(cInfo, cItem, status = cItem.meta.itemStatus)
}
withReportsChatsIfOpen {
if (cItem.content.msgContent is MsgContent.MCReport) {
if (cItem.isReport) {
updateChatItem(cInfo, cItem, status = cItem.meta.itemStatus)
}
}
@@ -2526,7 +2526,7 @@ object ChatController {
updateChatItem(r.reaction.chatInfo, r.reaction.chatReaction.chatItem)
}
withReportsChatsIfOpen {
if (r.reaction.chatReaction.chatItem.content.msgContent is MsgContent.MCReport) {
if (r.reaction.chatReaction.chatItem.isReport) {
updateChatItem(r.reaction.chatInfo, r.reaction.chatReaction.chatItem)
}
}
@@ -2568,7 +2568,7 @@ object ChatController {
}
}
withReportsChatsIfOpen {
if (cItem.content.msgContent is MsgContent.MCReport) {
if (cItem.isReport) {
if (toChatItem == null) {
removeChatItem(rhId, cInfo, cItem)
} else {
@@ -2603,12 +2603,17 @@ object ChatController {
generalGetString(MR.strings.marked_deleted_description)
)
}
val deleted = if (r.member_ != null && (cItem.chatDir as CIDirection.GroupRcv?)?.groupMember != r.member_) {
val wasModerated = r.member_ != null && (cItem.chatDir as CIDirection.GroupRcv?)?.groupMember != r.member_
val deleted = if (wasModerated && r.member_ != null) {
CIDeleted.Moderated(Clock.System.now(), r.member_)
} else {
CIDeleted.Deleted(Clock.System.now())
}
upsertChatItem(rhId, cInfo, cItem.copy(meta = cItem.meta.copy(itemDeleted = deleted)))
val isActiveReport = cItem.isReport && !cItem.isDeletedContent && cItem.meta.itemDeleted == null
if (isActiveReport) {
decreaseGroupReportsCounter(rhId, cInfo.id, wasModerated)
}
}
}
withReportsChatsIfOpen {
@@ -3102,7 +3107,7 @@ object ChatController {
val cItem = aChatItem.chatItem
withChats { upsertChatItem(rh, cInfo, cItem) }
withReportsChatsIfOpen {
if (cItem.content.msgContent is MsgContent.MCReport) {
if (cItem.isReport) {
upsertChatItem(rh, cInfo, cItem)
}
}
@@ -5953,7 +5958,7 @@ sealed class CR {
is ChatRunning -> noDetails()
is ChatStopped -> noDetails()
is ApiChats -> withUser(user, json.encodeToString(chats))
is ApiChat -> withUser(user, "chat: ${json.encodeToString(chat)}\nnavInfo: ${navInfo}")
is ApiChat -> withUser(user, "remoteHostId: ${chat.remoteHostId}\nchatInfo: ${chat.chatInfo}\nchatStats: ${chat.chatStats}\nnavInfo: ${navInfo}\nchatItems: ${chat.chatItems}")
is ChatTags -> withUser(user, "userTags: ${json.encodeToString(userTags)}")
is ApiChatItemInfo -> withUser(user, "chatItem: ${json.encodeToString(chatItem)}\n${json.encodeToString(chatItemInfo)}")
is ServerTestResult -> withUser(user, "server: $testServer\nresult: ${json.encodeToString(testFailure)}")

View File

@@ -44,11 +44,15 @@ suspend fun apiLoadMessages(
when (pagination) {
is ChatPagination.Initial -> {
val newSplits = if (chat.chatItems.isNotEmpty() && navInfo.afterTotal > 0) listOf(chat.chatItems.last().id) else emptyList()
withChats(contentTag) {
if (getChat(chat.id) == null) {
addChat(chat)
} else {
updateChatInfo(chat.remoteHostId, chat.chatInfo)
if (contentTag == null) {
// update main chats, not content tagged
withChats {
if (getChat(chat.id) == null) {
addChat(chat)
} else {
updateChatInfo(chat.remoteHostId, chat.chatInfo)
updateChatStats(chat.remoteHostId, chat.id, chat.chatStats)
}
}
}
withChats(contentTag) {

View File

@@ -397,9 +397,14 @@ fun ChatView(
} else {
removeChatItem(chatRh, chatInfo, deletedChatItem)
}
val deletedItem = deleted.deletedChatItem.chatItem
val isActiveReport = deletedItem.isReport == true && !deletedItem.isDeletedContent && deletedItem.meta.itemDeleted == null
if (isActiveReport) {
decreaseGroupReportsCounter(chatRh, chatInfo.id, toChatItem != null)
}
}
withReportsChatsIfOpen {
if (deletedChatItem.content.msgContent is MsgContent.MCReport) {
if (deletedChatItem.isReport) {
if (toChatItem != null) {
upsertChatItem(chatRh, chatInfo, toChatItem)
} else {
@@ -520,7 +525,7 @@ fun ChatView(
updateChatItem(cInfo, updatedCI)
}
withReportsChatsIfOpen {
if (cItem.content.msgContent is MsgContent.MCReport) {
if (cItem.isReport) {
updateChatItem(cInfo, updatedCI)
}
}
@@ -2322,17 +2327,22 @@ private fun deleteMessages(chatRh: Long?, chatInfo: ChatInfo, itemIds: List<Long
for (di in deleted) {
val toChatItem = di.toChatItem?.chatItem
if (toChatItem != null) {
if (toChatItem.content.msgContent is MsgContent.MCReport) {
if (toChatItem.isReport) {
upsertChatItem(chatRh, chatInfo, toChatItem)
}
} else {
removeChatItem(chatRh, chatInfo, di.deletedChatItem.chatItem)
}
val deletedItem = di.deletedChatItem.chatItem
val isActiveReport = deletedItem.isReport && !deletedItem.isDeletedContent && deletedItem.meta.itemDeleted == null
if (isActiveReport) {
decreaseGroupReportsCounter(chatRh, chatInfo.id, toChatItem != null)
}
}
}
withReportsChatsIfOpen {
for (di in deleted) {
if (di.deletedChatItem.chatItem.content.msgContent is MsgContent.MCReport) {
if (di.deletedChatItem.chatItem.isReport) {
val toChatItem = di.toChatItem?.chatItem
if (toChatItem != null) {
upsertChatItem(chatRh, chatInfo, toChatItem)

View File

@@ -90,21 +90,35 @@ fun GroupReportsAppBar(
offset = DpOffset(-width.value, if (oneHandUI.value) -height.value else AppBarHeight),
onClosed = onClosedAction
) {
ItemAction(stringResource(MR.strings.search_verb), painterResource(MR.images.ic_search), onClick = {
showMenu.value = false
showSearch.value = true
})
ItemAction(
if (groupReports.value.showArchived) stringResource(MR.strings.group_reports_show_active) else stringResource(MR.strings.group_reports_show_archived),
painterResource(if (groupReports.value.showArchived) MR.images.ic_flag else MR.images.ic_inventory_2),
onClick = {
onClosedAction.value = {
showArchived(!groupReports.value.showArchived)
onClosedAction.value = {}
}
@Composable
fun Search() {
ItemAction(stringResource(MR.strings.search_verb), painterResource(MR.images.ic_search), onClick = {
showMenu.value = false
}
)
showSearch.value = true
})
}
@Composable
fun ShowHideArchived() {
ItemAction(
if (groupReports.value.showArchived) stringResource(MR.strings.group_reports_show_active) else stringResource(MR.strings.group_reports_show_archived),
painterResource(if (groupReports.value.showArchived) MR.images.ic_flag else MR.images.ic_inventory_2),
onClick = {
onClosedAction.value = {
showArchived(!groupReports.value.showArchived)
onClosedAction.value = {}
}
showMenu.value = false
}
)
}
if (oneHandUI.value) {
ShowHideArchived()
Search()
} else {
Search()
ShowHideArchived()
}
}
}
ItemsReload(groupReports)
@@ -133,4 +147,4 @@ private suspend fun reloadItems(chat: Chat, groupReports: State<GroupReports>) {
} else {
openLoadedChat(chat.copy(chatItems = emptyList()), contentTag = contentFilter?.mcTag)
}
}
}

View File

@@ -322,6 +322,8 @@ fun ChatPreviewView(
} else if (cInfo is ChatInfo.Group) {
if (progressByTimeout) {
progressView()
} else if (chat.chatStats.reportsCount > 0) {
GroupReportsIcon()
} else {
IncognitoIcon(chat.chatInfo.incognito)
}
@@ -469,6 +471,18 @@ fun IncognitoIcon(incognito: Boolean) {
}
}
@Composable
fun GroupReportsIcon() {
Icon(
painterResource(MR.images.ic_flag),
contentDescription = null,
tint = MaterialTheme.colors.error,
modifier = Modifier
.size(21.sp.toDp())
.offset(x = 2.sp.toDp())
)
}
@Composable
private fun groupInvitationPreviewText(currentUserProfileDisplayName: String?, groupInfo: GroupInfo): String {
return if (groupInfo.membership.memberIncognito)