Browse Source

Fix open group profile picture bug

#314 without merge conflicts
pull/325/head
Niels Andriesse 2 years ago
parent
commit
451e629605
  1. 11
      SessionMessagingKit/Open Groups/OpenGroupAPI.swift
  2. 2
      SessionMessagingKit/Sending & Receiving/Attachments/OWSThumbnailService.swift
  3. 6
      SignalUtilitiesKit/UI/ProfilePictureView.swift

11
SessionMessagingKit/Open Groups/OpenGroupAPI.swift

@ -382,8 +382,15 @@ public final class OpenGroupAPI : DotNetAPI {
var sanitizedProfilePictureURL = profilePictureURL
while sanitizedProfilePictureURL.hasPrefix("/") { sanitizedProfilePictureURL.removeFirst() }
let url = "\(sanitizedServerURL)/\(sanitizedProfilePictureURL)"
FileServerAPI.downloadAttachment(from: url).map2 { data in
let attachmentStream = TSAttachmentStream(contentType: OWSMimeTypeImageJpeg, byteCount: UInt32(data.count), sourceFilename: nil, caption: nil, albumMessageId: nil)
FileServerAPI.downloadAttachment(from: url).map2 { rawData in
let attachmentStream: TSAttachmentStream
let data: Data
if let rawImage = UIImage(data: rawData), let jpegData = rawImage.jpegData(compressionQuality: 0.8) {
data = jpegData
} else {
data = rawData
}
attachmentStream = TSAttachmentStream(contentType: OWSMimeTypeImageJpeg, byteCount: UInt32(data.count), sourceFilename: nil, caption: nil, albumMessageId: nil)
try attachmentStream.write(data)
thread.updateAvatar(with: attachmentStream)
}

2
SessionMessagingKit/Sending & Receiving/Attachments/OWSThumbnailService.swift

@ -158,7 +158,7 @@ private struct OWSThumbnailRequest {
throw OWSThumbnailError.failure(description: "Could not convert thumbnail to JPEG.")
}
do {
try thumbnailData.write(to: URL(fileURLWithPath: thumbnailPath), options: .atomicWrite)
try thumbnailData.write(to: URL(fileURLWithPath: thumbnailPath, isDirectory: false), options: .atomic)
} catch let error as NSError {
throw OWSThumbnailError.externalError(description: "File write failed: \(thumbnailPath), \(error)", underlyingError: error)
}

6
SignalUtilitiesKit/UI/ProfilePictureView.swift

@ -60,11 +60,7 @@ public final class ProfilePictureView : UIView {
public func update(for thread: TSThread) {
openGroupProfilePicture = nil
if let thread = thread as? TSGroupThread {
if thread.name() == "Loki Public Chat"
|| thread.name() == "Session Public Chat" { // Override the profile picture for the Loki Public Chat and the Session Public Chat
hexEncodedPublicKey = ""
isRSSFeed = true
} else if let openGroupProfilePicture = thread.groupModel.groupImage { // An open group with a profile picture
if let openGroupProfilePicture = thread.groupModel.groupImage { // An open group with a profile picture
self.openGroupProfilePicture = openGroupProfilePicture
isRSSFeed = false
hasTappableProfilePicture = true

Loading…
Cancel
Save