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