Skip to content

Commit 4d26038

Browse files
authored
Merge pull request #627 from session-foundation/dev
Release 2.14.6 RC2
2 parents 239e7a1 + 59e4c59 commit 4d26038

37 files changed

+1065
-813
lines changed

Session.xcodeproj/project.pbxproj

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@
235235
B835247925C38D880089A44F /* MessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B835247825C38D880089A44F /* MessageCell.swift */; };
236236
B835249B25C3AB650089A44F /* VisibleMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B835249A25C3AB650089A44F /* VisibleMessageCell.swift */; };
237237
B83524A525C3BA4B0089A44F /* InfoMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B83524A425C3BA4B0089A44F /* InfoMessageCell.swift */; };
238-
B83F2B88240CB75A000A54AB /* UIImage+Scaling.swift in Sources */ = {isa = PBXBuildFile; fileRef = B83F2B87240CB75A000A54AB /* UIImage+Scaling.swift */; };
239238
B849789625D4A2F500D0D0B3 /* LinkPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B849789525D4A2F500D0D0B3 /* LinkPreviewView.swift */; };
240239
B84A89BC25DE328A0040017D /* ProfilePictureVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84A89BB25DE328A0040017D /* ProfilePictureVC.swift */; };
241240
B85357BF23A1AE0800AAF6CD /* SeedReminderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85357BE23A1AE0800AAF6CD /* SeedReminderView.swift */; };
@@ -1633,7 +1632,6 @@
16331632
B835247825C38D880089A44F /* MessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageCell.swift; sourceTree = "<group>"; };
16341633
B835249A25C3AB650089A44F /* VisibleMessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisibleMessageCell.swift; sourceTree = "<group>"; };
16351634
B83524A425C3BA4B0089A44F /* InfoMessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoMessageCell.swift; sourceTree = "<group>"; };
1636-
B83F2B87240CB75A000A54AB /* UIImage+Scaling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Scaling.swift"; sourceTree = "<group>"; };
16371635
B84664F4235022F30083A1CD /* MentionUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentionUtilities.swift; sourceTree = "<group>"; };
16381636
B849789525D4A2F500D0D0B3 /* LinkPreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkPreviewView.swift; sourceTree = "<group>"; };
16391637
B84A89BB25DE328A0040017D /* ProfilePictureVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilePictureVC.swift; sourceTree = "<group>"; };
@@ -2749,7 +2747,6 @@
27492747
FDE521992E08DBB000061B8E /* ImageLoading+Convenience.swift */,
27502748
FDB3DA832E1CA21C00148F8D /* UIActivityViewController+Utilities.swift */,
27512749
B8783E9D23EB948D00404FB8 /* UILabel+Interaction.swift */,
2752-
B83F2B87240CB75A000A54AB /* UIImage+Scaling.swift */,
27532750
FD1C98E3282E3C5B00B76F9E /* UINavigationBar+Utilities.swift */,
27542751
FD848B8E283EF2A8000E298B /* UIScrollView+Utilities.swift */,
27552752
C3548F0724456AB6009433A8 /* UIView+Wrapping.swift */,
@@ -6929,7 +6926,6 @@
69296926
C374EEF425DB31D40073A857 /* VoiceMessageRecordingView.swift in Sources */,
69306927
7B1581E6271FD2A100848B49 /* VideoPreviewVC.swift in Sources */,
69316928
9422568A2C23F8C800C0FDBF /* LoadingScreen.swift in Sources */,
6932-
B83F2B88240CB75A000A54AB /* UIImage+Scaling.swift in Sources */,
69336929
3430FE181F7751D4000EC51B /* GiphyAPI.swift in Sources */,
69346930
4C090A1B210FD9C7001FD7F9 /* HapticFeedback.swift in Sources */,
69356931
FDE754FA2C9BB0B0002A2623 /* NotificationPresenter.swift in Sources */,
@@ -8366,7 +8362,7 @@
83668362
CODE_SIGN_IDENTITY = "iPhone Developer";
83678363
COMPILE_LIB_SESSION = "";
83688364
COPY_PHASE_STRIP = NO;
8369-
CURRENT_PROJECT_VERSION = 656;
8365+
CURRENT_PROJECT_VERSION = 658;
83708366
ENABLE_BITCODE = NO;
83718367
ENABLE_STRICT_OBJC_MSGSEND = YES;
83728368
ENABLE_TESTABILITY = YES;
@@ -8447,7 +8443,7 @@
84478443
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
84488444
CODE_SIGN_IDENTITY = "iPhone Distribution";
84498445
COMPILE_LIB_SESSION = "";
8450-
CURRENT_PROJECT_VERSION = 656;
8446+
CURRENT_PROJECT_VERSION = 658;
84518447
ENABLE_BITCODE = NO;
84528448
ENABLE_MODULE_VERIFIER = YES;
84538449
ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -8933,7 +8929,7 @@
89338929
CODE_SIGN_IDENTITY = "iPhone Developer";
89348930
COMPILE_LIB_SESSION = YES;
89358931
COPY_PHASE_STRIP = NO;
8936-
CURRENT_PROJECT_VERSION = 656;
8932+
CURRENT_PROJECT_VERSION = 658;
89378933
ENABLE_BITCODE = NO;
89388934
ENABLE_STRICT_OBJC_MSGSEND = YES;
89398935
ENABLE_TESTABILITY = YES;
@@ -9523,7 +9519,7 @@
95239519
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
95249520
CODE_SIGN_IDENTITY = "iPhone Distribution";
95259521
COMPILE_LIB_SESSION = YES;
9526-
CURRENT_PROJECT_VERSION = 656;
9522+
CURRENT_PROJECT_VERSION = 658;
95279523
ENABLE_BITCODE = NO;
95289524
ENABLE_STRICT_OBJC_MSGSEND = YES;
95299525
GCC_NO_COMMON_BLOCKS = YES;

