mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
5432f5582e
Fixed an issue where if you left a closed group on one device you wouldn't leave it on another Renamed a few types to clean up the namespacing and code jumping Fixed a stack overflow issue which could occur in the JobRunner Fixed an issue where the DeletedMessageView could randomly have the wrong height Fixed an issue where you could interact with the hidden reply button on a cell Fixed an issue where tapping anywhere horizontally would trigger the cell tap (need to tap within the bubble) Disabled the ability to select text in messages (only works sometimes and is buggy)
85 lines
2.6 KiB
Swift
85 lines
2.6 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import Foundation
|
|
import GRDB
|
|
import SessionUtilitiesKit
|
|
|
|
public extension VisibleMessage {
|
|
struct VMLinkPreview: Codable {
|
|
public let title: String?
|
|
public let url: String?
|
|
public let attachmentId: String?
|
|
|
|
public var isValid: Bool { title != nil && url != nil && attachmentId != nil }
|
|
|
|
// MARK: - Initialization
|
|
|
|
internal init(title: String?, url: String, attachmentId: String?) {
|
|
self.title = title
|
|
self.url = url
|
|
self.attachmentId = attachmentId
|
|
}
|
|
|
|
// MARK: - Proto Conversion
|
|
|
|
public static func fromProto(_ proto: SNProtoDataMessagePreview) -> VMLinkPreview? {
|
|
return VMLinkPreview(
|
|
title: proto.title,
|
|
url: proto.url,
|
|
attachmentId: nil
|
|
)
|
|
}
|
|
|
|
public func toProto() -> SNProtoDataMessagePreview? {
|
|
preconditionFailure("Use toProto(using:) instead.")
|
|
}
|
|
|
|
public func toProto(_ db: Database) -> SNProtoDataMessagePreview? {
|
|
guard let url = url else {
|
|
SNLog("Couldn't construct link preview proto from: \(self).")
|
|
return nil
|
|
}
|
|
let linkPreviewProto = SNProtoDataMessagePreview.builder(url: url)
|
|
if let title = title { linkPreviewProto.setTitle(title) }
|
|
|
|
if
|
|
let attachmentId = attachmentId,
|
|
let attachment: Attachment = try? Attachment.fetchOne(db, id: attachmentId),
|
|
let attachmentProto = attachment.buildProto()
|
|
{
|
|
linkPreviewProto.setImage(attachmentProto)
|
|
}
|
|
|
|
do {
|
|
return try linkPreviewProto.build()
|
|
} catch {
|
|
SNLog("Couldn't construct link preview proto from: \(self).")
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// MARK: - Description
|
|
|
|
public var description: String {
|
|
"""
|
|
LinkPreview(
|
|
title: \(title ?? "null"),
|
|
url: \(url ?? "null"),
|
|
attachmentId: \(attachmentId ?? "null")
|
|
)
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Database Type Conversion
|
|
|
|
public extension VisibleMessage.VMLinkPreview {
|
|
static func from(_ db: Database, linkPreview: LinkPreview) -> VisibleMessage.VMLinkPreview {
|
|
return VisibleMessage.VMLinkPreview(
|
|
title: linkPreview.title,
|
|
url: linkPreview.url,
|
|
attachmentId: linkPreview.attachmentId
|
|
)
|
|
}
|
|
}
|