From eb70660575761a3171ed511e7df329b5f6f1694c Mon Sep 17 00:00:00 2001 From: Stream Bot Date: Tue, 24 Sep 2024 15:02:31 +0200 Subject: [PATCH] Added docs for query call members --- .../project.pbxproj | 4 ++ .../03-guides/07-querying-call-members.swift | 26 ++++++++++ Sources/StreamVideo/Call.swift | 28 +++++++++- .../iOS/03-guides/07-query-call-members.mdx | 52 +++++++++++++++++++ 4 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 DocumentationTests/DocumentationTests/DocumentationTests/03-guides/07-querying-call-members.swift create mode 100644 docusaurus/docs/iOS/03-guides/07-query-call-members.mdx diff --git a/DocumentationTests/DocumentationTests/DocumentationTests.xcodeproj/project.pbxproj b/DocumentationTests/DocumentationTests/DocumentationTests.xcodeproj/project.pbxproj index 60a1edc33..58204ae2b 100644 --- a/DocumentationTests/DocumentationTests/DocumentationTests.xcodeproj/project.pbxproj +++ b/DocumentationTests/DocumentationTests/DocumentationTests.xcodeproj/project.pbxproj @@ -78,6 +78,7 @@ 40FFDCA22B640741004DA7A2 /* 14-livestream-player.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40FFDCA12B640741004DA7A2 /* 14-livestream-player.swift */; }; 40FFDCA42B640772004DA7A2 /* 15-long-press-to-focus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40FFDCA32B640772004DA7A2 /* 15-long-press-to-focus.swift */; }; 40FFDCA62B6408DE004DA7A2 /* 00-ringing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40FFDCA52B6408DE004DA7A2 /* 00-ringing.swift */; }; + 84BA15AE2CA2EF420018DC51 /* 07-querying-call-members.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84BA15AD2CA2EF420018DC51 /* 07-querying-call-members.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -149,6 +150,7 @@ 40FFDCA12B640741004DA7A2 /* 14-livestream-player.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "14-livestream-player.swift"; sourceTree = ""; }; 40FFDCA32B640772004DA7A2 /* 15-long-press-to-focus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "15-long-press-to-focus.swift"; sourceTree = ""; }; 40FFDCA52B6408DE004DA7A2 /* 00-ringing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "00-ringing.swift"; sourceTree = ""; }; + 84BA15AD2CA2EF420018DC51 /* 07-querying-call-members.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "07-querying-call-members.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -217,6 +219,7 @@ 400D91D02B63DEA200EBA47D /* 04-camera-and-microphone.swift */, 400D91D22B63DFA500EBA47D /* 06-querying-calls.swift */, 400D91D42B63E27300EBA47D /* 07-dependency-injection.swift */, + 84BA15AD2CA2EF420018DC51 /* 07-querying-call-members.swift */, 40FFDC362B63E400004DA7A2 /* 08-permissions-and-moderation.swift */, 40FFDC382B63E459004DA7A2 /* 09-reactions-and-custom-events.swift */, 40FFDC3A2B63E493004DA7A2 /* 10-view-slots.swift */, @@ -455,6 +458,7 @@ 40FFDC922B63FF70004DA7A2 /* 06-lobby-preview.swift in Sources */, 4068C1252B67C056006B0BEE /* 03-callkit-integration.swift in Sources */, 40FFDC762B63F7D6004DA7A2 /* ChatGloballyUsedVariables.swift in Sources */, + 84BA15AE2CA2EF420018DC51 /* 07-querying-call-members.swift in Sources */, 40FFDC672B63F430004DA7A2 /* 04-connection-quality-indicator.swift in Sources */, 40B468982B67B6DF009B5B3E /* 01-deeplinking.swift in Sources */, 40FFDC3B2B63E493004DA7A2 /* 10-view-slots.swift in Sources */, diff --git a/DocumentationTests/DocumentationTests/DocumentationTests/03-guides/07-querying-call-members.swift b/DocumentationTests/DocumentationTests/DocumentationTests/03-guides/07-querying-call-members.swift new file mode 100644 index 000000000..a1c9ebd30 --- /dev/null +++ b/DocumentationTests/DocumentationTests/DocumentationTests/03-guides/07-querying-call-members.swift @@ -0,0 +1,26 @@ +import StreamVideo +import StreamVideoSwiftUI +import SwiftUI +import Combine + +@MainActor +fileprivate func content() { + asyncContainer { + // sorting and pagination + let sort = SortParamRequest(direction: 1, field: "user_id") + let result1 = try await call.queryMembers( + sort: [sort], + limit: 10 + ) + + // loading the next page + if let next = result1.next { + let result2 = try await call.queryMembers(sort: [sort], limit: 10, next: next) + } + + // filtering + let result2 = try await call.queryMembers( + filters: ["role": .dictionary(["eq": "admin"])] + ) + } +} diff --git a/Sources/StreamVideo/Call.swift b/Sources/StreamVideo/Call.swift index 063cd31f8..e23e5e94a 100644 --- a/Sources/StreamVideo/Call.swift +++ b/Sources/StreamVideo/Call.swift @@ -826,6 +826,15 @@ public class Call: @unchecked Sendable, WSEventsSubscriber { return response } + /// Queries call members with the specified filters, sort options, and limit. + /// + /// - Parameters: + /// - filters: An optional dictionary of filters. + /// - sort: An optional array of `SortParamRequest` that determines the sorting order of the results. Defaults to sorting by `created_at` in descending order. + /// - limit: The maximum number of members to return. Defaults to 25. + /// + /// - Returns: A `QueryMembersResponse` containing the results of the query. + /// - Throws: An error if the query fails. public func queryMembers( filters: [String: RawJSON]? = nil, sort: [SortParamRequest] = [SortParamRequest.descending("created_at")], @@ -834,8 +843,23 @@ public class Call: @unchecked Sendable, WSEventsSubscriber { try await queryMembers(filters: filters, limit: limit, sort: sort) } - public func queryMembers(next: String) async throws -> QueryMembersResponse { - try await queryMembers(filters: nil, limit: nil, next: next, sort: nil) + /// Asynchronously queries members with pagination support, using filters, sort options, and limit. + /// + /// - Parameters: + /// - filters: An optional dictionary of filters. + /// - sort: An optional array of `SortParamRequest` that determines the sorting order of the results. + /// - limit: The maximum number of members to return. Defaults to 25. + /// - next: A `String` representing the pagination token to fetch the next set of results. + /// + /// - Returns: A `QueryMembersResponse` containing the results of the query. + /// - Throws: An error if the query fails. + public func queryMembers( + filters: [String: RawJSON]? = nil, + sort: [SortParamRequest]? = nil, + limit: Int = 25, + next: String + ) async throws -> QueryMembersResponse { + try await queryMembers(filters: filters, limit: limit, next: next, sort: sort) } // MARK: - Pinning diff --git a/docusaurus/docs/iOS/03-guides/07-query-call-members.mdx b/docusaurus/docs/iOS/03-guides/07-query-call-members.mdx new file mode 100644 index 000000000..c54c8d6c0 --- /dev/null +++ b/docusaurus/docs/iOS/03-guides/07-query-call-members.mdx @@ -0,0 +1,52 @@ +--- +id: querying-call-members +title: Querying Call Members +description: How to query call members +--- + +import FilterConditions from '../../../shared/_filter-operators.mdx'; +import CallMemberFilters from '../../../shared/video/_call-member-filters.mdx'; +import CallMemberSort from '../../../shared/video/_call-member-sort-fields.mdx'; + +When you create or join a call you get a list of call members, however this can return at most 25 members: + +```swift +// The maximum limit is 25 +// The default limit is 25 +try await call.get(membersLimit: 25) +``` + +To get the complete list of call members the Stream API allows you to query, filter and sort members of a call using a paginated list. + +## Examples + +Below are a few examples of how to use this API: + +```swift +// sorting and pagination +let sort = SortParamRequest(direction: 1, field: "user_id") +let result1 = try await call.queryMembers( + sort: [sort], + limit: 10 +) + +// loading the next page +if let next = result1.next { + let result2 = try await call.queryMembers(sort: [sort], limit: 10, next: next) +} + +// filtering +let result2 = try await call.queryMembers( + filters: ["role": .dictionary(["eq": "admin"])] +) +``` + +## Sort options + + + +## Filter options + + + +