Session/Conversations/ConversationVC+Interaction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ extension ConversationVC:
969969

970970
@MainActor func didPasteImageDataFromPasteboard(_ imageData: Data) {
971971
let pendingAttachment: PendingAttachment = PendingAttachment(
972-
source: .media(UUID().uuidString, imageData),
972+
source: .media(.data(UUID().uuidString, imageData)),
973973
sourceFilename: nil,
974974
using: viewModel.dependencies
975975
)

Session/Conversations/ConversationViewModel.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate, NavigatableStateHold
762762
if let draft: LinkPreviewDraft = linkPreviewDraft {
763763
linkPreviewPreparedAttachment = try? await LinkPreview.prepareAttachmentIfPossible(
764764
urlString: draft.urlString,
765-
imageData: draft.jpegImageData,
766-
type: .jpeg,
765+
imageSource: draft.imageSource,
767766
using: dependencies
768767
)
769768
}

Session/Conversations/Input View/InputView.swift

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ final class InputView: UIView, InputViewButtonDelegate, InputTextViewDelegate, M
2121

2222
var quoteDraftInfo: (model: QuotedReplyModel, isOutgoing: Bool)? { didSet { handleQuoteDraftChanged() } }
2323
var linkPreviewInfo: (url: String, draft: LinkPreviewDraft?)?
24+
private var linkPreviewLoadTask: Task<Void, Never>?
2425
private var voiceMessageRecordingView: VoiceMessageRecordingView?
2526
private lazy var mentionsViewHeightConstraint = mentionsView.set(.height, to: 0)
2627

@@ -231,6 +232,10 @@ final class InputView: UIView, InputViewButtonDelegate, InputTextViewDelegate, M
231232
required init?(coder: NSCoder) {
232233
preconditionFailure("Use init(delegate:) instead.")
233234
}
235+
236+
deinit {
237+
linkPreviewLoadTask?.cancel()
238+
}
234239

235240
private func setUpViewHierarchy() {
236241
autoresizingMask = .flexibleHeight
@@ -400,7 +405,7 @@ final class InputView: UIView, InputViewButtonDelegate, InputTextViewDelegate, M
400405
}
401406
}
402407

