Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
signalapp
GitHub Repository: signalapp/Signal-iOS
Path: blob/main/SignalServiceKit/Messages/Interactions/TSErrorMessage+Builder.swift
1 views
//
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//

@objcMembers
public class TSErrorMessageBuilder: TSMessageBuilder {
    public let errorType: TSErrorMessageType
    public var recipientAddress: SignalServiceAddress?
    public var senderAddress: SignalServiceAddress?
    public var wasIdentityVerified: Bool = false

    init(
        thread: TSThread,
        errorType: TSErrorMessageType,
    ) {
        self.errorType = errorType

        super.init(
            thread: thread,
            timestamp: nil,
            receivedAtTimestamp: nil,
            messageBody: nil,
            editState: .none,
            expiresInSeconds: nil,
            expireTimerVersion: nil,
            expireStartedAt: nil,
            isSmsMessageRestoredFromBackup: false,
            isViewOnceMessage: false,
            isViewOnceComplete: false,
            wasRemotelyDeleted: false,
            storyAuthorAci: nil,
            storyTimestamp: nil,
            storyReactionEmoji: nil,
            quotedMessage: nil,
            contactShare: nil,
            linkPreview: nil,
            messageSticker: nil,
            giftBadge: nil,
            isPoll: false,
        )
    }

    // MARK: -

    private var hasBuilt = false

    public func build() -> TSErrorMessage {
        if hasBuilt {
            owsFailDebug("Don't build more than once.")
        }

        hasBuilt = true

        return TSErrorMessage(errorMessageWithBuilder: self)
    }
}