5#include "Channel/ChannelProperties.h"
6#include "Channel/ChannelSortOption.h"
7#include "Channel/ChatChannel.h"
8#include "Channel/Filter.h"
9#include "ChannelFlags.h"
10#include "ChatSocketEvents.h"
11#include "Components/ActorComponent.h"
12#include "CoreMinimal.h"
13#include "Engine/LatentActionManager.h"
14#include "Event/Notification/NotificationMutesUpdatedEvent.h"
15#include "IChatSocket.h"
16#include "Moderation/BanPaginationOptions.h"
17#include "PaginationOptions.h"
18#include "User/OwnUser.h"
21#include "StreamChatClientComponent.generated.h"
40UCLASS(ClassGroup = (Stream), meta = (BlueprintSpawnableComponent))
80 void ConnectGuestUser(
const FUser& User, TFunction<
void(
const FOwnUser&)> Callback = {});
85 UFUNCTION(BlueprintCallable, Category =
"Stream Chat|Client")
86 void DisconnectUser();
91 UFUNCTION(BlueprintCallable, Category = "Stream Chat|Client")
92 void UpsertUsers(const TArray<
FUser>& Users);
95 UFUNCTION(BlueprintCallable, Category = "Stream Chat|Client")
98 UFUNCTION(BlueprintCallable, Category = "Stream Chat|Client")
113 TOptional<
FFilter> Filter = {},
114 const TArray<FChannelSortOption>& SortOptions = {},
117 TFunction<void(
const TArray<UChatChannel*>&)> Callback = {});
153 void QueryAdditionalChannels(int32 Limit = 10, TFunction<
void()> Callback = {});
166 const TArray<FUserSortOption>& Sort = {},
167 bool bPresence =
true,
168 const TOptional<FPaginationOptions> PaginationOptions = {},
169 TFunction<void(
const TArray<FUserRef>&)> Callback = {})
const;
184 const FFilter& ChannelFilter = {},
185 const TOptional<FString>&
Query = {},
186 const TOptional<FFilter>& MessageFilter = {},
187 const TArray<FMessageSortOption>& Sort = {},
188 TOptional<uint32> MessageLimit = {},
189 TFunction<void(
const TArray<FMessage>&)> Callback = {})
const;
194 UFUNCTION(BlueprintCallable, BlueprintPure =
false, Category =
"Stream Chat|Client")
195 void MarkAllRead() const;
197 UFUNCTION(BlueprintPure, Category = "Stream Chat|Client")
200 UFUNCTION(BlueprintPure, Category = "Stream Chat|Client")
201 static FString DevToken(const FString&
UserId);
208 UFUNCTION(BlueprintCallable, Category = "Stream Chat|Client")
209 void AddDevice(const FString& DeviceId, EPushProvider PushProvider) const;
215 UFUNCTION(BlueprintCallable, Category = "Stream Chat|Client")
216 void RemoveDevice(const FString& DeviceId) const;
222 void ListDevices(TFunction<
void(TArray<
FDevice>)> Callback) const;
224 UPROPERTY(EditAnywhere, Config, Category = "Stream Chat", meta = (DisplayName = "API Key"))
227 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FChannelsUpdatedDelegate, const TArray<
UChatChannel*>&, Channels);
230 UPROPERTY(BlueprintAssignable, Category = "Stream Chat|Channel")
231 FChannelsUpdatedDelegate ChannelsUpdated;
235 virtual
void BeginPlay() override;
237 void ConnectUserInternal(const
FUser& User, TFunction<
void(const
FOwnUser&)> Callback);
245 void AddChannels(const TArray<
UChatChannel*>& InChannels);
247 TSharedPtr<FTokenManager> TokenManager;
253#pragma region Blueprint
265 UFUNCTION(BlueprintCallable, Category =
"Stream Chat|Client", meta = (Latent, WorldContext = WorldContextObject, LatentInfo = LatentInfo))
266 void ConnectUser(
const FUser& User,
const FString& Token,
const UObject* WorldContextObject, FLatentActionInfo LatentInfo,
FOwnUser& OutUser);
272 UFUNCTION(BlueprintCallable, Category =
"Stream Chat|Client", meta = (Latent, WorldContext = WorldContextObject, LatentInfo = LatentInfo))
273 void ConnectAnonymousUser(
const UObject* WorldContextObject, FLatentActionInfo LatentInfo,
FOwnUser& OutUser);
280 UFUNCTION(BlueprintCallable, Category =
"Stream Chat|Client", meta = (Latent, WorldContext = WorldContextObject, LatentInfo = LatentInfo))
281 void ConnectGuestUser(
const FUser& User,
const UObject* WorldContextObject, FLatentActionInfo LatentInfo,
FOwnUser& OutUser);
293 UFUNCTION(BlueprintCallable, Category =
"Stream Chat|Client", meta = (Latent, WorldContext = WorldContextObject, LatentInfo = LatentInfo))
297 const UObject* WorldContextObject,
298 FLatentActionInfo LatentInfo,
300 UPARAM(meta = (Bitmask, BitmaskEnum =
EChannelFlags)) const int32 Flags = 3);
309 UFUNCTION(BlueprintCallable, Category = "Stream Chat|Client", meta = (Latent, WorldContext = WorldContextObject, LatentInfo = LatentInfo, AdvancedDisplay =
Id))
310 void WatchChannel(const
FChannelProperties& ChannelProperties, const UObject* WorldContextObject, FLatentActionInfo LatentInfo,
UChatChannel*& OutChannel);
313#pragma endregion Blueprint
321 template <
class TEvent>
322 using TEventMulticastDelegate = TMulticastDelegate<void(
const TEvent& Event)>;
323 template <
class TEvent>
324 using TEventDelegate =
typename TEventMulticastDelegate<TEvent>::FDelegate;
325#if ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION <= 27
326 template <
class TEvent,
class UserClass>
327 using TEventDelegateUObjectMethodPtr =
typename TEventDelegate<TEvent>::template TUObjectMethodDelegate<UserClass>::FMethodPtr;
328 template <
class TEvent,
class UserClass>
329 using TEventDelegateSpMethodPtr =
typename TEventDelegate<TEvent>::template TSPMethodDelegate<UserClass>::FMethodPtr;
331 template <
class TEvent,
class UserClass>
332 using TEventDelegateUObjectMethodPtr =
typename TEventDelegate<TEvent>::template TMethodPtr<UserClass>;
333 template <
class TEvent,
class UserClass>
334 using TEventDelegateSpMethodPtr =
typename TEventDelegate<TEvent>::template TMethodPtr<UserClass>;
338 template <
class TEvent>
339 FDelegateHandle On(TEventDelegate<TEvent> Callback);
348 template <
class TEvent,
class UserClass>
349 typename TEnableIf<TIsDerivedFrom<UserClass, UObject>::IsDerived, FDelegateHandle>
::Type On(
351 TEventDelegateUObjectMethodPtr<TEvent, UserClass> Method);
360 template <
class TEvent,
class UserClass>
361 typename TEnableIf<!TIsDerivedFrom<UserClass, UObject>::IsDerived, FDelegateHandle>
::Type On(
363 TEventDelegateSpMethodPtr<TEvent, UserClass> Method);
373 template <
class TEvent,
typename FunctorType,
typename... VarTypes>
374 typename TEnableIf<TIsInvocable<FunctorType,
const TEvent&, VarTypes...>::Value, FDelegateHandle>
::Type On(FunctorType&& Functor, VarTypes... Vars);
376 template <
class TEvent>
377 bool Unsubscribe(FDelegateHandle)
const;
380 TSharedPtr<IChatSocket> Socket;
383#pragma endregion Events
385#pragma region Moderation
400 UFUNCTION(BlueprintCallable, BlueprintPure =
false, Category =
"Stream Chat|Client|Moderation", DisplayName =
"Ban User")
401 void BanUserBP(const
FUserRef& User, FTimespan Timeout, const FString& Reason,
bool bIpBan) const;
402 void BanUser(const
FUserRef& User, const TOptional<FTimespan>& Timeout = {},
const TOptional<FString>& Reason = {},
bool bIpBan =
false)
const;
408 UFUNCTION(BlueprintCallable, Category =
"Stream Chat|Client|Moderation")
409 void UnbanUser(const
FUserRef& User) const;
418 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "Stream Chat|Client|Moderation", DisplayName = "Shadow Ban User")
419 void ShadowBanUserBP(const
FUserRef& User, FTimespan Timeout) const;
420 void ShadowBanUser(const
FUserRef& User, const TOptional<FTimespan>& Timeout = {})
const;
426 UFUNCTION(BlueprintCallable, Category =
"Stream Chat|Client|Moderation")
427 void ShadowUnbanUser(const
FUserRef& User) const;
438 void QueryBannedUsers(
441 const TOptional<FBanPaginationOptions> PaginationOptions = {},
442 const TFunction<void(
const TArray<FBan>&)> Callback = {});
449 UFUNCTION(BlueprintCallable, BlueprintPure =
false, Category =
"Stream Chat|Client")
450 void FlagMessage(const
FMessage& Message) const;
457 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "Stream Chat|Client")
458 void FlagUser(const
FUserRef& User) const;
466 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "Stream Chat|Client", DisplayName = "Mute User")
467 void MuteUserBP(const
FUserRef& User, FTimespan Timeout) const;
468 void MuteUser(const
FUserRef& User, const TOptional<FTimespan>& Timeout = {})
const;
475 UFUNCTION(BlueprintCallable, Category =
"Stream Chat|Client")
476 void UnmuteUser(const
FUserRef& User) const;
479#pragma endregion Moderation
484template <
class TEvent>
487 return Socket->Events().SubscribeLambda<TEvent>(
488 [
this, Callback](
const TEvent& Event)
491 Callback.ExecuteIfBound(Event);
495template <
class TEvent,
class UserClass>
498 TEventDelegateUObjectMethodPtr<TEvent, UserClass> Method)
500 const TEventDelegate<TEvent> Delegate = TEventDelegate<TEvent>::CreateUObject(Obj, Method);
501 return On<TEvent>(Delegate);
504template <
class TEvent,
class UserClass>
507 TEventDelegateSpMethodPtr<TEvent, UserClass> Method)
509 const TEventDelegate<TEvent> Delegate = TEventDelegate<TEvent>::CreateSP(Obj, Method);
510 return On<TEvent>(Delegate);
513template <
class TEvent,
typename FunctorType,
typename... VarTypes>
515 FunctorType&& Functor,
518 const TEventDelegate<TEvent> Delegate = TEventDelegate<TEvent>::CreateLambda(Forward<FunctorType>(Functor), Vars...);
519 return On<TEvent>(Delegate);
522template <
class TEvent>
523bool UStreamChatClientComponent::Unsubscribe(
const FDelegateHandle Handle)
const
525 return Socket->Events().Unsubscribe<TEvent>(Handle);
527#pragma endregion Events
All Stream Chat REST API requests can be made via this object.
Definition: ChatApi.h:59
The client-side representation of a Stream Chat channel.
Definition: ChatChannel.h:74
A component which allows for connecting to the Stream Chat API. Should be added to a client-side acto...
Definition: StreamChatClientComponent.h:42
TEnableIf<!TIsDerivedFrom< UserClass, UObject >::IsDerived, FDelegateHandle >::Type On(UserClass *Obj, TEventDelegateSpMethodPtr< TEvent, UserClass > Method)
void ConnectUser(const FUser &User, const FString &Token, TFunction< void(const FOwnUser &)> Callback={})
Create a connection to the API for the given user and credentials.
void WatchChannel(const FChannelProperties &ChannelProperties, TFunction< void(UChatChannel *)> Callback)
Create a channel if it does not exist yet (if this user has the right permissions),...
void ConnectUser(const FUser &User, TUniquePtr< ITokenProvider > TokenProvider, TFunction< void(const FOwnUser &)> Callback={})
Create a connection to the API for the given user and using a custom token provider.
FDelegateHandle On(TEventDelegate< TEvent > Callback)
Subscribe to a client event using your own delegate object.
Definition: StreamChatClientComponent.h:485
void ConnectAnonymousUser(TFunction< void(const FOwnUser &)> Callback={})
Create a connection to the API anonymously.
EChannelFlags
Additional channel actions to perform when requesting channel data from API.
Definition: ChannelFlags.h:15
@ State
Return channel state in response.
@ Watch
Start watching the channel (receive events regarding this channel via WebSocket)
@ UserId
The user ID of the user that sent the message.
@ Type
Type of the message.
@ Query
Matches values by performing text search with the specified value.
A banned user.
Definition: Ban.h:17
The desired sort options for ban queries.
Definition: ChannelSortOption.h:188
Encapsulates the static properties of a channel.
Definition: ChannelProperties.h:21
The desired sort options for Channel API queries.
Definition: ChannelSortOption.h:44
#/components/schemas/ChannelStateResponseFields
Definition: ChannelStateResponseFieldsDto.h:19
Sent when the connection is recovered.
Definition: ConnectionRecoveredEvent.h:17
A push notification device.
Definition: Device.h:16
A filter used for querying channels.
Definition: Filter.h:75
Represents a Stream Chat message.
Definition: Message.h:66
A new message was created.
Definition: MessageNewEvent.h:17
Notification when a new message was created.
Definition: NotificationMutesUpdatedEvent.h:18
The currently connected Stream Chat user.
Definition: OwnUser.h:18
A Stream Chat user.
Definition: User.h:20
#/components/schemas/UserPresenceChangedEvent
Definition: UserPresenceChangedEvent.h:18
A reference to a unique User.
Definition: UserRef.h:23