403-
func autoGenerateLinkPreview() {
408+
@MainActor func autoGenerateLinkPreview() {
404409
// Check that a valid URL is present
405410
guard let linkPreviewURL = LinkPreview.previewUrl(for: text, selectedRange: inputTextView.selectedRange, using: dependencies) else {
406411
return
@@ -425,37 +430,43 @@ final class InputView: UIView, InputViewButtonDelegate, InputTextViewDelegate, M
425430
linkPreviewView.pin(.bottom, to: .bottom, of: additionalContentContainer, withInset: -4)
426431

427432
// Build the link preview
428-
LinkPreview
429-
.tryToBuildPreviewInfo(
430-
previewUrl: linkPreviewURL,
431-
skipImageDownload: (inputState.allowedInputTypes != .all), /// Disable image download if attachments are disabled
432-
using: dependencies
433-
)
434-
.subscribe(on: DispatchQueue.global(qos: .userInitiated))
435-
.receive(on: DispatchQueue.main)
436-
.sink(
437-
receiveCompletion: { [weak self] result in
438-
switch result {
439-
case .finished: break
440-
case .failure:
441-
guard self?.linkPreviewInfo?.url == linkPreviewURL else { return } // Obsolete
442-
443-
self?.linkPreviewInfo = nil
444-
self?.additionalContentContainer.subviews.forEach { $0.removeFromSuperview() }
445-
}
446-
},
447-
receiveValue: { [weak self, dependencies] draft in
448-
guard self?.linkPreviewInfo?.url == linkPreviewURL else { return } // Obsolete
433+
linkPreviewLoadTask?.cancel()
434+
linkPreviewLoadTask = Task.detached(priority: .userInitiated) { [weak self, allowedInputTypes = inputState.allowedInputTypes, dependencies] in
435+
do {
436+
/// Load the draft
437+
let draft: LinkPreviewDraft = try await LinkPreview.tryToBuildPreviewInfo(
438+
previewUrl: linkPreviewURL,
439+
skipImageDownload: (allowedInputTypes != .all), /// Disable if attachments are disabled
440+
using: dependencies
441+
)
442+
try Task.checkCancellation()
443+
444+
await MainActor.run { [weak self] in
445+
guard let self else { return }
446+
guard linkPreviewInfo?.url == linkPreviewURL else { return } /// Obsolete
449447

450-
self?.linkPreviewInfo = (url: linkPreviewURL, draft: draft)
451-
self?.linkPreviewView.update(
448+
linkPreviewInfo = (url: linkPreviewURL, draft: draft)
449+
linkPreviewView.update(
452450
with: LinkPreview.DraftState(linkPreviewDraft: draft),
453451
isOutgoing: false,
454452
using: dependencies
455453
)
454+
setNeedsLayout()
455+
layoutIfNeeded()
456456
}
457-
)
458-
.store(in: &disposables)
457+
}
458+
catch {
459+
await MainActor.run { [weak self] in
460+
guard let self else { return }
461+
guard linkPreviewInfo?.url == linkPreviewURL else { return } /// Obsolete
462+
463+
linkPreviewInfo = nil
464+
additionalContentContainer.subviews.forEach { $0.removeFromSuperview() }
465+
setNeedsLayout()
466+
layoutIfNeeded()
467+
}
468+
}
469+
}
459470
}
460471

461472
func setMessageInputState(_ updatedInputState: SessionThreadViewModel.MessageInputState) {

Session/Conversations/Message Cells/Content Views/LinkPreviewState.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,12 @@ public extension LinkPreview {
4444
}
4545

4646
var imageState: LinkPreview.ImageState {
47-
if linkPreviewDraft.jpegImageData != nil { return .loaded }
47+
if linkPreviewDraft.imageSource != nil { return .loaded }
4848

4949
return .none
5050
}
5151

52-
var imageSource: ImageDataManager.DataSource? {
53-
guard let jpegImageData = linkPreviewDraft.jpegImageData else { return nil }
54-
guard let image = UIImage(data: jpegImageData) else {
55-
Log.error("[LinkPreview] Could not load image: \(jpegImageData.count)")
56-
return nil
57-
}
58-
59-
return .image(urlString ?? "Invalid_Link_Preview", image)
60-
}
52+
var imageSource: ImageDataManager.DataSource? { linkPreviewDraft.imageSource }
6153

6254
// MARK: - Type Specific
6355

Session/Conversations/Message Cells/Content Views/LinkPreviewView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ final class LinkPreviewView: UIView {
148148

149149
// MARK: - Updating
150150

151-
public func update(
151+
@MainActor public func update(
152152
with state: LinkPreviewState,
153153
isOutgoing: Bool,
154154
delegate: TappableLabelDelegate? = nil,

Session/Conversations/Message Cells/Content Views/SwiftUI/LinkPreviewView_SwiftUI.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ struct LinkPreview_SwiftUI_Previews: PreviewProvider {
146146
linkPreviewDraft: .init(
147147
urlString: "https://github.com/oxen-io",
148148
title: "Github - oxen-io/session-ios: A private messenger for iOS.",
149-
jpegImageData: UIImage(named: "AppIcon")?.jpegData(compressionQuality: 1)
149+
imageSource: .image("AppIcon", UIImage(named: "AppIcon"))
150150
)
151151
),
152152
dataManager: ImageDataManager(),

0 commit comments

Comments
 (0)