mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 01:15:54 +03:00
Room : add RoomTag to handle favourites, low priority and system alerts in room list.
This commit is contained in:
parent
0f66fa0895
commit
d3d536f4f0
17 changed files with 276 additions and 50 deletions
|
@ -27,6 +27,7 @@ import im.vector.riotredesign.features.home.room.detail.timeline.TimelineDateFor
|
||||||
import im.vector.riotredesign.features.home.room.detail.timeline.TimelineEventController
|
import im.vector.riotredesign.features.home.room.detail.timeline.TimelineEventController
|
||||||
import im.vector.riotredesign.features.home.room.detail.timeline.TimelineItemFactory
|
import im.vector.riotredesign.features.home.room.detail.timeline.TimelineItemFactory
|
||||||
import im.vector.riotredesign.features.home.room.detail.timeline.helper.TimelineMediaSizeProvider
|
import im.vector.riotredesign.features.home.room.detail.timeline.helper.TimelineMediaSizeProvider
|
||||||
|
import im.vector.riotredesign.features.home.room.list.RoomSummaryController
|
||||||
import org.koin.dsl.module.module
|
import org.koin.dsl.module.module
|
||||||
|
|
||||||
class HomeModule {
|
class HomeModule {
|
||||||
|
@ -65,6 +66,10 @@ class HomeModule {
|
||||||
HomeNavigator()
|
HomeNavigator()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
factory {
|
||||||
|
RoomSummaryController(get())
|
||||||
|
}
|
||||||
|
|
||||||
factory { (roomId: String) ->
|
factory { (roomId: String) ->
|
||||||
TimelineEventController(roomId, get(), get(), get())
|
TimelineEventController(roomId, get(), get(), get())
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import android.text.TextWatcher
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.inputmethod.EditorInfo
|
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.Incomplete
|
import com.airbnb.mvrx.Incomplete
|
||||||
import com.airbnb.mvrx.Success
|
import com.airbnb.mvrx.Success
|
||||||
|
@ -30,7 +29,6 @@ import com.airbnb.mvrx.activityViewModel
|
||||||
import im.vector.matrix.android.api.failure.Failure
|
import im.vector.matrix.android.api.failure.Failure
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||||
import im.vector.riotredesign.R
|
import im.vector.riotredesign.R
|
||||||
import im.vector.riotredesign.core.extensions.hideKeyboard
|
|
||||||
import im.vector.riotredesign.core.extensions.setupAsSearch
|
import im.vector.riotredesign.core.extensions.setupAsSearch
|
||||||
import im.vector.riotredesign.core.platform.RiotFragment
|
import im.vector.riotredesign.core.platform.RiotFragment
|
||||||
import im.vector.riotredesign.core.platform.StateView
|
import im.vector.riotredesign.core.platform.StateView
|
||||||
|
@ -47,8 +45,8 @@ class RoomListFragment : RiotFragment(), RoomSummaryController.Callback {
|
||||||
}
|
}
|
||||||
|
|
||||||
private val homeNavigator by inject<HomeNavigator>()
|
private val homeNavigator by inject<HomeNavigator>()
|
||||||
|
private val roomController by inject<RoomSummaryController>()
|
||||||
private val homeViewModel: RoomListViewModel by activityViewModel()
|
private val homeViewModel: RoomListViewModel by activityViewModel()
|
||||||
private lateinit var roomController: RoomSummaryController
|
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
return inflater.inflate(R.layout.fragment_room_list, container, false)
|
return inflater.inflate(R.layout.fragment_room_list, container, false)
|
||||||
|
@ -56,7 +54,7 @@ class RoomListFragment : RiotFragment(), RoomSummaryController.Callback {
|
||||||
|
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
super.onActivityCreated(savedInstanceState)
|
super.onActivityCreated(savedInstanceState)
|
||||||
roomController = RoomSummaryController(this)
|
roomController.callback = this
|
||||||
stateView.contentView = epoxyRecyclerView
|
stateView.contentView = epoxyRecyclerView
|
||||||
epoxyRecyclerView.setController(roomController)
|
epoxyRecyclerView.setController(roomController)
|
||||||
setupFilterView()
|
setupFilterView()
|
||||||
|
|
|
@ -24,6 +24,7 @@ import im.vector.matrix.android.api.Matrix
|
||||||
import im.vector.matrix.android.api.session.Session
|
import im.vector.matrix.android.api.session.Session
|
||||||
import im.vector.matrix.android.api.session.group.model.GroupSummary
|
import im.vector.matrix.android.api.session.group.model.GroupSummary
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||||
|
import im.vector.matrix.android.api.session.room.model.tag.RoomTag
|
||||||
import im.vector.matrix.rx.rx
|
import im.vector.matrix.rx.rx
|
||||||
import im.vector.riotredesign.core.platform.RiotViewModel
|
import im.vector.riotredesign.core.platform.RiotViewModel
|
||||||
import im.vector.riotredesign.features.home.group.SelectedGroupHolder
|
import im.vector.riotredesign.features.home.group.SelectedGroupHolder
|
||||||
|
@ -96,15 +97,7 @@ class RoomListViewModel(initialState: RoomListViewState,
|
||||||
selectedGroupHolder.selectedGroup(),
|
selectedGroupHolder.selectedGroup(),
|
||||||
roomListFilter,
|
roomListFilter,
|
||||||
Function3 { rooms, selectedGroupOption, filterRoomOption ->
|
Function3 { rooms, selectedGroupOption, filterRoomOption ->
|
||||||
val filterRoom = filterRoomOption.orNull()
|
val filteredRooms = filterRooms(rooms, filterRoomOption)
|
||||||
val filteredRooms = rooms.filter {
|
|
||||||
if (filterRoom.isNullOrBlank()) {
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
it.displayName.contains(other = filterRoom, ignoreCase = true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val selectedGroup = selectedGroupOption.orNull()
|
val selectedGroup = selectedGroupOption.orNull()
|
||||||
val filteredDirectRooms = filteredRooms
|
val filteredDirectRooms = filteredRooms
|
||||||
.filter { it.isDirect }
|
.filter { it.isDirect }
|
||||||
|
@ -123,7 +116,7 @@ class RoomListViewModel(initialState: RoomListViewState,
|
||||||
.filter {
|
.filter {
|
||||||
selectedGroup?.roomIds?.contains(it.roomId) ?: true
|
selectedGroup?.roomIds?.contains(it.roomId) ?: true
|
||||||
}
|
}
|
||||||
RoomSummaries(filteredDirectRooms, filteredGroupRooms)
|
buildRoomSummaries(filteredDirectRooms + filteredGroupRooms)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.execute { async ->
|
.execute { async ->
|
||||||
|
@ -132,4 +125,37 @@ class RoomListViewModel(initialState: RoomListViewState,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun filterRooms(rooms: List<RoomSummary>, filterRoomOption: Option<RoomListFilterName>): List<RoomSummary> {
|
||||||
|
val filterRoom = filterRoomOption.orNull()
|
||||||
|
return rooms.filter {
|
||||||
|
if (filterRoom.isNullOrBlank()) {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
it.displayName.contains(other = filterRoom, ignoreCase = true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildRoomSummaries(rooms: List<RoomSummary>): RoomSummaries {
|
||||||
|
val favourites = ArrayList<RoomSummary>()
|
||||||
|
val directChats = ArrayList<RoomSummary>()
|
||||||
|
val groupRooms = ArrayList<RoomSummary>()
|
||||||
|
val lowPriorities = ArrayList<RoomSummary>()
|
||||||
|
val serverNotices = ArrayList<RoomSummary>()
|
||||||
|
|
||||||
|
for (room in rooms) {
|
||||||
|
val tags = room.tags.map { it.name }
|
||||||
|
when {
|
||||||
|
tags.contains(RoomTag.ROOM_TAG_SERVER_NOTICE) -> serverNotices.add(room)
|
||||||
|
tags.contains(RoomTag.ROOM_TAG_FAVOURITE) -> favourites.add(room)
|
||||||
|
tags.contains(RoomTag.ROOM_TAG_LOW_PRIORITY) -> lowPriorities.add(room)
|
||||||
|
room.isDirect -> directChats.add(room)
|
||||||
|
else -> groupRooms.add(room)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return RoomSummaries(favourites, directChats, groupRooms, lowPriorities, serverNotices)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -27,10 +27,13 @@ data class RoomListViewState(
|
||||||
) : MvRxState
|
) : MvRxState
|
||||||
|
|
||||||
data class RoomSummaries(
|
data class RoomSummaries(
|
||||||
|
val favourites: List<RoomSummary>,
|
||||||
val directRooms: List<RoomSummary>,
|
val directRooms: List<RoomSummary>,
|
||||||
val groupRooms: List<RoomSummary>
|
val groupRooms: List<RoomSummary>,
|
||||||
|
val lowPriorities: List<RoomSummary>,
|
||||||
|
val serverNotices: List<RoomSummary>
|
||||||
)
|
)
|
||||||
|
|
||||||
fun RoomSummaries?.isNullOrEmpty(): Boolean {
|
fun RoomSummaries?.isNullOrEmpty(): Boolean {
|
||||||
return this == null || (directRooms.isEmpty() && groupRooms.isEmpty())
|
return this == null || (directRooms.isEmpty() && groupRooms.isEmpty() && favourites.isEmpty() && lowPriorities.isEmpty() && serverNotices.isEmpty())
|
||||||
}
|
}
|
|
@ -16,47 +16,74 @@
|
||||||
|
|
||||||
package im.vector.riotredesign.features.home.room.list
|
package im.vector.riotredesign.features.home.room.list
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
import com.airbnb.epoxy.TypedEpoxyController
|
import com.airbnb.epoxy.TypedEpoxyController
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||||
|
import im.vector.riotredesign.R
|
||||||
|
import im.vector.riotredesign.core.resources.StringProvider
|
||||||
|
|
||||||
class RoomSummaryController(private val callback: Callback? = null
|
class RoomSummaryController(private val stringProvider: StringProvider
|
||||||
) : TypedEpoxyController<RoomListViewState>() {
|
) : TypedEpoxyController<RoomListViewState>() {
|
||||||
|
|
||||||
private var isDirectRoomsExpanded = true
|
private var isDirectRoomsExpanded = true
|
||||||
private var isGroupRoomsExpanded = true
|
private var isGroupRoomsExpanded = true
|
||||||
|
private var isFavoriteRoomsExpanded = true
|
||||||
|
private var isLowPriorityRoomsExpanded = true
|
||||||
|
private var isServerNoticeRoomsExpanded = true
|
||||||
|
|
||||||
|
var callback: Callback? = null
|
||||||
|
|
||||||
override fun buildModels(viewState: RoomListViewState) {
|
override fun buildModels(viewState: RoomListViewState) {
|
||||||
val roomSummaries = viewState.asyncRooms()
|
val roomSummaries = viewState.asyncRooms()
|
||||||
RoomCategoryItem(
|
|
||||||
title = "DIRECT MESSAGES",
|
|
||||||
isExpanded = isDirectRoomsExpanded,
|
|
||||||
listener = {
|
|
||||||
isDirectRoomsExpanded = !isDirectRoomsExpanded
|
|
||||||
setData(viewState)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.id("direct_messages")
|
|
||||||
.addTo(this)
|
|
||||||
|
|
||||||
|
buildRoomCategory(viewState, R.string.room_list_favourites, isFavoriteRoomsExpanded) {
|
||||||
|
isFavoriteRoomsExpanded = !isFavoriteRoomsExpanded
|
||||||
|
}
|
||||||
|
if (isFavoriteRoomsExpanded) {
|
||||||
|
buildRoomModels(roomSummaries?.favourites ?: emptyList(), viewState.selectedRoomId)
|
||||||
|
}
|
||||||
|
|
||||||
|
buildRoomCategory(viewState, R.string.room_list_direct, isDirectRoomsExpanded) {
|
||||||
|
isDirectRoomsExpanded = !isDirectRoomsExpanded
|
||||||
|
}
|
||||||
if (isDirectRoomsExpanded) {
|
if (isDirectRoomsExpanded) {
|
||||||
buildRoomModels(roomSummaries?.directRooms ?: emptyList(), viewState.selectedRoomId)
|
buildRoomModels(roomSummaries?.directRooms ?: emptyList(), viewState.selectedRoomId)
|
||||||
}
|
}
|
||||||
|
|
||||||
RoomCategoryItem(
|
buildRoomCategory(viewState, R.string.room_list_group, isGroupRoomsExpanded) {
|
||||||
title = "GROUPS",
|
isGroupRoomsExpanded = !isGroupRoomsExpanded
|
||||||
isExpanded = isGroupRoomsExpanded,
|
}
|
||||||
listener = {
|
|
||||||
isGroupRoomsExpanded = !isGroupRoomsExpanded
|
|
||||||
setData(viewState)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.id("group_messages")
|
|
||||||
.addTo(this)
|
|
||||||
|
|
||||||
if (isGroupRoomsExpanded) {
|
if (isGroupRoomsExpanded) {
|
||||||
buildRoomModels(roomSummaries?.groupRooms ?: emptyList(), viewState.selectedRoomId)
|
buildRoomModels(roomSummaries?.groupRooms ?: emptyList(), viewState.selectedRoomId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildRoomCategory(viewState, R.string.room_list_low_priority, isLowPriorityRoomsExpanded) {
|
||||||
|
isLowPriorityRoomsExpanded = !isLowPriorityRoomsExpanded
|
||||||
|
}
|
||||||
|
if (isLowPriorityRoomsExpanded) {
|
||||||
|
buildRoomModels(roomSummaries?.lowPriorities ?: emptyList(), viewState.selectedRoomId)
|
||||||
|
}
|
||||||
|
|
||||||
|
buildRoomCategory(viewState, R.string.room_list_system_alert, isServerNoticeRoomsExpanded) {
|
||||||
|
isServerNoticeRoomsExpanded = !isServerNoticeRoomsExpanded
|
||||||
|
}
|
||||||
|
if (isServerNoticeRoomsExpanded) {
|
||||||
|
buildRoomModels(roomSummaries?.serverNotices ?: emptyList(), viewState.selectedRoomId)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildRoomCategory(viewState: RoomListViewState, @StringRes titleRes: Int, isExpanded: Boolean, mutateExpandedState: () -> Unit) {
|
||||||
|
RoomCategoryItem(
|
||||||
|
title = stringProvider.getString(titleRes).toUpperCase(),
|
||||||
|
isExpanded = isExpanded,
|
||||||
|
listener = {
|
||||||
|
mutateExpandedState()
|
||||||
|
setData(viewState)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.id(titleRes)
|
||||||
|
.addTo(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildRoomModels(summaries: List<RoomSummary>, selectedRoomId: String?) {
|
private fun buildRoomModels(summaries: List<RoomSummary>, selectedRoomId: String?) {
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Riot X</string>
|
<string name="app_name">"Riot X"</string>
|
||||||
|
|
||||||
<string name="global_retry">Réessayer</string>
|
<string name="global_retry">"Retry"</string>
|
||||||
<string name="error_no_network">Pas de connexion internet</string>
|
<string name="error_no_network">"No network connection"</string>
|
||||||
<string name="error_common">Une erreur est survenue</string>
|
<string name="error_common">"An error occurred"</string>
|
||||||
<string name="room_list_empty">Rejoignez une room pour commencer à utiliser l\'application</string>
|
|
||||||
|
<string name="room_list_empty">"Join a room to start using the app."</string>
|
||||||
|
<string name="room_list_favourites">"Favourites"</string>
|
||||||
|
<string name="room_list_direct">"People"</string>
|
||||||
|
<string name="room_list_group">"Rooms"</string>
|
||||||
|
<string name="room_list_low_priority">"Low priority"</string>
|
||||||
|
<string name="room_list_system_alert">"System Alerts"</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -35,6 +35,7 @@ interface Room : TimelineService, SendService, ReadService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A live [RoomSummary] associated with the room
|
* A live [RoomSummary] associated with the room
|
||||||
|
* You can observe this summary to get dynamic data from this room.
|
||||||
*/
|
*/
|
||||||
val roomSummary: LiveData<RoomSummary>
|
val roomSummary: LiveData<RoomSummary>
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package im.vector.matrix.android.api.session.room.model
|
package im.vector.matrix.android.api.session.room.model
|
||||||
|
|
||||||
|
import im.vector.matrix.android.api.session.room.model.tag.RoomTag
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class holds some data of a room.
|
* This class holds some data of a room.
|
||||||
* It can be retrieved by [im.vector.matrix.android.api.session.room.Room] and [im.vector.matrix.android.api.session.room.RoomService]
|
* It can be retrieved by [im.vector.matrix.android.api.session.room.Room] and [im.vector.matrix.android.api.session.room.RoomService]
|
||||||
|
@ -28,5 +30,6 @@ data class RoomSummary(
|
||||||
val isDirect: Boolean,
|
val isDirect: Boolean,
|
||||||
val otherMemberIds: List<String> = emptyList(),
|
val otherMemberIds: List<String> = emptyList(),
|
||||||
var notificationCount: Int = 0,
|
var notificationCount: Int = 0,
|
||||||
var highlightCount: Int = 0
|
var highlightCount: Int = 0,
|
||||||
|
var tags: List<RoomTag> = emptyList()
|
||||||
)
|
)
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.matrix.android.api.session.room.model.tag
|
||||||
|
|
||||||
|
data class RoomTag(
|
||||||
|
val name: String,
|
||||||
|
val order: Double?
|
||||||
|
) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val ROOM_TAG_FAVOURITE = "m.favourite"
|
||||||
|
val ROOM_TAG_LOW_PRIORITY = "m.lowpriority"
|
||||||
|
val ROOM_TAG_NO_TAG = "m.recent"
|
||||||
|
val ROOM_TAG_SERVER_NOTICE = "m.server_notice"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.matrix.android.api.session.room.model.tag
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class RoomTagContent(
|
||||||
|
@Json(name = "tags") val tags: Map<String, Map<String, Double>> = emptyMap()
|
||||||
|
)
|
|
@ -17,12 +17,16 @@
|
||||||
package im.vector.matrix.android.internal.database.mapper
|
package im.vector.matrix.android.internal.database.mapper
|
||||||
|
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||||
|
import im.vector.matrix.android.api.session.room.model.tag.RoomTag
|
||||||
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
||||||
|
|
||||||
|
|
||||||
internal object RoomSummaryMapper {
|
internal object RoomSummaryMapper {
|
||||||
|
|
||||||
fun map(roomSummaryEntity: RoomSummaryEntity): RoomSummary {
|
fun map(roomSummaryEntity: RoomSummaryEntity): RoomSummary {
|
||||||
|
val tags = roomSummaryEntity.tags.map {
|
||||||
|
RoomTag(it.tagName, it.tagOrder)
|
||||||
|
}
|
||||||
return RoomSummary(
|
return RoomSummary(
|
||||||
roomId = roomSummaryEntity.roomId,
|
roomId = roomSummaryEntity.roomId,
|
||||||
displayName = roomSummaryEntity.displayName ?: "",
|
displayName = roomSummaryEntity.displayName ?: "",
|
||||||
|
@ -31,7 +35,8 @@ internal object RoomSummaryMapper {
|
||||||
isDirect = roomSummaryEntity.isDirect,
|
isDirect = roomSummaryEntity.isDirect,
|
||||||
otherMemberIds = roomSummaryEntity.otherMemberIds.toList(),
|
otherMemberIds = roomSummaryEntity.otherMemberIds.toList(),
|
||||||
highlightCount = roomSummaryEntity.highlightCount,
|
highlightCount = roomSummaryEntity.highlightCount,
|
||||||
notificationCount = roomSummaryEntity.notificationCount
|
notificationCount = roomSummaryEntity.notificationCount,
|
||||||
|
tags = tags
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,8 @@ internal open class RoomSummaryEntity(@PrimaryKey var roomId: String = "",
|
||||||
var isDirect: Boolean = false,
|
var isDirect: Boolean = false,
|
||||||
var otherMemberIds: RealmList<String> = RealmList(),
|
var otherMemberIds: RealmList<String> = RealmList(),
|
||||||
var notificationCount: Int = 0,
|
var notificationCount: Int = 0,
|
||||||
var highlightCount: Int = 0
|
var highlightCount: Int = 0,
|
||||||
|
var tags: RealmList<RoomTagEntity> = RealmList()
|
||||||
) : RealmObject() {
|
) : RealmObject() {
|
||||||
|
|
||||||
companion object
|
companion object
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.matrix.android.internal.database.model
|
||||||
|
|
||||||
|
import io.realm.RealmObject
|
||||||
|
|
||||||
|
internal open class RoomTagEntity(
|
||||||
|
var tagName: String = "",
|
||||||
|
var tagOrder: Double? = null
|
||||||
|
) : RealmObject() {
|
||||||
|
|
||||||
|
companion object
|
||||||
|
|
||||||
|
}
|
|
@ -21,6 +21,7 @@ import im.vector.matrix.android.api.session.events.model.Event
|
||||||
import im.vector.matrix.android.api.session.events.model.EventType
|
import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
import im.vector.matrix.android.api.session.events.model.toModel
|
import im.vector.matrix.android.api.session.events.model.toModel
|
||||||
import im.vector.matrix.android.api.session.room.model.MyMembership
|
import im.vector.matrix.android.api.session.room.model.MyMembership
|
||||||
|
import im.vector.matrix.android.api.session.room.model.tag.RoomTagContent
|
||||||
import im.vector.matrix.android.internal.database.helper.addAll
|
import im.vector.matrix.android.internal.database.helper.addAll
|
||||||
import im.vector.matrix.android.internal.database.helper.addOrUpdate
|
import im.vector.matrix.android.internal.database.helper.addOrUpdate
|
||||||
import im.vector.matrix.android.internal.database.helper.addStateEvents
|
import im.vector.matrix.android.internal.database.helper.addStateEvents
|
||||||
|
@ -33,6 +34,7 @@ import im.vector.matrix.android.internal.database.query.where
|
||||||
import im.vector.matrix.android.internal.session.room.timeline.PaginationDirection
|
import im.vector.matrix.android.internal.session.room.timeline.PaginationDirection
|
||||||
import im.vector.matrix.android.internal.session.sync.model.InvitedRoomSync
|
import im.vector.matrix.android.internal.session.sync.model.InvitedRoomSync
|
||||||
import im.vector.matrix.android.internal.session.sync.model.RoomSync
|
import im.vector.matrix.android.internal.session.sync.model.RoomSync
|
||||||
|
import im.vector.matrix.android.internal.session.sync.model.RoomSyncAccountData
|
||||||
import im.vector.matrix.android.internal.session.sync.model.RoomSyncEphemeral
|
import im.vector.matrix.android.internal.session.sync.model.RoomSyncEphemeral
|
||||||
import im.vector.matrix.android.internal.session.sync.model.RoomSyncSummary
|
import im.vector.matrix.android.internal.session.sync.model.RoomSyncSummary
|
||||||
import im.vector.matrix.android.internal.session.sync.model.RoomSyncUnreadNotifications
|
import im.vector.matrix.android.internal.session.sync.model.RoomSyncUnreadNotifications
|
||||||
|
@ -40,9 +42,9 @@ import im.vector.matrix.android.internal.session.sync.model.RoomsSyncResponse
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import io.realm.kotlin.createObject
|
import io.realm.kotlin.createObject
|
||||||
|
|
||||||
|
|
||||||
internal class RoomSyncHandler(private val monarchy: Monarchy,
|
internal class RoomSyncHandler(private val monarchy: Monarchy,
|
||||||
private val readReceiptHandler: ReadReceiptHandler) {
|
private val readReceiptHandler: ReadReceiptHandler,
|
||||||
|
private val roomTagHandler: RoomTagHandler) {
|
||||||
|
|
||||||
sealed class HandlingStrategy {
|
sealed class HandlingStrategy {
|
||||||
data class JOINED(val data: Map<String, RoomSync>) : HandlingStrategy()
|
data class JOINED(val data: Map<String, RoomSync>) : HandlingStrategy()
|
||||||
|
@ -118,6 +120,10 @@ internal class RoomSyncHandler(private val monarchy: Monarchy,
|
||||||
handleEphemeral(realm, roomId, roomSync.ephemeral)
|
handleEphemeral(realm, roomId, roomSync.ephemeral)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (roomSync.accountData != null && roomSync.accountData.events.isNullOrEmpty().not()) {
|
||||||
|
handleRoomAccountDataEvents(realm, roomId, roomSync.accountData)
|
||||||
|
}
|
||||||
|
|
||||||
return roomEntity
|
return roomEntity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,4 +213,11 @@ internal class RoomSyncHandler(private val monarchy: Monarchy,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleRoomAccountDataEvents(realm: Realm, roomId: String, accountData: RoomSyncAccountData) {
|
||||||
|
accountData.events
|
||||||
|
.filter { it.type == EventType.TAG }
|
||||||
|
.map { it.content.toModel<RoomTagContent>() }
|
||||||
|
.forEach { roomTagHandler.handle(realm, roomId, it) }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.matrix.android.internal.session.sync
|
||||||
|
|
||||||
|
import im.vector.matrix.android.api.session.room.model.tag.RoomTagContent
|
||||||
|
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
||||||
|
import im.vector.matrix.android.internal.database.model.RoomTagEntity
|
||||||
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
|
import io.realm.Realm
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
internal class RoomTagHandler {
|
||||||
|
|
||||||
|
fun handle(realm: Realm, roomId: String, content: RoomTagContent?) {
|
||||||
|
if (content == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val tags = ArrayList<RoomTagEntity>()
|
||||||
|
for (tagName in content.tags.keys) {
|
||||||
|
val params = content.tags[tagName]
|
||||||
|
val tag = if (params != null) {
|
||||||
|
RoomTagEntity(tagName, params["order"])
|
||||||
|
} else {
|
||||||
|
RoomTagEntity(tagName, null)
|
||||||
|
}
|
||||||
|
tags.add(tag)
|
||||||
|
}
|
||||||
|
val roomSummaryEntity = RoomSummaryEntity.where(realm, roomId).findFirst()
|
||||||
|
?: RoomSummaryEntity(roomId)
|
||||||
|
|
||||||
|
roomSummaryEntity.tags.clear()
|
||||||
|
roomSummaryEntity.tags.addAll(tags)
|
||||||
|
realm.insertOrUpdate(roomSummaryEntity)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -36,7 +36,11 @@ internal class SyncModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
scope(DefaultSession.SCOPE) {
|
scope(DefaultSession.SCOPE) {
|
||||||
RoomSyncHandler(get(), get())
|
RoomTagHandler()
|
||||||
|
}
|
||||||
|
|
||||||
|
scope(DefaultSession.SCOPE) {
|
||||||
|
RoomSyncHandler(get(), get(), get())
|
||||||
}
|
}
|
||||||
|
|
||||||
scope(DefaultSession.SCOPE) {
|
scope(DefaultSession.SCOPE) {
|
||||||
|
|
|
@ -25,5 +25,5 @@ internal data class RoomSyncAccountData(
|
||||||
/**
|
/**
|
||||||
* List of account data events (array of Event).
|
* List of account data events (array of Event).
|
||||||
*/
|
*/
|
||||||
@Json(name = "events") val events: List<Event>? = null
|
@Json(name = "events") val events: List<Event> = emptyList()
|
||||||
)
|
)
|
Loading…
Reference in a new issue