Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Create private room] Picture doesn't not displayed #5405

Merged
merged 6 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5402.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Create room] Setting an avatar when creating a room had no effect
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import okio.BufferedSink
import okio.source
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.failure.MatrixError
Expand All @@ -53,6 +54,7 @@ internal class FileUploader @Inject constructor(
private val homeServerCapabilitiesService: HomeServerCapabilitiesService,
private val context: Context,
private val temporaryFileCreator: TemporaryFileCreator,
private val coroutineDispatchers: MatrixCoroutineDispatchers,
contentUrlResolver: ContentUrlResolver,
moshi: Moshi
) {
Expand Down Expand Up @@ -146,14 +148,16 @@ internal class FileUploader @Inject constructor(
.post(requestBody)
.build()

return okHttpClient.newCall(request).awaitResponse().use { response ->
if (!response.isSuccessful) {
throw response.toFailure(globalErrorReceiver)
} else {
response.body?.source()?.let {
responseAdapter.fromJson(it)
return withContext(coroutineDispatchers.io) {
okHttpClient.newCall(request).awaitResponse().use { response ->
if (!response.isSuccessful) {
throw response.toFailure(globalErrorReceiver)
} else {
response.body?.source()?.let {
responseAdapter.fromJson(it)
}
?: throw IOException()
}
?: throw IOException()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ internal class DefaultProfileService @Inject constructor(private val taskExecuto
}

override suspend fun updateAvatar(userId: String, newAvatarUri: Uri, fileName: String) {
withContext(coroutineDispatchers.io) {
val response = fileUploader.uploadFromUri(newAvatarUri, fileName, MimeTypes.Jpeg)
setAvatarUrlTask.execute(SetAvatarUrlTask.Params(userId = userId, newAvatarUrl = response.contentUri))
userStore.updateAvatar(userId, response.contentUri)
}
val response = fileUploader.uploadFromUri(newAvatarUri, fileName, MimeTypes.Jpeg)
setAvatarUrlTask.execute(SetAvatarUrlTask.Params(userId = userId, newAvatarUrl = response.contentUri))
userStore.updateAvatar(userId, response.contentUri)
}

override suspend fun getAvatarUrl(userId: String): Optional<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,18 @@ internal class CreateRoomBodyBuilder @Inject constructor(
private suspend fun buildAvatarEvent(params: CreateRoomParams): Event? {
return params.avatarUri?.let { avatarUri ->
// First upload the image, ignoring any error
tryOrNull {
tryOrNull("Failed to upload image") {
fileUploader.uploadFromUri(
uri = avatarUri,
filename = UUID.randomUUID().toString(),
mimeType = MimeTypes.Jpeg)
}
?.let { response ->
Event(
type = EventType.STATE_ROOM_AVATAR,
stateKey = "",
content = mapOf("url" to response.contentUri)
)
}
}?.let { response ->
Event(
type = EventType.STATE_ROOM_AVATAR,
stateKey = "",
content = mapOf("url" to response.contentUri)
)
}
}

Expand Down Expand Up @@ -180,19 +179,19 @@ internal class CreateRoomBodyBuilder @Inject constructor(
params.invite3pids.isEmpty() &&
params.invitedUserIds.isNotEmpty() &&
params.invitedUserIds.let { userIds ->
val keys = deviceListManager.downloadKeys(userIds, forceDownload = false)

userIds.all { userId ->
keys.map[userId].let { deviceMap ->
if (deviceMap.isNullOrEmpty()) {
// A user has no device, so do not enable encryption
false
} else {
// Check that every user's device have at least one key
deviceMap.values.all { !it.keys.isNullOrEmpty() }
val keys = deviceListManager.downloadKeys(userIds, forceDownload = false)

userIds.all { userId ->
keys.map[userId].let { deviceMap ->
if (deviceMap.isNullOrEmpty()) {
// A user has no device, so do not enable encryption
false
} else {
// Check that every user's device have at least one key
deviceMap.values.all { !it.keys.isNullOrEmpty() }
}
}
}
}
}
}
}
}