|
@@ -296,7 +296,6 @@ class ChatActivity :
|
|
var mentionAutocomplete: Autocomplete<*>? = null
|
|
var mentionAutocomplete: Autocomplete<*>? = null
|
|
var layoutManager: LinearLayoutManager? = null
|
|
var layoutManager: LinearLayoutManager? = null
|
|
var pullChatMessagesPending = false
|
|
var pullChatMessagesPending = false
|
|
- var newMessagesCount = 0
|
|
|
|
var startCallFromNotification: Boolean = false
|
|
var startCallFromNotification: Boolean = false
|
|
var startCallFromRoomSwitch: Boolean = false
|
|
var startCallFromRoomSwitch: Boolean = false
|
|
|
|
|
|
@@ -758,8 +757,8 @@ class ChatActivity :
|
|
|
|
|
|
removeUnreadMessagesMarker()
|
|
removeUnreadMessagesMarker()
|
|
|
|
|
|
- if (binding.unreadMessagesPopup.isShown == true) {
|
|
|
|
- binding.unreadMessagesPopup.hide()
|
|
|
|
|
|
+ if (binding.unreadMessagesPopup.isShown) {
|
|
|
|
+ binding.unreadMessagesPopup.visibility = View.GONE
|
|
}
|
|
}
|
|
binding.messagesListView.smoothScrollToPosition(0)
|
|
binding.messagesListView.smoothScrollToPosition(0)
|
|
}
|
|
}
|
|
@@ -770,8 +769,8 @@ class ChatActivity :
|
|
if (code.toString().startsWith("2")) {
|
|
if (code.toString().startsWith("2")) {
|
|
myFirstMessage = state.message
|
|
myFirstMessage = state.message
|
|
|
|
|
|
- if (binding.unreadMessagesPopup.isShown == true) {
|
|
|
|
- binding.unreadMessagesPopup.hide()
|
|
|
|
|
|
+ if (binding.unreadMessagesPopup.isShown) {
|
|
|
|
+ binding.unreadMessagesPopup.visibility = View.GONE
|
|
}
|
|
}
|
|
|
|
|
|
binding.messagesListView.smoothScrollToPosition(0)
|
|
binding.messagesListView.smoothScrollToPosition(0)
|
|
@@ -1016,7 +1015,7 @@ class ChatActivity :
|
|
}
|
|
}
|
|
|
|
|
|
private fun removeUnreadMessagesMarker() {
|
|
private fun removeUnreadMessagesMarker() {
|
|
- val index = adapter?.getMessagePositionById("-1")
|
|
|
|
|
|
+ val index = adapter?.getMessagePositionById(UNREAD_MESSAGES_MARKER_ID.toString())
|
|
if (index != null && index != -1) {
|
|
if (index != null && index != -1) {
|
|
adapter?.items?.removeAt(index)
|
|
adapter?.items?.removeAt(index)
|
|
}
|
|
}
|
|
@@ -1041,22 +1040,9 @@ class ChatActivity :
|
|
|
|
|
|
setupSwipeToReply()
|
|
setupSwipeToReply()
|
|
|
|
|
|
- binding.unreadMessagesPopup.setRecyclerView(binding.messagesListView)
|
|
|
|
-
|
|
|
|
- binding.unreadMessagesPopup.setPopupBubbleListener { _ ->
|
|
|
|
- if (newMessagesCount != 0) {
|
|
|
|
- val scrollPosition = if (newMessagesCount - 1 < 0) {
|
|
|
|
- 0
|
|
|
|
- } else {
|
|
|
|
- newMessagesCount - 1
|
|
|
|
- }
|
|
|
|
- Handler().postDelayed(
|
|
|
|
- {
|
|
|
|
- binding.messagesListView.smoothScrollToPosition(scrollPosition)
|
|
|
|
- },
|
|
|
|
- NEW_MESSAGES_POPUP_BUBBLE_DELAY
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
|
|
+ binding.unreadMessagesPopup.setOnClickListener {
|
|
|
|
+ binding.messagesListView.smoothScrollToPosition(0)
|
|
|
|
+ binding.unreadMessagesPopup.visibility = View.GONE
|
|
}
|
|
}
|
|
|
|
|
|
binding.scrollDownButton.setOnClickListener {
|
|
binding.scrollDownButton.setOnClickListener {
|
|
@@ -1075,21 +1061,14 @@ class ChatActivity :
|
|
super.onScrollStateChanged(recyclerView, newState)
|
|
super.onScrollStateChanged(recyclerView, newState)
|
|
|
|
|
|
if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
|
|
if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
|
|
- if (layoutManager!!.findFirstCompletelyVisibleItemPosition() > 0 &&
|
|
|
|
- !binding.unreadMessagesPopup.isShown
|
|
|
|
- ) {
|
|
|
|
- binding.scrollDownButton.visibility = View.VISIBLE
|
|
|
|
- } else {
|
|
|
|
|
|
+ if (isScrolledToBottom()) {
|
|
|
|
+ binding.unreadMessagesPopup.visibility = View.GONE
|
|
binding.scrollDownButton.visibility = View.GONE
|
|
binding.scrollDownButton.visibility = View.GONE
|
|
- }
|
|
|
|
-
|
|
|
|
- if (newMessagesCount != 0 && layoutManager != null) {
|
|
|
|
- if (layoutManager!!.findFirstCompletelyVisibleItemPosition() < newMessagesCount) {
|
|
|
|
- newMessagesCount = 0
|
|
|
|
-
|
|
|
|
- if (binding.unreadMessagesPopup.isShown) {
|
|
|
|
- binding.unreadMessagesPopup.hide()
|
|
|
|
- }
|
|
|
|
|
|
+ } else {
|
|
|
|
+ if (binding.unreadMessagesPopup.isShown) {
|
|
|
|
+ binding.scrollDownButton.visibility = View.GONE
|
|
|
|
+ } else {
|
|
|
|
+ binding.scrollDownButton.visibility = View.VISIBLE
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -2677,7 +2656,7 @@ class ChatActivity :
|
|
scrollToBottom = true
|
|
scrollToBottom = true
|
|
} else {
|
|
} else {
|
|
scrollToBottom = false
|
|
scrollToBottom = false
|
|
- binding.unreadMessagesPopup.show()
|
|
|
|
|
|
+ binding.unreadMessagesPopup.visibility = View.VISIBLE
|
|
// here we have the problem that the chat jumps for every update
|
|
// here we have the problem that the chat jumps for every update
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -2698,13 +2677,18 @@ class ChatActivity :
|
|
it.addToStart(chatMessage, scrollToBottom)
|
|
it.addToStart(chatMessage, scrollToBottom)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // workaround to jump back to unread messages marker
|
|
|
|
+ if (setUnreadMessagesMarker) {
|
|
|
|
+ scrollToFirstUnreadMessage()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private fun isScrolledToBottom() = layoutManager?.findFirstVisibleItemPosition() == 0
|
|
private fun isScrolledToBottom() = layoutManager?.findFirstVisibleItemPosition() == 0
|
|
|
|
|
|
private fun setUnreadMessageMarker(chatMessageList: List<ChatMessage>) {
|
|
private fun setUnreadMessageMarker(chatMessageList: List<ChatMessage>) {
|
|
val unreadChatMessage = ChatMessage()
|
|
val unreadChatMessage = ChatMessage()
|
|
- unreadChatMessage.jsonMessageId = -1
|
|
|
|
|
|
+ unreadChatMessage.jsonMessageId = UNREAD_MESSAGES_MARKER_ID
|
|
unreadChatMessage.actorId = "-1"
|
|
unreadChatMessage.actorId = "-1"
|
|
unreadChatMessage.timestamp = chatMessageList[0].timestamp
|
|
unreadChatMessage.timestamp = chatMessageList[0].timestamp
|
|
unreadChatMessage.message = context.getString(R.string.nc_new_messages)
|
|
unreadChatMessage.message = context.getString(R.string.nc_new_messages)
|
|
@@ -2736,7 +2720,7 @@ class ChatActivity :
|
|
|
|
|
|
private fun scrollToFirstUnreadMessage() {
|
|
private fun scrollToFirstUnreadMessage() {
|
|
adapter?.let {
|
|
adapter?.let {
|
|
- scrollToAndCenterMessageWithId("-1")
|
|
|
|
|
|
+ scrollToAndCenterMessageWithId(UNREAD_MESSAGES_MARKER_ID.toString())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -3552,7 +3536,7 @@ class ChatActivity :
|
|
CONTENT_TYPE_POLL -> message.isPoll()
|
|
CONTENT_TYPE_POLL -> message.isPoll()
|
|
CONTENT_TYPE_LINK_PREVIEW -> message.isLinkPreview()
|
|
CONTENT_TYPE_LINK_PREVIEW -> message.isLinkPreview()
|
|
CONTENT_TYPE_SYSTEM_MESSAGE -> !TextUtils.isEmpty(message.systemMessage)
|
|
CONTENT_TYPE_SYSTEM_MESSAGE -> !TextUtils.isEmpty(message.systemMessage)
|
|
- CONTENT_TYPE_UNREAD_NOTICE_MESSAGE -> message.id == "-1"
|
|
|
|
|
|
+ CONTENT_TYPE_UNREAD_NOTICE_MESSAGE -> message.id == UNREAD_MESSAGES_MARKER_ID.toString()
|
|
CONTENT_TYPE_CALL_STARTED -> message.id == "-2"
|
|
CONTENT_TYPE_CALL_STARTED -> message.id == "-2"
|
|
CONTENT_TYPE_TEMP -> message.id == "-3"
|
|
CONTENT_TYPE_TEMP -> message.id == "-3"
|
|
CONTENT_TYPE_DECK_CARD -> message.isDeckCard()
|
|
CONTENT_TYPE_DECK_CARD -> message.isDeckCard()
|
|
@@ -3762,6 +3746,7 @@ class ChatActivity :
|
|
private const val CONTENT_TYPE_LINK_PREVIEW: Byte = 7
|
|
private const val CONTENT_TYPE_LINK_PREVIEW: Byte = 7
|
|
private const val CONTENT_TYPE_DECK_CARD: Byte = 8
|
|
private const val CONTENT_TYPE_DECK_CARD: Byte = 8
|
|
private const val CONTENT_TYPE_TEMP: Byte = 9
|
|
private const val CONTENT_TYPE_TEMP: Byte = 9
|
|
|
|
+ private const val UNREAD_MESSAGES_MARKER_ID = -1
|
|
private const val NEW_MESSAGES_POPUP_BUBBLE_DELAY: Long = 200
|
|
private const val NEW_MESSAGES_POPUP_BUBBLE_DELAY: Long = 200
|
|
private const val GET_ROOM_INFO_DELAY_NORMAL: Long = 30000
|
|
private const val GET_ROOM_INFO_DELAY_NORMAL: Long = 30000
|
|
private const val GET_ROOM_INFO_DELAY_LOBBY: Long = 5000
|
|
private const val GET_ROOM_INFO_DELAY_LOBBY: Long = 5000
|