Files
session-ios/SessionMessagingKit/Messages/Visible Messages/VisibleMessage+OpenGroupInvitation.swift
Morgan Pretty eddffae6a1 Refactored a number of processes to no longer require database access
• Refactored the MessageSender to no longer require database access
• Refactored the attachment upload process to no longer require database access
• Updated the OpenGroupAPI to no longer require database access
• Added back logic to send the `endCall` message when receiving a call while on another call
• Added `community` to `AuthenticationMethod` to help standardise the code behaviour
• Updated the `toProto` functions to no longer required a `Database` instance
• Updated a bunch of functions to be @MainActor (so we can ditch thread swapping code)
2025-06-03 08:51:05 +10:00

66 lines
1.9 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import SessionUtilitiesKit
public extension VisibleMessage {
struct VMOpenGroupInvitation: Codable {
public let name: String?
public let url: String?
// MARK: - Initialization
public init(name: String, url: String) {
self.name = name
self.url = url
}
// MARK: - Proto Conversion
public static func fromProto(_ proto: SNProtoDataMessageOpenGroupInvitation) -> VMOpenGroupInvitation? {
return VMOpenGroupInvitation(
name: proto.name,
url: proto.url
)
}
public func toProto() -> SNProtoDataMessageOpenGroupInvitation? {
guard let url = url, let name = name else {
Log.warn(.messageSender, "Couldn't construct open group invitation proto from: \(self).")
return nil
}
let openGroupInvitationProto = SNProtoDataMessageOpenGroupInvitation.builder(url: url, name: name)
do {
return try openGroupInvitationProto.build()
} catch {
Log.warn(.messageSender, "Couldn't construct open group invitation proto from: \(self).")
return nil
}
}
// MARK: - Description
public var description: String {
"""
OpenGroupInvitation(
name: \(name ?? "null"),
url: \(url ?? "null")
)
"""
}
}
}
// MARK: - Database Type Conversion
public extension VisibleMessage.VMOpenGroupInvitation {
static func from(linkPreview: LinkPreview) -> VisibleMessage.VMOpenGroupInvitation? {
guard let name: String = linkPreview.title else { return nil }
return VisibleMessage.VMOpenGroupInvitation(
name: name,
url: linkPreview.url
)
}
}