Skip to content

Feat: getContextUsers #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 12, 2025
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
23 changes: 22 additions & 1 deletion Sources/PrivMXEndpointSwift/Core/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,26 @@ public class Connection{
return result
}


/// Retrieves a list of Users from a particular Context.
///
/// - parameter contextId: Id of the Context.
///
/// - throws: When the operation fails.
///
/// - returns: a list of UserInfo objects.
public func getContextUsers(
contextId: std.string
) throws -> privmx.UserInfoVector {
let res = api.getContextUsers(contextId)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedGettingContextUsers(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.failedGettingContextUsers(err)
}
return result
}
}
6 changes: 6 additions & 0 deletions Sources/PrivMXEndpointSwift/Errors/PrivMXEndpointError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public enum PrivMXEndpointError : Error{
case failedDisconnecting(privmx.InternalError)
/// Failed to list Contexts
case failedListingContexts(privmx.InternalError)
/// Falied to get a list of Users from a Context
case failedGettingContextUsers(privmx.InternalError)

/// Failed to instantiate `ThreadApi`
case failedInstantiatingThreadApi(privmx.InternalError)
Expand Down Expand Up @@ -179,6 +181,7 @@ public enum PrivMXEndpointError : Error{
.failedConnecting(let err),
.failedDisconnecting(let err),
.failedListingContexts(let err),
.failedGettingContextUsers(let err),
.failedCreatingThread(let err),
.failedGettingThread(let err),
.failedListingThreads(let err),
Expand Down Expand Up @@ -251,6 +254,7 @@ public enum PrivMXEndpointError : Error{
.failedConnecting(let err),
.failedDisconnecting(let err),
.failedListingContexts(let err),
.failedGettingContextUsers(let err),
.failedCreatingThread(let err),
.failedGettingThread(let err),
.failedListingThreads(let err),
Expand Down Expand Up @@ -323,6 +327,7 @@ public enum PrivMXEndpointError : Error{
.failedConnecting(let err),
.failedDisconnecting(let err),
.failedListingContexts(let err),
.failedGettingContextUsers(let err),
.failedCreatingThread(let err),
.failedGettingThread(let err),
.failedListingThreads(let err),
Expand Down Expand Up @@ -394,6 +399,7 @@ public enum PrivMXEndpointError : Error{
.failedConnecting(let err),
.failedDisconnecting(let err),
.failedListingContexts(let err),
.failedGettingContextUsers(let err),
.failedCreatingThread(let err),
.failedGettingThread(let err),
.failedListingThreads(let err),
Expand Down
25 changes: 25 additions & 0 deletions Sources/PrivMXEndpointSwiftNative/NativeConnectionWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,31 @@ ResultWithError<ContextList> NativeConnectionWrapper::listContexts(const core::P
return res;
}

ResultWithError<UserInfoVector> NativeConnectionWrapper::getContextUsers(const std::string &contextId){
ResultWithError<UserInfoVector> res;
try{
res.result = getApi()->getContextUsers(contextId);
}catch(core::Exception& err){
res.error = {
.name = err.getName(),
.code = err.getCode(),
.description = err.getDescription(),
.message = err.what()
};
}catch (std::exception & err) {
res.error ={
.name = "std::Exception",
.message = err.what()
};
}catch (...) {
res.error ={
.name = "Unknown Exception",
.message = "Failed to work"
};
}
return res;
}

ResultWithError<int64_t> NativeConnectionWrapper::getConnectionId(){
ResultWithError<int64_t> res;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class NativeConnectionWrapper {
* @return struct containing a list of Contexts wrapped in a `ResultWithError` object for error handling.
*/
ResultWithError<ContextList> listContexts(const endpoint::core::PagingQuery& query);

ResultWithError<UserInfoVector> getContextUsers(const std::string& contextId);
private:

std::shared_ptr<endpoint::core::Connection> getApi();
Expand Down
1 change: 1 addition & 0 deletions Sources/PrivMXEndpointSwiftNative/include/PrivMXUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ using InboxFileHandleVector = std::vector<InboxFileHandle>;
using StringVector = std::vector<std::string>;
using OptionalString = std::optional<std::string>;
using UserWithPubKeyVector = std::vector<endpoint::core::UserWithPubKey>;
using UserInfoVector = std::vector<endpoint::core::UserInfo>;

using OptionalInboxFilesConfig = std::optional<endpoint::inbox::FilesConfig>;

Expand Down