Code review

This commit is contained in:
Valere 2020-11-16 09:56:26 +01:00 committed by Benoit Marty
parent 264bc52bcc
commit 1de5cd2e61
5 changed files with 38 additions and 23 deletions

View File

@ -26,6 +26,8 @@ import org.matrix.android.sdk.internal.database.query.getOrNull
import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.session.room.membership.RoomMemberHelper
import io.realm.Realm
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
import org.matrix.android.sdk.internal.database.query.where
import javax.inject.Inject
internal class RoomAvatarResolver @Inject constructor(@UserId private val userId: String) {
@ -46,7 +48,8 @@ internal class RoomAvatarResolver @Inject constructor(@UserId private val userId
val roomMembers = RoomMemberHelper(realm, roomId)
val members = roomMembers.queryActiveRoomMembersEvent().findAll()
// detect if it is a room with no more than 2 members (i.e. an alone or a 1:1 chat)
if (roomMembers.isDirectRoom()) {
val isDirectRoom = RoomSummaryEntity.where(realm, roomId).findFirst()?.isDirect ?: false
if (isDirectRoom) {
if (members.size == 1) {
res = members.firstOrNull()?.avatarUrl
} else if (members.size == 2) {

View File

@ -116,17 +116,35 @@ internal class RoomDisplayNameResolver @Inject constructor(
// TODO (was xx and yyy) ...
}
1 -> resolveRoomMemberName(otherMembersSubset[0], roomMembers)
2 -> {
stringProvider.getString(R.string.room_displayname_two_members,
resolveRoomMemberName(otherMembersSubset[0], roomMembers),
resolveRoomMemberName(otherMembersSubset[1], roomMembers)
)
}
3 -> {
stringProvider.getString(R.string.room_displayname_3_members,
resolveRoomMemberName(otherMembersSubset[0], roomMembers),
resolveRoomMemberName(otherMembersSubset[1], roomMembers),
resolveRoomMemberName(otherMembersSubset[2], roomMembers)
)
}
4 -> {
stringProvider.getString(R.string.room_displayname_4_members,
resolveRoomMemberName(otherMembersSubset[0], roomMembers),
resolveRoomMemberName(otherMembersSubset[1], roomMembers),
resolveRoomMemberName(otherMembersSubset[2], roomMembers),
resolveRoomMemberName(otherMembersSubset[3], roomMembers)
)
}
else -> {
val names = otherMembersSubset.map {
resolveRoomMemberName(it, roomMembers) ?: ""
}
if (otherMembersCount <= othersTotalCount) {
val remainingCount = invitedCount + joinedCount - names.size
(names.joinToString("${stringProvider.getString(R.string.room_displayname_separator)} ")
+ " " + stringProvider.getQuantityString(R.plurals.and_n_others, remainingCount, remainingCount))
} else {
names.dropLast(1).joinToString(", ") + " & ${names.last()}"
}
val remainingCount = invitedCount + joinedCount - otherMembersCount + 1
stringProvider.getString(R.string.room_displayname_four_and_more_members,
resolveRoomMemberName(otherMembersSubset[0], roomMembers),
resolveRoomMemberName(otherMembersSubset[1], roomMembers),
resolveRoomMemberName(otherMembersSubset[2], roomMembers),
remainingCount
)
}
}
}

View File

@ -16,6 +16,8 @@
package org.matrix.android.sdk.internal.session.room.membership
import io.realm.Realm
import io.realm.RealmQuery
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntity
@ -25,8 +27,6 @@ import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntityFie
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
import org.matrix.android.sdk.internal.database.query.getOrNull
import org.matrix.android.sdk.internal.database.query.where
import io.realm.Realm
import io.realm.RealmQuery
/**
* This class is an helper around STATE_ROOM_MEMBER events.
@ -98,10 +98,6 @@ internal class RoomMemberHelper(private val realm: Realm,
return getNumberOfJoinedMembers() + getNumberOfInvitedMembers()
}
fun isDirectRoom() : Boolean {
return roomSummary?.isDirect ?: false
}
/**
* Return all the roomMembers ids which are joined or invited to the room
*

View File

@ -175,16 +175,14 @@
<!-- The 2 parameters will be members' name -->
<string name="room_displayname_two_members">%1$s and %2$s</string>
<string name="room_displayname_3_members">%1$s, %2$s and %3$s</string>
<string name="room_displayname_4_members">%1$s, %2$s, %3$s and %4$s</string>
<string name="room_displayname_four_and_more_members">%1$s, %2$s, %3$s and %4$d others</string>
<plurals name="room_displayname_three_and_more_members">
<item quantity="one">%1$s and 1 other</item>
<item quantity="other">%1$s and %2$d others</item>
</plurals>
<plurals name="and_n_others">
<item quantity="one">&amp; %d other</item>
<item quantity="other">&amp; %d others</item>
</plurals>
<string name="room_displayname_separator">,</string>
<string name="room_displayname_empty_room">Empty room</string>
<string name="room_displayname_empty_room_was">Empty room (was %s)</string>

View File

@ -161,7 +161,7 @@ class RoomMemberProfileController @Inject constructor(
} else {
genericFooterItem {
id("verify_footer_not_encrypted")
text(RRstringProvider.getString(R.string.room_profile_not_encrypted_subtitle))
text(stringProvider.getString(R.string.room_profile_not_encrypted_subtitle))
centered(false)
}
}