2021-07-29 21:24:34 +00:00
|
|
|
//
|
|
|
|
// Copyright 2021 New Vector Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2021-08-16 08:33:10 +00:00
|
|
|
extension MXKImageView {
|
2021-10-11 15:06:15 +00:00
|
|
|
@objc func vc_setRoomAvatarImage(with url: String?, roomId: String, displayName: String, mediaManager: MXMediaManager) {
|
2021-08-16 08:33:10 +00:00
|
|
|
// Use the display name to prepare the default avatar image.
|
2021-10-11 15:06:15 +00:00
|
|
|
let avatarImage = AvatarGenerator.generateAvatar(forMatrixItem: roomId, withDisplayName: displayName)
|
2021-08-16 08:33:10 +00:00
|
|
|
|
|
|
|
if let avatarUrl = url {
|
|
|
|
self.enableInMemoryCache = true
|
|
|
|
self.setImageURI(avatarUrl, withType: nil, andImageOrientation: .up, toFitViewSize: self.frame.size, with: MXThumbnailingMethodCrop, previewImage: avatarImage, mediaManager: mediaManager)
|
2021-07-29 21:24:34 +00:00
|
|
|
} else {
|
2021-08-16 08:33:10 +00:00
|
|
|
self.image = avatarImage
|
2021-07-29 21:24:34 +00:00
|
|
|
}
|
2021-08-16 08:33:10 +00:00
|
|
|
self.contentMode = .scaleAspectFill
|
2021-07-29 21:24:34 +00:00
|
|
|
}
|
|
|
|
}
|