Skip to content

Commit

Permalink
Added docs for query call members (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmitrevski authored Sep 24, 2024
1 parent 578c416 commit 9ef4a25
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -149,6 +150,7 @@
40FFDCA12B640741004DA7A2 /* 14-livestream-player.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "14-livestream-player.swift"; sourceTree = "<group>"; };
40FFDCA32B640772004DA7A2 /* 15-long-press-to-focus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "15-long-press-to-focus.swift"; sourceTree = "<group>"; };
40FFDCA52B6408DE004DA7A2 /* 00-ringing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "00-ringing.swift"; sourceTree = "<group>"; };
84BA15AD2CA2EF420018DC51 /* 07-querying-call-members.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "07-querying-call-members.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
@@ -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"])]
)
}
}
28 changes: 26 additions & 2 deletions Sources/StreamVideo/Call.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")],
Expand All @@ -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
Expand Down
52 changes: 52 additions & 0 deletions docusaurus/docs/iOS/03-guides/07-query-call-members.mdx
Original file line number Diff line number Diff line change
@@ -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

<CallMemberSort />

## Filter options

<CallMemberFilters />

<FilterConditions />

0 comments on commit 9ef4a25

Please sign in to comment.