mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
Merge pull request #4318 from nextcloud/messgaes_grouped_wrong
group chat messages
This commit is contained in:
commit
ed3b92c718
@ -2666,11 +2666,10 @@ class ChatActivity :
|
|||||||
chatMessage.activeUser = conversationUser
|
chatMessage.activeUser = conversationUser
|
||||||
|
|
||||||
adapter?.let {
|
adapter?.let {
|
||||||
chatMessage.isGrouped = (
|
val previousChatMessage = adapter!!.items[1].item
|
||||||
it.isPreviousSameAuthor(chatMessage.actorId, -1) &&
|
if (previousChatMessage is ChatMessage) {
|
||||||
it.getSameAuthorLastMessagesCount(chatMessage.actorId) %
|
chatMessage.isGrouped = groupMessages(chatMessage, previousChatMessage)
|
||||||
GROUPED_MESSAGES_SAME_AUTHOR_THRESHOLD > 0
|
}
|
||||||
)
|
|
||||||
chatMessage.isOneToOneConversation =
|
chatMessage.isOneToOneConversation =
|
||||||
(currentConversation?.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL)
|
(currentConversation?.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL)
|
||||||
chatMessage.isFormerOneToOneConversation =
|
chatMessage.isFormerOneToOneConversation =
|
||||||
@ -2716,19 +2715,9 @@ class ChatActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun processMessagesNotFromTheFuture(chatMessageList: List<ChatMessage>) {
|
private fun processMessagesNotFromTheFuture(chatMessageList: List<ChatMessage>) {
|
||||||
var countGroupedMessages = 0
|
|
||||||
|
|
||||||
for (i in chatMessageList.indices) {
|
for (i in chatMessageList.indices) {
|
||||||
if (chatMessageList.size > i + 1) {
|
if (chatMessageList.size > i + 1) {
|
||||||
if (isSameDayNonSystemMessages(chatMessageList[i], chatMessageList[i + 1]) &&
|
chatMessageList[i].isGrouped = groupMessages(chatMessageList[i], chatMessageList[i + 1])
|
||||||
chatMessageList[i + 1].actorId == chatMessageList[i].actorId &&
|
|
||||||
countGroupedMessages < GROUPED_MESSAGES_THRESHOLD
|
|
||||||
) {
|
|
||||||
chatMessageList[i].isGrouped = true
|
|
||||||
countGroupedMessages++
|
|
||||||
} else {
|
|
||||||
countGroupedMessages = 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val chatMessage = chatMessageList[i]
|
val chatMessage = chatMessageList[i]
|
||||||
@ -2754,6 +2743,40 @@ class ChatActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun groupMessages(message1: ChatMessage, message2: ChatMessage): Boolean {
|
||||||
|
val message1IsSystem = message1.systemMessage.isNotEmpty()
|
||||||
|
val message2IsSystem = message2.systemMessage.isNotEmpty()
|
||||||
|
if (message1IsSystem != message2IsSystem) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message1.actorType == "bots" && message1.actorId != "changelog") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!message1IsSystem && (
|
||||||
|
(message1.actorType != message2.actorType) ||
|
||||||
|
(message2.actorId != message1.actorId)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
val timeDifference = dateUtils.getTimeDifferenceInSeconds(
|
||||||
|
message2.timestamp,
|
||||||
|
message1.timestamp
|
||||||
|
)
|
||||||
|
val isLessThan5Min = timeDifference > FIVE_MINUTES_IN_SECONDS
|
||||||
|
if (isSameDayMessages(message2, message1) &&
|
||||||
|
(message2.actorId == message1.actorId) &&
|
||||||
|
(!isLessThan5Min) &&
|
||||||
|
(message2.lastEditTimestamp == 0L || message1.lastEditTimestamp == 0L)
|
||||||
|
) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
private fun determinePreviousMessageIds(chatMessageList: List<ChatMessage>) {
|
private fun determinePreviousMessageIds(chatMessageList: List<ChatMessage>) {
|
||||||
var previousMessageId = NO_PREVIOUS_MESSAGE_ID
|
var previousMessageId = NO_PREVIOUS_MESSAGE_ID
|
||||||
for (i in chatMessageList.indices.reversed()) {
|
for (i in chatMessageList.indices.reversed()) {
|
||||||
@ -2840,6 +2863,10 @@ class ChatActivity :
|
|||||||
TextUtils.isEmpty(messageRight.systemMessage) &&
|
TextUtils.isEmpty(messageRight.systemMessage) &&
|
||||||
DateFormatter.isSameDay(messageLeft.createdAt, messageRight.createdAt)
|
DateFormatter.isSameDay(messageLeft.createdAt, messageRight.createdAt)
|
||||||
|
|
||||||
|
private fun isSameDayMessages(message1: ChatMessage, message2: ChatMessage): Boolean {
|
||||||
|
return DateFormatter.isSameDay(message1.createdAt, message2.createdAt)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onLoadMore(page: Int, totalItemsCount: Int) {
|
override fun onLoadMore(page: Int, totalItemsCount: Int) {
|
||||||
val id = (
|
val id = (
|
||||||
adapter?.items?.last {
|
adapter?.items?.last {
|
||||||
@ -3766,8 +3793,6 @@ class ChatActivity :
|
|||||||
private const val SEMI_TRANSPARENT_INT: Int = 99
|
private const val SEMI_TRANSPARENT_INT: Int = 99
|
||||||
private const val VOICE_MESSAGE_SEEKBAR_BASE = 1000
|
private const val VOICE_MESSAGE_SEEKBAR_BASE = 1000
|
||||||
private const val NO_PREVIOUS_MESSAGE_ID: Int = -1
|
private const val NO_PREVIOUS_MESSAGE_ID: Int = -1
|
||||||
private const val GROUPED_MESSAGES_THRESHOLD = 4
|
|
||||||
private const val GROUPED_MESSAGES_SAME_AUTHOR_THRESHOLD = 5
|
|
||||||
private const val TOOLBAR_AVATAR_RATIO = 1.5
|
private const val TOOLBAR_AVATAR_RATIO = 1.5
|
||||||
private const val STATUS_SIZE_IN_DP = 9f
|
private const val STATUS_SIZE_IN_DP = 9f
|
||||||
private const val HTTP_CODE_NOT_MODIFIED = 304
|
private const val HTTP_CODE_NOT_MODIFIED = 304
|
||||||
@ -3809,5 +3834,6 @@ class ChatActivity :
|
|||||||
private const val CURRENT_AUDIO_WAS_PLAYING_KEY = "CURRENT_AUDIO_PLAYING"
|
private const val CURRENT_AUDIO_WAS_PLAYING_KEY = "CURRENT_AUDIO_PLAYING"
|
||||||
private const val RESUME_AUDIO_TAG = "RESUME_AUDIO_TAG"
|
private const val RESUME_AUDIO_TAG = "RESUME_AUDIO_TAG"
|
||||||
private const val DELAY_TO_SHOW_PROGRESS_BAR = 1000L
|
private const val DELAY_TO_SHOW_PROGRESS_BAR = 1000L
|
||||||
|
private const val FIVE_MINUTES_IN_SECONDS: Long = 300
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import com.nextcloud.talk.R
|
|||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
import kotlin.math.abs
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
class DateUtils(val context: Context) {
|
class DateUtils(val context: Context) {
|
||||||
@ -50,6 +51,11 @@ class DateUtils(val context: Context) {
|
|||||||
return formatTime.format(Date(timestampSeconds * DateConstants.SECOND_DIVIDER))
|
return formatTime.format(Date(timestampSeconds * DateConstants.SECOND_DIVIDER))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getTimeDifferenceInSeconds(time2: Long, time1: Long): Long {
|
||||||
|
val difference = (time2 - time1)
|
||||||
|
return abs(difference)
|
||||||
|
}
|
||||||
|
|
||||||
fun relativeStartTimeForLobby(timestampMilliseconds: Long, resources: Resources): String {
|
fun relativeStartTimeForLobby(timestampMilliseconds: Long, resources: Resources): String {
|
||||||
val fmt = RelativeDateTimeFormatter.getInstance()
|
val fmt = RelativeDateTimeFormatter.getInstance()
|
||||||
val timeLeftMillis = timestampMilliseconds - System.currentTimeMillis()
|
val timeLeftMillis = timestampMilliseconds - System.currentTimeMillis()
|
||||||
|
Loading…
Reference in New Issue
Block a user