QNAddressBooksRepository

public actor QNAddressBooksRepository

Service to manage contact actions and subscribe to contact events

  • Sources from which the contacts will be fetched

    • contacts
    • phonebooks
    • domain
    • static
    • groups

    Declaration

    Swift

    public enum Source : String

Api

  • Emit event when new contact is created

    Declaration

    Swift

    nonisolated public var newContact: AnyPublisher<QNContact, Never> { get }
  • Emit event when a contact is updated

    Declaration

    Swift

    nonisolated public var contactUpdated: AnyPublisher<QNContact, Never> { get }
  • Emit event when a contact is deleted

    Declaration

    Swift

    nonisolated public var contactDeleted: AnyPublisher<QNContact, Never> { get }
  • Subscribes to the external presence updates of a personal contact from the specified [contactId].

    This function validates that the contact exists and belongs to a [Personal] source before establishing the subscription. It uses a shared subscription mechanism to optimize resources.

    Declaration

    Swift

    nonisolated public func subscribeToPersonalContactExternalPresence(contact: QNContact) -> AnyPublisher<QNContact, Never>

    Parameters

    contactId

    Contact Id to be subscribed to.

    Return Value

    A Publisher to manage the lifecycle of the presence stream.

  • Fetches and synchronizes contacts from multiple address book sources.

    Throws

    QNGenericError.internalError if the repository instance is deallocated, or service-specific errors during execution.

    Declaration

    Swift

    public func getContacts(
        using sources: [QNAddressBooksRepository.Source]? = nil,
        fetchPresences: Bool? = nil,
        fromCache: Bool = true
    ) async throws -> [QNContact]

    Parameters

    sources

    The specific address book sources to query. If nil, the SDK’s default configuration is used.

    fetchPresences

    Explicit flag to enable/disable presence fetching. If nil, follows the SDK configuration.

    fromCache

    If true (default), attempts to retrieve data from local storage before hitting the network.

    Return Value

    An array of QNContact objects fully populated with domain data and presence info.

  • Retrieves the personal contact associated with a specific user.

    This method orchestrates calls to the address book and presence services to construct a complete domain model of a contact.

    Throws

    Throws:

    • QNGenericError: If the service instance was deallocated (self is nil).
    • Service-specific errors encountered during the address book fetch or presence lookup.

    Note

    Presence data is fetched with fromCache: true to optimize performance.

    Declaration

    Swift

    public func getPersonalContact(associatedTo user: QNUser) async throws -> QNContact?

    Parameters

    user

    The QNUser instance used to identify the contact.

    Return Value

    A mapped QNContact object if found; otherwise, nil.

  • add(contact:) Asynchronous

    Add a new contact

    Declaration

    Swift

    public func add(contact: QNContact) async throws -> QNContact

    Parameters

    contact

    Contact to create

    result

    Result with new Contact

  • update(contact:) Asynchronous

    Update a contact

    Declaration

    Swift

    public func update(contact: QNContact) async throws -> QNContact

    Parameters

    contact

    Contact to update

    result

    Result with updated Contact

  • delete(contact:) Asynchronous

    Remove a contact

    Declaration

    Swift

    public func delete(contact: QNContact) async throws

    Parameters

    contact

    Contact to remove