Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sources/PrivMXEndpointSwift/Errors/PrivMXEndpointError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public enum PrivMXEndpointError : Error{
case failedSubscribingForEvents(privmx.InternalError)
/// Failed to unsubscribe from Events.
case failedUnsubscribingFromEvents(privmx.InternalError)
/// Failed to construct a Subscription Query.
case failedBuildingSubscriptionQuery(privmx.InternalError)

/// Failed to delete a Thread.
case failedDeletingThread(privmx.InternalError)
Expand Down Expand Up @@ -312,6 +314,7 @@ public enum PrivMXEndpointError : Error{
.failedGettingEvent(let err),
.failedSubscribingForEvents(let err),
.failedUnsubscribingFromEvents(let err),
.failedBuildingSubscriptionQuery(let err),
.failedDeletingThread(let err),
.failedDeletingMessage(let err),
.failedDeletingStore(let err),
Expand Down Expand Up @@ -432,6 +435,7 @@ public enum PrivMXEndpointError : Error{
.failedGettingEvent(let err),
.failedSubscribingForEvents(let err),
.failedUnsubscribingFromEvents(let err),
.failedBuildingSubscriptionQuery(let err),
.failedDeletingThread(let err),
.failedDeletingMessage(let err),
.failedDeletingStore(let err),
Expand Down Expand Up @@ -551,6 +555,7 @@ public enum PrivMXEndpointError : Error{
.failedGettingEvent(let err),
.failedSubscribingForEvents(let err),
.failedUnsubscribingFromEvents(let err),
.failedBuildingSubscriptionQuery(let err),
.failedDeletingThread(let err),
.failedDeletingMessage(let err),
.failedDeletingStore(let err),
Expand Down Expand Up @@ -670,6 +675,7 @@ public enum PrivMXEndpointError : Error{
.failedGettingEvent(let err),
.failedSubscribingForEvents(let err),
.failedUnsubscribingFromEvents(let err),
.failedBuildingSubscriptionQuery(let err),
.failedDeletingThread(let err),
.failedDeletingMessage(let err),
.failedDeletingStore(let err),
Expand Down Expand Up @@ -789,6 +795,7 @@ public enum PrivMXEndpointError : Error{
.failedGettingEvent(let err),
.failedSubscribingForEvents(let err),
.failedUnsubscribingFromEvents(let err),
.failedBuildingSubscriptionQuery(let err),
.failedDeletingThread(let err),
.failedDeletingMessage(let err),
.failedDeletingStore(let err),
Expand Down
74 changes: 52 additions & 22 deletions Sources/PrivMXEndpointSwift/Events/EventApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,38 +75,68 @@ public class EventApi{
}
}

/// Subscribe for the custom events on the given channel.

/// Subscribe for the events on the given subscription query.
///
/// - Parameter contextId: ID of the Context
/// - Parameter channelName: name of the Channel
/// - Parameter subscriptionQueries: list of queries
///
/// - Throws: `PrivMXEndpointError.failedSubscribingForEvents` if subscribing to custom events fails.
public func subscribeForCustomEvents(
contextId: std.string,
channelName:std.string
) throws -> Void {
let res = api.subscribeForCustomEvents(contextId,
channelName)
/// - Throws: When subscribing for events fails.
///
/// - Returns: list of subscriptionIds in maching order to subscriptionQueries.
public func subscribeFor(
subscriptionQueries: privmx.SubscriptionQueryVector
) throws -> privmx.SubscriptionIdVector {
let res = api.subscribeFor(subscriptionQueries)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedSubscribingForCustomEvents(res.error.value!)
throw PrivMXEndpointError.failedSubscribingForEvents(res.error.value!)
}
guard let result = res.result.value else {
var err = privmx.InternalError()
err.name = "Value error"
err.description = "Unexpectedly recived nil result"
throw PrivMXEndpointError.failedSubscribingForEvents(err)
}
return result
}

/// Unsubscribe from the custom events on the given channel.
/// Unsubscribe from events for the given subscriptionId.
///
/// - Parameter contextId: ID of the Context
/// - Parameter channelName: name of the Channel
/// - Parameter subscriptionIds: list of subscriptionId
///
/// - Throws: `PrivMXEndpointError.failedSubscribingForEvents` if subscribing to message events fails.
public func unsubscribeFromCustomEvents(
contextId: std.string,
channelName: std.string
/// - Throws: When unsubscribing fails.
public func unsubscribeFrom(
subscriptionId: privmx.SubscriptionIdVector
) throws -> Void {
let res = api.unsubscribeFromCustomEvents(contextId,
channelName)
let res = api.unsubscribeFrom(subscriptionId)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedUnsubscribingFromCustomEvents(res.error.value!)
throw PrivMXEndpointError.failedUnsubscribingFromEvents(res.error.value!)
}

}

/// Generate subscription Query for the Custom events.
///
/// - Parameter eventType: type of event which you listen for
/// - Parameter selectorType: scope on which you listen for events
/// - Parameter selectorId: ID of the selector
///
/// - Throws: When building the subscription Query fails.
///
/// - Returns: a properly formatted event subscription request.
public func buildSubscriptionQuery(
channelName: std.string,
selectorType: privmx.endpoint.event.EventSelectorType,
selectorId: std.string
) throws -> privmx.SubscriptionQuery {
let res = api.buildSubscriptionQuery(channelName, selectorType, selectorId)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedBuildingSubscriptionQuery(res.error.value!)
}
guard let result = res.result.value else {
var err = privmx.InternalError()
err.name = "Value error"
err.description = "Unexpectedly recived nil result"
throw PrivMXEndpointError.failedBuildingSubscriptionQuery(err)
}
return result
}
}
74 changes: 44 additions & 30 deletions Sources/PrivMXEndpointSwift/Inboxes/InboxApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -554,53 +554,67 @@ public class InboxApi{
return result
}

/// Subscribes to Inbox-related events.
/// Subscribe for the Inbox events on the given subscription query.
///
/// - Throws: `PrivMXEndpointError.failedSubscribingForEvents` if subscribing to Inbox events fails.
public func subscribeForInboxEvents(
) throws -> Void {
let res = api.subscribeForInboxEvents()
/// - Parameter subscriptionQueries: list of queries
///
/// - Throws: When subscribing for events fails.
///
/// - Returns: list of subscriptionIds in maching order to subscriptionQueries.
public func subscribeFor(
subscriptionQueries: privmx.SubscriptionQueryVector
) throws -> privmx.SubscriptionIdVector {
let res = api.subscribeFor(subscriptionQueries)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedSubscribingForEvents(res.error.value!)
}
}

/// Unsubscribes from Inbox-related events.
///
/// - Throws: `PrivMXEndpointError.failedUnsubscribingFromEvents` if unsubscribing from Inbox events fails.
public func unsubscribeFromInboxEvents(
) throws -> Void {
let res = api.unsubscribeFromInboxEvents()
guard res.error.value == nil else {
throw PrivMXEndpointError.failedUnsubscribingFromEvents(res.error.value!)
guard let result = res.result.value else {
var err = privmx.InternalError()
err.name = "Value error"
err.description = "Unexpectedly recived nil result"
throw PrivMXEndpointError.failedSubscribingForEvents(err)
}
return result
}

/// Subscribes to entry-related events within a specific Inbox.
/// Unsubscribe from events for the given subscriptionId.
///
/// - Parameter inboxId: The ID of the Inbox to subscribe to entry events for.
/// - Parameter subscriptionIds: list of subscriptionId
///
/// - Throws: `PrivMXEndpointError.failedSubscribingForEvents` if subscribing to entry events fails.
public func subscribeForEntryEvents(
inboxId: std.string
/// - Throws: When unsubscribing fails.
public func unsubscribeFrom(
subscriptionId: privmx.SubscriptionIdVector
) throws -> Void {
let res = api.subscribeForEntryEvents(inboxId)
let res = api.unsubscribeFrom(subscriptionId)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedSubscribingForEvents(res.error.value!)
throw PrivMXEndpointError.failedUnsubscribingFromEvents(res.error.value!)
}
}

/// Unsubscribes from entry-related events within a specific Inbox.
/// Generate subscription Query for the Inbox events.
///
/// - Parameter inboxId: The ID of the Inbox to unsubscribe from entry events for.
/// - Parameter eventType: type of event which you listen for
/// - Parameter selectorType: scope on which you listen for events
/// - Parameter selectorId: ID of the selector
///
/// - Throws: `PrivMXEndpointError.failedUnsubscribingFromEvents` if unsubscribing from entry events fails.
public func unsubscribeFromEntryEvents(
inboxId: std.string
) throws -> Void {
let res = api.unsubscribeFromEntryEvents(inboxId)
/// - Throws: When building the subscription Query fails.
///
/// - Returns: a properly formatted event subscription request.
public func buildSubscriptionQuery(
eventType: privmx.endpoint.inbox.EventType,
selectorType: privmx.endpoint.inbox.EventSelectorType,
selectorId: std.string
) throws -> privmx.SubscriptionQuery {
let res = api.buildSubscriptionQuery(eventType, selectorType, selectorId)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedUnsubscribingFromEvents(res.error.value!)
throw PrivMXEndpointError.failedBuildingSubscriptionQuery(res.error.value!)
}
guard let result = res.result.value else {
var err = privmx.InternalError()
err.name = "Value error"
err.description = "Unexpectedly recived nil result"
throw PrivMXEndpointError.failedBuildingSubscriptionQuery(err)
}
return result
}
}
73 changes: 44 additions & 29 deletions Sources/PrivMXEndpointSwift/Kvdbs/KvdbApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -373,52 +373,67 @@ public class KvdbApi: @unchecked Sendable{
return result
}

/// Subscribes for the KVDB module main events.
/// Subscribe for the Kvdb events on the given subscription query.
///
/// - Throws: `PrivMXEndpointError.failedSubscribingForEvents` if the operation fails.
public func subscribeForKvdbEvents(
) throws -> Void {
let res = api.subscribeForKvdbEvents()
/// - Parameter subscriptionQueries: list of queries
///
/// - Throws: When subscribing for events fails.
///
/// - Returns: list of subscriptionIds in maching order to subscriptionQueries.
public func subscribeFor(
subscriptionQueries: privmx.SubscriptionQueryVector
) throws -> privmx.SubscriptionIdVector {
let res = api.subscribeFor(subscriptionQueries)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedSubscribingForEvents(res.error.value!)
}
guard let result = res.result.value else {
var err = privmx.InternalError()
err.name = "Value error"
err.description = "Unexpectedly recived nil result"
throw PrivMXEndpointError.failedSubscribingForEvents(err)
}
return result
}

/// Unsubscribes from the KVDB module main events.
/// Unsubscribe from events for the given subscriptionId.
///
/// - Parameter subscriptionIds: list of subscriptionId
///
/// - Throws: `PrivMXEndpointError.failedUnsubscribingFromEvents` if the operation fails.
public func unsubscribeFromKvdbEvents(
/// - Throws: When unsubscribing fails.
public func unsubscribeFrom(
subscriptionId: privmx.SubscriptionIdVector
) throws -> Void {
let res = api.unsubscribeFromKvdbEvents()
let res = api.unsubscribeFrom(subscriptionId)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedUnsubscribingFromEvents(res.error.value!)
}
}

/// Subscribes for events in given KVDB.
/// Generate subscription Query for the Kvdb events.
///
/// - Parameter kvdbId: ID of the KVDB to subscribe
/// - Throws: `PrivMXEndpointError.failedSubscribingForEvents` if the operation fails.
public func subscribeForEntryEvents(
kvdbId: std.string
) throws -> Void {
let res = api.subscribeForEntryEvents(kvdbId)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedSubscribingForEvents(res.error.value!)
}
}

/// Unsubscribes from events in given KVDB.
/// - Parameter eventType: type of event which you listen for
/// - Parameter selectorType: scope on which you listen for events
/// - Parameter selectorId: ID of the selector
///
/// - Parameter kvdbId: ID of the KVDB to unsubscribe
/// - Throws: When building the subscription Query fails.
///
/// - Throws: `PrivMXEndpointError.failedUnsubscribingFromEvents` if the operation fails.
public func unsubscribeFromEntryEvents(
kvdbId: std.string
) throws -> Void {
let res = api.unsubscribeFromEntryEvents(kvdbId)
/// - Returns: a properly formatted event subscription request.
public func buildSubscriptionQuery(
eventType: privmx.endpoint.kvdb.EventType,
selectorType: privmx.endpoint.kvdb.EventSelectorType,
selectorId: std.string
) throws -> privmx.SubscriptionQuery {
let res = api.buildSubscriptionQuery(eventType, selectorType, selectorId)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedUnsubscribingFromEvents(res.error.value!)
throw PrivMXEndpointError.failedBuildingSubscriptionQuery(res.error.value!)
}
guard let result = res.result.value else {
var err = privmx.InternalError()
err.name = "Value error"
err.description = "Unexpectedly recived nil result"
throw PrivMXEndpointError.failedBuildingSubscriptionQuery(err)
}
return result
}
}
Loading