Unverified Commit 45ea3824 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito Committed by GitHub

Merge pull request #949 from TheGamer007/mark_as_read

[FIX] Properly mark a room as read
parents 9670e641 1673b61e
...@@ -71,13 +71,13 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView, ...@@ -71,13 +71,13 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
client.messages(chatRoomId, roomTypeOf(chatRoomType), offset, 30).result client.messages(chatRoomId, roomTypeOf(chatRoomType), offset, 30).result
messagesRepository.saveAll(messages) messagesRepository.saveAll(messages)
val messagesViewModels = mapper.map(messages)
view.showMessages(messagesViewModels)
// TODO: For now we are marking the room as read if we can get the messages (I mean, no exception occurs) // TODO: For now we are marking the room as read if we can get the messages (I mean, no exception occurs)
// but should mark only when the user see the first unread message. // but should mark only when the user see the first unread message.
markRoomAsRead(chatRoomId) markRoomAsRead(chatRoomId)
val messagesViewModels = mapper.map(messages)
view.showMessages(messagesViewModels)
subscribeMessages(chatRoomId) subscribeMessages(chatRoomId)
} catch (ex: Exception) { } catch (ex: Exception) {
ex.printStackTrace() ex.printStackTrace()
...@@ -230,6 +230,9 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView, ...@@ -230,6 +230,9 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
fun unsubscribeMessages(chatRoomId: String) { fun unsubscribeMessages(chatRoomId: String) {
manager.removeStatusChannel(stateChannel) manager.removeStatusChannel(stateChannel)
manager.unsubscribeRoomMessages(chatRoomId) manager.unsubscribeRoomMessages(chatRoomId)
// All messages during the subscribed period are assumed to be read,
// and lastSeen is updated as the time when the user leaves the room
markRoomAsRead(chatRoomId)
} }
/** /**
......
...@@ -35,13 +35,20 @@ ...@@ -35,13 +35,20 @@
android:layout_height="1dp" android:layout_height="1dp"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_weight="1" android:layout_weight="1"
android:layout_marginRight="4dp" android:layout_marginEnd="4dp"
android:background="@color/red"/> android:background="@color/red"/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:text="@string/msg_unread_messages" android:text="@string/msg_unread_messages"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="@color/red" /> android:textColor="@color/red" />
<View
android:layout_gravity="center"
android:layout_height="1dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginStart="4dp"
android:background="@color/red"/>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment