Merge pull request #5405 from vector-im/cgizard/ISSUE-5402

[Create private room] Picture doesn't not displayed
This commit is contained in:
ClaireG 2022-03-03 22:40:26 +01:00 committed by GitHub
parent 1690a0b2cf
commit 2a9e582db5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 31 deletions

1
changelog.d/5402.bugfix Normal file
View File

@ -0,0 +1 @@
[Create room] Setting an avatar when creating a room had no effect

View File

@ -30,6 +30,7 @@ import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.RequestBody.Companion.toRequestBody
import okio.BufferedSink import okio.BufferedSink
import okio.source import okio.source
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.failure.MatrixError import org.matrix.android.sdk.api.failure.MatrixError
@ -53,6 +54,7 @@ internal class FileUploader @Inject constructor(
private val homeServerCapabilitiesService: HomeServerCapabilitiesService, private val homeServerCapabilitiesService: HomeServerCapabilitiesService,
private val context: Context, private val context: Context,
private val temporaryFileCreator: TemporaryFileCreator, private val temporaryFileCreator: TemporaryFileCreator,
private val coroutineDispatchers: MatrixCoroutineDispatchers,
contentUrlResolver: ContentUrlResolver, contentUrlResolver: ContentUrlResolver,
moshi: Moshi moshi: Moshi
) { ) {
@ -146,14 +148,16 @@ internal class FileUploader @Inject constructor(
.post(requestBody) .post(requestBody)
.build() .build()
return okHttpClient.newCall(request).awaitResponse().use { response -> return withContext(coroutineDispatchers.io) {
if (!response.isSuccessful) { okHttpClient.newCall(request).awaitResponse().use { response ->
throw response.toFailure(globalErrorReceiver) if (!response.isSuccessful) {
} else { throw response.toFailure(globalErrorReceiver)
response.body?.source()?.let { } else {
responseAdapter.fromJson(it) response.body?.source()?.let {
responseAdapter.fromJson(it)
}
?: throw IOException()
} }
?: throw IOException()
} }
} }
} }

View File

@ -68,11 +68,9 @@ internal class DefaultProfileService @Inject constructor(private val taskExecuto
} }
override suspend fun updateAvatar(userId: String, newAvatarUri: Uri, fileName: String) { override suspend fun updateAvatar(userId: String, newAvatarUri: Uri, fileName: String) {
withContext(coroutineDispatchers.io) { val response = fileUploader.uploadFromUri(newAvatarUri, fileName, MimeTypes.Jpeg)
val response = fileUploader.uploadFromUri(newAvatarUri, fileName, MimeTypes.Jpeg) setAvatarUrlTask.execute(SetAvatarUrlTask.Params(userId = userId, newAvatarUrl = response.contentUri))
setAvatarUrlTask.execute(SetAvatarUrlTask.Params(userId = userId, newAvatarUrl = response.contentUri)) userStore.updateAvatar(userId, response.contentUri)
userStore.updateAvatar(userId, response.contentUri)
}
} }
override suspend fun getAvatarUrl(userId: String): Optional<String> { override suspend fun getAvatarUrl(userId: String): Optional<String> {

View File

@ -112,19 +112,18 @@ internal class CreateRoomBodyBuilder @Inject constructor(
private suspend fun buildAvatarEvent(params: CreateRoomParams): Event? { private suspend fun buildAvatarEvent(params: CreateRoomParams): Event? {
return params.avatarUri?.let { avatarUri -> return params.avatarUri?.let { avatarUri ->
// First upload the image, ignoring any error // First upload the image, ignoring any error
tryOrNull { tryOrNull("Failed to upload image") {
fileUploader.uploadFromUri( fileUploader.uploadFromUri(
uri = avatarUri, uri = avatarUri,
filename = UUID.randomUUID().toString(), filename = UUID.randomUUID().toString(),
mimeType = MimeTypes.Jpeg) mimeType = MimeTypes.Jpeg)
} }
?.let { response -> }?.let { response ->
Event( Event(
type = EventType.STATE_ROOM_AVATAR, type = EventType.STATE_ROOM_AVATAR,
stateKey = "", stateKey = "",
content = mapOf("url" to response.contentUri) content = mapOf("url" to response.contentUri)
) )
}
} }
} }
@ -180,19 +179,19 @@ internal class CreateRoomBodyBuilder @Inject constructor(
params.invite3pids.isEmpty() && params.invite3pids.isEmpty() &&
params.invitedUserIds.isNotEmpty() && params.invitedUserIds.isNotEmpty() &&
params.invitedUserIds.let { userIds -> params.invitedUserIds.let { userIds ->
val keys = deviceListManager.downloadKeys(userIds, forceDownload = false) val keys = deviceListManager.downloadKeys(userIds, forceDownload = false)
userIds.all { userId -> userIds.all { userId ->
keys.map[userId].let { deviceMap -> keys.map[userId].let { deviceMap ->
if (deviceMap.isNullOrEmpty()) { if (deviceMap.isNullOrEmpty()) {
// A user has no device, so do not enable encryption // A user has no device, so do not enable encryption
false false
} else { } else {
// Check that every user's device have at least one key // Check that every user's device have at least one key
deviceMap.values.all { !it.keys.isNullOrEmpty() } deviceMap.values.all { !it.keys.isNullOrEmpty() }
}
}
} }
} }
}
}
} }
} }