Unverified Commit e6d4f9a1 authored by Benoît Marty's avatar Benoît Marty Committed by GitHub
Browse files

Merge pull request #3298 from vector-im/feature/ypi/join_rules

Add joinRules field to RoomSummary
parents 0e0cfaba bea67bd7
......@@ -7,15 +7,6 @@
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
<option name="ALIGN_IN_COLUMNS_CASE_BRANCH" value="true" />
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
......
......@@ -11,6 +11,7 @@ Improvements 🙌:
- Improve file too big error detection (#3245)
- User can now select video when selecting Gallery to send attachments to a room
- Add option to record a video from the camera
- Add the public icon on the rooms in the room list (#3292)
Bugfix 🐛:
- Message states cosmetic changes (#3007)
......
......@@ -26,7 +26,7 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
* This class holds some data of a room.
* It can be retrieved by [org.matrix.android.sdk.api.session.room.Room] and [org.matrix.android.sdk.api.session.room.RoomService]
*/
data class RoomSummary constructor(
data class RoomSummary(
val roomId: String,
// Computed display name
val displayName: String = "",
......@@ -35,6 +35,7 @@ data class RoomSummary constructor(
val avatarUrl: String = "",
val canonicalAlias: String? = null,
val aliases: List<String> = emptyList(),
val joinRules: RoomJoinRules? = null,
val isDirect: Boolean = false,
val directUserId: String? = null,
val joinedMembersCount: Int? = 0,
......@@ -74,6 +75,9 @@ data class RoomSummary constructor(
val isFavorite: Boolean
get() = hasTag(RoomTag.ROOM_TAG_FAVOURITE)
val isPublic: Boolean
get() = joinRules == RoomJoinRules.PUBLIC
fun hasTag(tag: String) = tags.any { it.name == tag }
val canStartCall: Boolean
......
......@@ -20,6 +20,7 @@ import io.realm.DynamicRealm
import io.realm.FieldAttribute
import io.realm.RealmMigration
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent
import org.matrix.android.sdk.api.session.room.model.create.RoomCreateContent
import org.matrix.android.sdk.api.session.room.model.tag.RoomTag
import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntityFields
......@@ -33,9 +34,9 @@ import org.matrix.android.sdk.internal.database.model.RoomEntityFields
import org.matrix.android.sdk.internal.database.model.RoomMembersLoadStatusType
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
import org.matrix.android.sdk.internal.database.model.RoomTagEntityFields
import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields
import org.matrix.android.sdk.internal.database.model.SpaceChildSummaryEntityFields
import org.matrix.android.sdk.internal.database.model.SpaceParentSummaryEntityFields
import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields
import org.matrix.android.sdk.internal.di.MoshiProvider
import timber.log.Timber
import javax.inject.Inject
......@@ -43,7 +44,7 @@ import javax.inject.Inject
class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
companion object {
const val SESSION_STORE_SCHEMA_VERSION = 11L
const val SESSION_STORE_SCHEMA_VERSION = 12L
}
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
......@@ -60,6 +61,7 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
if (oldVersion <= 8) migrateTo9(realm)
if (oldVersion <= 9) migrateTo10(realm)
if (oldVersion <= 10) migrateTo11(realm)
if (oldVersion <= 11) migrateTo12(realm)
}
private fun migrateTo1(realm: DynamicRealm) {
......@@ -247,4 +249,25 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
realm.schema.get("EventEntity")
?.addField(EventEntityFields.SEND_STATE_DETAILS, String::class.java)
}
private fun migrateTo12(realm: DynamicRealm) {
Timber.d("Step 11 -> 12")
val joinRulesContentAdapter = MoshiProvider.providesMoshi().adapter(RoomJoinRulesContent::class.java)
realm.schema.get("RoomSummaryEntity")
?.addField(RoomSummaryEntityFields.JOIN_RULES_STR, String::class.java)
?.transform { obj ->
val joinRulesEvent = realm.where("CurrentStateEventEntity")
.equalTo(CurrentStateEventEntityFields.ROOM_ID, obj.getString(RoomSummaryEntityFields.ROOM_ID))
.equalTo(CurrentStateEventEntityFields.TYPE, EventType.STATE_ROOM_JOIN_RULES)
.findFirst()
val roomJoinRules = joinRulesEvent?.getObject(CurrentStateEventEntityFields.ROOT.`$`)
?.getString(EventEntityFields.CONTENT)?.let {
joinRulesContentAdapter.fromJson(it)?.joinRules
}
obj.setString(RoomSummaryEntityFields.JOIN_RULES_STR, roomJoinRules?.name)
}
}
}
......@@ -44,6 +44,7 @@ internal class RoomSummaryMapper @Inject constructor(private val timelineEventMa
name = roomSummaryEntity.name ?: "",
topic = roomSummaryEntity.topic ?: "",
avatarUrl = roomSummaryEntity.avatarUrl ?: "",
joinRules = roomSummaryEntity.joinRules,
isDirect = roomSummaryEntity.isDirect,
directUserId = roomSummaryEntity.directUserId,
latestPreviewableEvent = latestEvent,
......
......@@ -21,7 +21,9 @@ import io.realm.RealmObject
import io.realm.annotations.Index
import io.realm.annotations.PrimaryKey
import org.matrix.android.sdk.api.crypto.RoomEncryptionTrustLevel
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.model.RoomJoinRules
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.VersioningState
import org.matrix.android.sdk.api.session.room.model.tag.RoomTag
......@@ -242,6 +244,19 @@ internal open class RoomSummaryEntity(
}
}
private var joinRulesStr: String? = null
var joinRules: RoomJoinRules?
get() {
return joinRulesStr?.let {
tryOrNull { RoomJoinRules.valueOf(it) }
}
}
set(value) {
if (value?.name != joinRulesStr) {
joinRulesStr = value?.name
}
}
var roomEncryptionTrustLevel: RoomEncryptionTrustLevel?
get() {
return roomEncryptionTrustLevelStr?.let {
......
......@@ -24,6 +24,7 @@ import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.model.RoomAliasesContent
import org.matrix.android.sdk.api.session.room.model.RoomCanonicalAliasContent
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent
import org.matrix.android.sdk.api.session.room.model.RoomNameContent
import org.matrix.android.sdk.api.session.room.model.RoomTopicContent
import org.matrix.android.sdk.api.session.room.model.RoomType
......@@ -104,6 +105,7 @@ internal class RoomSummaryUpdater @Inject constructor(
val lastCanonicalAliasEvent = CurrentStateEventEntity.getOrNull(realm, roomId, type = EventType.STATE_ROOM_CANONICAL_ALIAS, stateKey = "")?.root
val lastAliasesEvent = CurrentStateEventEntity.getOrNull(realm, roomId, type = EventType.STATE_ROOM_ALIASES, stateKey = "")?.root
val roomCreateEvent = CurrentStateEventEntity.getOrNull(realm, roomId, type = EventType.STATE_ROOM_CREATE, stateKey = "")?.root
val joinRulesEvent = CurrentStateEventEntity.getOrNull(realm, roomId, type = EventType.STATE_ROOM_JOIN_RULES, stateKey = "")?.root
val roomType = ContentMapper.map(roomCreateEvent?.content).toModel<RoomCreateContent>()?.type
roomSummaryEntity.roomType = roomType
......@@ -130,6 +132,7 @@ internal class RoomSummaryUpdater @Inject constructor(
roomSummaryEntity.avatarUrl = roomAvatarResolver.resolve(realm, roomId)
roomSummaryEntity.name = ContentMapper.map(lastNameEvent?.content).toModel<RoomNameContent>()?.name
roomSummaryEntity.topic = ContentMapper.map(lastTopicEvent?.content).toModel<RoomTopicContent>()?.topic
roomSummaryEntity.joinRules = ContentMapper.map(joinRulesEvent?.content).toModel<RoomJoinRulesContent>()?.joinRules
roomSummaryEntity.latestPreviewableEvent = latestPreviewableEvent
roomSummaryEntity.canonicalAlias = ContentMapper.map(lastCanonicalAliasEvent?.content).toModel<RoomCanonicalAliasContent>()
?.canonicalAlias
......
......@@ -50,6 +50,7 @@ abstract class RoomSummaryItem : VectorEpoxyModel<RoomSummaryItem.Holder>() {
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) lateinit var lastFormattedEvent: CharSequence
@EpoxyAttribute lateinit var lastEventTime: CharSequence
@EpoxyAttribute var encryptionTrustLevel: RoomEncryptionTrustLevel? = null
@EpoxyAttribute var izPublic: Boolean = false
@EpoxyAttribute var unreadNotificationCount: Int = 0
@EpoxyAttribute var hasUnreadMessage: Boolean = false
@EpoxyAttribute var hasDraft: Boolean = false
......@@ -74,6 +75,7 @@ abstract class RoomSummaryItem : VectorEpoxyModel<RoomSummaryItem.Holder>() {
holder.draftView.isVisible = hasDraft
avatarRenderer.render(matrixItem, holder.avatarImageView)
holder.roomAvatarDecorationImageView.render(encryptionTrustLevel)
holder.roomAvatarPublicDecorationImageView.isVisible = izPublic
holder.roomAvatarFailSendingImageView.isVisible = hasFailedSending
renderSelection(holder, showSelected)
holder.typingView.setTextOrHide(typingMessage)
......@@ -110,6 +112,7 @@ abstract class RoomSummaryItem : VectorEpoxyModel<RoomSummaryItem.Holder>() {
val avatarCheckedImageView by bind<ImageView>(R.id.roomAvatarCheckedImageView)
val avatarImageView by bind<ImageView>(R.id.roomAvatarImageView)
val roomAvatarDecorationImageView by bind<ShieldImageView>(R.id.roomAvatarDecorationImageView)
val roomAvatarPublicDecorationImageView by bind<ImageView>(R.id.roomAvatarPublicDecorationImageView)
val roomAvatarFailSendingImageView by bind<ImageView>(R.id.roomAvatarFailSendingImageView)
val rootView by bind<ViewGroup>(R.id.itemRoomLayout)
}
......
......@@ -112,6 +112,7 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor
.avatarRenderer(avatarRenderer)
// We do not display shield in the room list anymore
// .encryptionTrustLevel(roomSummary.roomEncryptionTrustLevel)
.izPublic(roomSummary.isPublic)
.matrixItem(roomSummary.toMatrixItem())
.lastEventTime(latestEventTime)
.typingMessage(typingMessage)
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="96dp" />
<solid android:color="?riotx_background" />
</shape>
\ No newline at end of file
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M24,12C24,18.6274 18.6274,24 12,24C5.3726,24 0,18.6274 0,12C0,5.3726 5.3726,0 12,0C18.6274,0 24,5.3726 24,12Z"
android:fillColor="#C1C6CD"/>
<path
android:pathData="M18.6999,18.8177L19.6243,15.9652C19.6324,15.9404 19.6365,15.9143 19.6365,15.8882V15.0473C19.6365,14.9823 19.6111,14.9197 19.5657,14.8731L18.7105,13.9934C18.6916,13.9739 18.6697,13.9577 18.6456,13.9453L16.8092,13.0009C16.7852,12.9885 16.7632,12.9723 16.7443,12.9529L15.8919,12.0761C15.8449,12.0277 15.7802,12.0004 15.7127,12.0004H12.2501C12.1121,12.0004 12.0001,11.8885 12.0001,11.7504V10.2868C12.0001,10.1487 11.8882,10.0368 11.7501,10.0368H9.3865C9.2484,10.0368 9.1365,9.9248 9.1365,9.7868V8.3798C9.1365,8.2215 9.2818,8.103 9.4369,8.1349L13.6089,8.9931C13.7639,9.0251 13.9092,8.9066 13.9092,8.7483V7.1928C13.9092,7.1277 13.9346,7.0652 13.98,7.0185L16.6034,4.3201C16.6978,4.2231 16.6978,4.0686 16.6034,3.9716L14.9023,2.2219C14.8769,2.1957 14.8461,2.1755 14.8121,2.1625L13.3697,1.613C12.4823,1.275 11.5072,1.2439 10.6001,1.5247L9.1365,1.9777C7.1638,2.6207 5.6129,4.1612 4.9568,6.1296L4.621,7.1369C4.5407,7.3779 4.4931,7.6285 4.4795,7.8822L4.3696,9.9275C4.3659,9.9972 4.3914,10.0652 4.44,10.1152L6.1992,11.9247C6.2463,11.9731 6.311,12.0004 6.3785,12.0004H8.1214C8.1612,12.0004 8.2004,12.0099 8.2358,12.0281L9.9554,12.9124C10.0387,12.9553 10.091,13.0411 10.091,13.1348V15.8701C10.091,15.908 10.0996,15.9454 10.1162,15.9794L10.9772,17.7506C11.019,17.8367 11.1063,17.8913 11.202,17.8913H12.8491C12.9166,17.8913 12.9812,17.9186 13.0283,17.967L13.9092,18.8731L14.8357,19.8261C14.8543,19.8452 14.8697,19.8671 14.8813,19.8911L15.6626,21.4982C15.7383,21.654 15.9458,21.6874 16.0667,21.5631L16.7729,20.8368L17.7274,19.8549L18.6413,18.9149C18.6681,18.8874 18.6881,18.8542 18.6999,18.8177Z"
android:fillColor="#F4F6FA"
android:fillAlpha="0.91"/>
android:width="21dp"
android:height="20dp"
android:viewportWidth="21"
android:viewportHeight="20">
<path
android:fillColor="#8D99A5"
android:fillType="evenOdd"
android:pathData="M10.5,20C16.0228,20 20.5,15.5228 20.5,10C20.5,4.4771 16.0228,0 10.5,0C4.9771,0 0.5,4.4771 0.5,10C0.5,15.5228 4.9771,20 10.5,20ZM16.8518,13.3106L16.0865,15.6722C16.0747,15.7086 16.0546,15.7419 16.0279,15.7694L15.2731,16.5458L14.4776,17.364L13.9305,17.9267C13.8097,18.051 13.6022,18.0176 13.5264,17.8617L12.9043,16.5819C12.8927,16.558 12.8773,16.5361 12.8587,16.517L12.0913,15.7276L11.3694,14.9852C11.3224,14.9367 11.2577,14.9094 11.1902,14.9094H9.8614C9.7656,14.9094 9.6783,14.8548 9.6365,14.7687L8.9346,13.3248C8.918,13.2908 8.9094,13.2534 8.9094,13.2155V10.9711C8.9094,10.8774 8.8571,10.7916 8.7738,10.7487L7.3724,10.028C7.337,10.0098 7.2978,10.0003 7.258,10.0003H5.8333C5.7657,10.0003 5.7011,9.973 5.654,9.9246L4.213,8.4424C4.1644,8.3924 4.1389,8.3244 4.1426,8.2547L4.2331,6.5685C4.2445,6.3571 4.2842,6.1482 4.3511,5.9474L4.6309,5.108C5.1777,3.4677 6.47,2.1839 8.114,1.6481L9.1003,1.3428C10.0075,1.062 10.9825,1.0931 11.8699,1.4312L12.835,1.7988C12.8691,1.8118 12.8999,1.832 12.9253,1.8582L14.3082,3.2806C14.4025,3.3776 14.4025,3.5321 14.3082,3.6291L12.162,5.8366C12.1166,5.8833 12.0913,5.9458 12.0913,6.0109V7.2391C12.0913,7.3974 11.946,7.5159 11.7909,7.484L8.4144,6.7894C8.2593,6.7575 8.114,6.8759 8.114,7.0343V8.114C8.114,8.252 8.2259,8.364 8.364,8.364H10.2504C10.3884,8.364 10.5004,8.4759 10.5004,8.614V9.7503C10.5004,9.8884 10.6123,10.0003 10.7504,10.0003H13.5766C13.6441,10.0003 13.7087,10.0276 13.7558,10.0761L14.4491,10.7892C14.468,10.8086 14.4899,10.8248 14.514,10.8372L16.0321,11.618C16.0562,11.6304 16.0782,11.6466 16.0971,11.666L16.7932,12.3821C16.8386,12.4288 16.864,12.4913 16.864,12.5564V13.2336C16.864,13.2597 16.8599,13.2857 16.8518,13.3106Z" />
</vector>
......@@ -60,6 +60,7 @@
app:layout_constraintCircleRadius="30dp"
tools:ignore="MissingConstraints" />
<!-- Note: this is always gone now -->
<im.vector.app.core.ui.views.ShieldImageView
android:id="@+id/roomAvatarDecorationImageView"
android:layout_width="24dp"
......@@ -67,7 +68,23 @@
app:layout_constraintCircle="@id/roomAvatarContainer"
app:layout_constraintCircleAngle="135"
app:layout_constraintCircleRadius="28dp"
tools:ignore="MissingConstraints" />
tools:ignore="MissingConstraints"
tools:visibility="gone" />
<ImageView
android:id="@+id/roomAvatarPublicDecorationImageView"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/background_circle"
android:contentDescription="@string/a11y_public_room"
android:padding="2dp"
android:src="@drawable/ic_public_room"
android:visibility="gone"
app:layout_constraintCircle="@id/roomAvatarContainer"
app:layout_constraintCircleAngle="135"
app:layout_constraintCircleRadius="28dp"
tools:ignore="MissingConstraints"
tools:visibility="visible" />
<!-- Margin bottom does not work, so I use space -->
<Space
......
......@@ -3251,6 +3251,7 @@
<string name="a11y_rule_notify_silent">Notify without sound</string>
<string name="a11y_rule_notify_off">Do not notify</string>
<string name="a11y_view_read_receipts">View read receipts</string>
<string name="a11y_public_room">This room is public</string>
<string name="dev_tools_menu_name">Dev Tools</string>
<string name="dev_tools_explore_room_state">Explore Room State</string>
......
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