Introduce MatrixClient.isMe for checking sessionID
This commit is contained in:
parent
3e087c06da
commit
303a0a6677
6 changed files with 9 additions and 9 deletions
|
|
@ -100,7 +100,7 @@ class RoomMemberDetailsPresenter @AssistedInject constructor(
|
|||
avatarUrl = userAvatar,
|
||||
isBlocked = isBlocked.value,
|
||||
displayConfirmationDialog = confirmationDialog,
|
||||
isCurrentUser = roomMember?.userId == client.sessionId,
|
||||
isCurrentUser = client.isMe(roomMember?.userId),
|
||||
eventSink = ::handleEvents
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class DefaultRoomLastMessageFormatter @Inject constructor(
|
|||
) : RoomLastMessageFormatter {
|
||||
|
||||
override fun format(event: EventTimelineItem, isDmRoom: Boolean): CharSequence? {
|
||||
val isOutgoing = event.sender == matrixClient.sessionId
|
||||
val isOutgoing = matrixClient.isMe(event.sender)
|
||||
val senderDisplayName = (event.senderProfile as? ProfileTimelineDetails.Ready)?.displayName ?: event.sender.value
|
||||
return when (val content = event.content) {
|
||||
is MessageContent -> processMessageContents(content, senderDisplayName, isDmRoom)
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class DefaultTimelineEventFormatter @Inject constructor(
|
|||
) : TimelineEventFormatter {
|
||||
|
||||
override fun format(event: EventTimelineItem): CharSequence? {
|
||||
val isOutgoing = event.sender == matrixClient.sessionId
|
||||
val isOutgoing = matrixClient.isMe(event.sender)
|
||||
val senderDisplayName = (event.senderProfile as? ProfileTimelineDetails.Ready)?.displayName ?: event.sender.value
|
||||
return when (val content = event.content) {
|
||||
is RoomMembershipContent -> {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class RoomMembershipContentFormatter @Inject constructor(
|
|||
senderIsYou: Boolean,
|
||||
): CharSequence? {
|
||||
val userId = membershipContent.userId
|
||||
val memberIsYou = userId == matrixClient.sessionId
|
||||
val memberIsYou = matrixClient.isMe(userId)
|
||||
return when (val change = membershipContent.change) {
|
||||
MembershipChange.JOINED -> if (memberIsYou) {
|
||||
sp.getString(R.string.state_event_room_join_by_you)
|
||||
|
|
|
|||
|
|
@ -60,4 +60,6 @@ interface MatrixClient : Closeable {
|
|||
suspend fun loadUserAvatarURLString(): Result<String?>
|
||||
suspend fun uploadMedia(mimeType: String, data: ByteArray, progressCallback: ProgressCallback?): Result<String>
|
||||
fun roomMembershipObserver(): RoomMembershipObserver
|
||||
|
||||
fun isMe(userId: UserId?) = userId == sessionId
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,15 +32,13 @@ import javax.inject.Inject
|
|||
|
||||
@ContributesBinding(SessionScope::class)
|
||||
class MatrixUserRepository @Inject constructor(
|
||||
client: MatrixClient,
|
||||
private val client: MatrixClient,
|
||||
private val dataSource: UserListDataSource
|
||||
) : UserRepository {
|
||||
|
||||
private val sessionId = client.sessionId
|
||||
|
||||
override suspend fun search(query: String): Flow<List<UserSearchResult>> = flow {
|
||||
// Manually add a fake result with the matrixId, if provided and not the local user
|
||||
val isAnotherUsersId = query != sessionId.value && MatrixPatterns.isUserId(query)
|
||||
val isAnotherUsersId = MatrixPatterns.isUserId(query) && !client.isMe(UserId(query))
|
||||
if (isAnotherUsersId) {
|
||||
emit(listOf(UserSearchResult(MatrixUser(UserId(query)))))
|
||||
}
|
||||
|
|
@ -51,7 +49,7 @@ class MatrixUserRepository @Inject constructor(
|
|||
|
||||
val results = dataSource
|
||||
.search(query, MAXIMUM_SEARCH_RESULTS)
|
||||
.filter { it.userId != sessionId }
|
||||
.filter { !client.isMe(it.userId) }
|
||||
.map { UserSearchResult(it) }
|
||||
.toMutableList()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue