Code review
This commit is contained in:
parent
264bc52bcc
commit
1de5cd2e61
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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">& %d other</item>
|
||||
<item quantity="other">& %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>
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue