forked from GitHub-Mirror/riotX-android
Timeline: handle room history visibility
This commit is contained in:
parent
8fdce937bd
commit
42cf45c8f3
@ -48,12 +48,16 @@ class HomeModule {
|
|||||||
RoomMemberItemFactory(get())
|
RoomMemberItemFactory(get())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
single {
|
||||||
|
RoomHistoryVisibilityItemFactory(get())
|
||||||
|
}
|
||||||
|
|
||||||
single {
|
single {
|
||||||
DefaultItemFactory()
|
DefaultItemFactory()
|
||||||
}
|
}
|
||||||
|
|
||||||
single {
|
single {
|
||||||
TimelineItemFactory(get(), get(), get(), get(), get())
|
TimelineItemFactory(get(), get(), get(), get(), get(), get())
|
||||||
}
|
}
|
||||||
|
|
||||||
single {
|
single {
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* * 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.riotredesign.features.home.room.detail.timeline
|
||||||
|
|
||||||
|
import im.vector.matrix.android.api.session.events.model.Event
|
||||||
|
import im.vector.matrix.android.api.session.events.model.toModel
|
||||||
|
import im.vector.matrix.android.api.session.room.model.RoomHistoryVisibility
|
||||||
|
import im.vector.matrix.android.api.session.room.model.RoomHistoryVisibilityContent
|
||||||
|
import im.vector.matrix.android.api.session.room.model.RoomMember
|
||||||
|
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
||||||
|
import im.vector.riotredesign.R
|
||||||
|
import im.vector.riotredesign.core.resources.StringProvider
|
||||||
|
|
||||||
|
|
||||||
|
class RoomHistoryVisibilityItemFactory(private val stringProvider: StringProvider) {
|
||||||
|
|
||||||
|
fun create(event: TimelineEvent): NoticeItem? {
|
||||||
|
val roomMember = event.roomMember ?: return null
|
||||||
|
val noticeText = buildRoomMemberNotice(event.root, roomMember) ?: return null
|
||||||
|
return NoticeItem_()
|
||||||
|
.noticeText(noticeText)
|
||||||
|
.avatarUrl(roomMember.avatarUrl)
|
||||||
|
.memberName(roomMember.displayName)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildRoomMemberNotice(event: Event, roomMember: RoomMember): CharSequence? {
|
||||||
|
val content = event.content.toModel<RoomHistoryVisibilityContent>() ?: return null
|
||||||
|
val formattedVisibility = when (content.historyVisibility) {
|
||||||
|
RoomHistoryVisibility.SHARED -> stringProvider.getString(R.string.notice_room_visibility_shared)
|
||||||
|
RoomHistoryVisibility.INVITED -> stringProvider.getString(R.string.notice_room_visibility_invited)
|
||||||
|
RoomHistoryVisibility.JOINED -> stringProvider.getString(R.string.notice_room_visibility_joined)
|
||||||
|
RoomHistoryVisibility.WORLD_READABLE -> stringProvider.getString(R.string.notice_room_visibility_world_readable)
|
||||||
|
}
|
||||||
|
return stringProvider.getString(R.string.notice_made_future_room_visibility, roomMember.displayName, formattedVisibility)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -25,6 +25,7 @@ class TimelineItemFactory(private val messageItemFactory: MessageItemFactory,
|
|||||||
private val roomNameItemFactory: RoomNameItemFactory,
|
private val roomNameItemFactory: RoomNameItemFactory,
|
||||||
private val roomTopicItemFactory: RoomTopicItemFactory,
|
private val roomTopicItemFactory: RoomTopicItemFactory,
|
||||||
private val roomMemberItemFactory: RoomMemberItemFactory,
|
private val roomMemberItemFactory: RoomMemberItemFactory,
|
||||||
|
private val roomHistoryVisibilityItemFactory: RoomHistoryVisibilityItemFactory,
|
||||||
private val defaultItemFactory: DefaultItemFactory) {
|
private val defaultItemFactory: DefaultItemFactory) {
|
||||||
|
|
||||||
fun create(event: TimelineEvent,
|
fun create(event: TimelineEvent,
|
||||||
@ -37,6 +38,7 @@ class TimelineItemFactory(private val messageItemFactory: MessageItemFactory,
|
|||||||
EventType.STATE_ROOM_NAME -> roomNameItemFactory.create(event)
|
EventType.STATE_ROOM_NAME -> roomNameItemFactory.create(event)
|
||||||
EventType.STATE_ROOM_TOPIC -> roomTopicItemFactory.create(event)
|
EventType.STATE_ROOM_TOPIC -> roomTopicItemFactory.create(event)
|
||||||
EventType.STATE_ROOM_MEMBER -> roomMemberItemFactory.create(event)
|
EventType.STATE_ROOM_MEMBER -> roomMemberItemFactory.create(event)
|
||||||
|
EventType.STATE_HISTORY_VISIBILITY -> roomHistoryVisibilityItemFactory.create(event)
|
||||||
EventType.STATE_ROOM_CREATE,
|
EventType.STATE_ROOM_CREATE,
|
||||||
EventType.STATE_ROOM_POWER_LEVELS,
|
EventType.STATE_ROOM_POWER_LEVELS,
|
||||||
EventType.REDACTION -> EmptyItem_()
|
EventType.REDACTION -> EmptyItem_()
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* * 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
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class RoomHistoryVisibilityContent(
|
||||||
|
@Json(name = "history_visibility") val historyVisibility: RoomHistoryVisibility
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user