Twitch SDK (Internal)
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
ttv::social::SocialAPI Class Reference

#include <socialapi.h>

Inheritance diagram for ttv::social::SocialAPI:
ttv::ModuleBase ttv::IModule

Classes

class  CoreApiClient
 

Public Types

using PostPresenceCallback = std::function< void(TTV_ErrorCode ec)>
 
using FetchPresenceSettingsCallback = std::function< void(TTV_ErrorCode ec, const PresenceSettings &settings)>
 
using SetPresenceSettingsCallback = std::function< void(TTV_ErrorCode ec)>
 
using FetchFriendListCallback = std::function< void(TTV_ErrorCode ec, const std::vector< Friend > &friends)>
 
using UpdateFriendshipCallback = std::function< void(TTV_ErrorCode ec, UpdateFriendResult result, FriendStatus status)>
 
using FetchFriendRequestsCallback = std::function< void(TTV_ErrorCode ec, const std::vector< FriendRequest > &requests)>
 
using FetchUnreadFriendRequestCountCallback = std::function< void(TTV_ErrorCode ec, uint32_t requestCount)>
 
using MarkAllFriendRequestsReadCallback = std::function< void(TTV_ErrorCode ec)>
 
using FetchFriendStatusCallback = std::function< void(TTV_ErrorCode ec, FriendStatus status)>
 
using FetchRecommendedFriendsCallback = std::function< void(TTV_ErrorCode ec, const std::vector< UserInfo > &recommendedFriends)>
 
using DismissRecommendedFriendCallback = std::function< void(TTV_ErrorCode ec)>
 
enum  State { State::Uninitialized, State::Initializing, State::Initialized, State::ShuttingDown }
 
using InitializeCallback = std::function< void(TTV_ErrorCode ec)>
 
using ShutdownCallback = std::function< void(TTV_ErrorCode ec)>
 

Public Member Functions

 SocialAPI ()
 
virtual ~SocialAPI ()
 
virtual std::string GetModuleName () const override
 
virtual TTV_ErrorCode Initialize (const InitializeCallback &callback) override
 
virtual TTV_ErrorCode Shutdown (const ShutdownCallback &callback) override
 
virtual TTV_ErrorCode Update () override
 
TTV_ErrorCode SetCoreApi (const std::shared_ptr< CoreAPI > &coreApi)
 
TTV_ErrorCode SetListener (const std::shared_ptr< ISocialAPIListener > &listener)
 
TTV_ErrorCode SetEnabledFeatures (const FeatureFlags &features)
 
TTV_ErrorCode PostPresence (UserId userId, const PostPresenceCallback &callback)
 
TTV_ErrorCode SetPresenceSessionAvailability (UserId userId, PresenceSessionAvailability availability)
 
TTV_ErrorCode AddWatchingActivity (UserId userId, ChannelId channelId, PresenceActivityToken &activityToken)
 
TTV_ErrorCode AddPlayingActivity (UserId userId, GameId gameId, const std::string &gameDisplayContext, PresenceActivityToken &activityToken)
 
TTV_ErrorCode RemoveActivity (UserId userId, PresenceActivityToken activityToken)
 
TTV_ErrorCode FetchPresenceSettings (UserId userId, const FetchPresenceSettingsCallback &callback)
 
TTV_ErrorCode SetPresenceSettings (UserId userId, const PresenceSettings &settings, const SetPresenceSettingsCallback &callback)
 
TTV_ErrorCode SetAutomaticPresencePostingEnabled (UserId userId, bool enabled)
 
TTV_ErrorCode GetAutomaticPresencePostingEnabled (UserId userId, bool &enabled)
 
TTV_ErrorCode FetchFriendList (UserId userId, const FetchFriendListCallback &callback)
 
TTV_ErrorCode UpdateFriendship (UserId userId, UserId otherUserId, FriendAction action, const UpdateFriendshipCallback &callback)
 
TTV_ErrorCode FetchFriendRequests (UserId userId, const FetchFriendRequestsCallback &callback)
 
TTV_ErrorCode FetchUnreadFriendRequestCount (UserId userId, const FetchUnreadFriendRequestCountCallback &callback)
 
TTV_ErrorCode MarkAllFriendRequestsRead (UserId userId, const MarkAllFriendRequestsReadCallback &callback)
 
TTV_ErrorCode FetchFriendStatus (UserId userId, UserId otherUserId, const FetchFriendStatusCallback &callback)
 
TTV_ErrorCode FetchRecommendedFriends (UserId userId, const FetchRecommendedFriendsCallback &callback)
 
TTV_ErrorCode DismissRecommendedFriend (UserId userId, UserId dismissUserId, const DismissRecommendedFriendCallback &callback)
 
virtual State GetState () const override
 

Protected Member Functions

void NotifyStateChange ()
 
void RegisterInitializeCallback (const InitializeCallback &callback)
 
void RegisterShutdownCallback (const ShutdownCallback &callback)
 
template<typename T >
void Invoke (std::function< void(std::shared_ptr< T >)> callback)
 
std::shared_ptr< ComponentContainerGetComponentContainer ()
 

Protected Attributes

EventSource< IModuleListenermListeners
 
State mState
 
State mLastReportedState
 

Private Member Functions

void CoreUserLoggedIn (std::shared_ptr< User > user)
 
void CoreUserLoggedOut (std::shared_ptr< User > user)
 
TTV_ErrorCode GetPresenceForUser (UserId userId, std::shared_ptr< Presence > &presence)
 
TTV_ErrorCode GetFriendListForUser (UserId userId, std::shared_ptr< FriendList > &friendList)
 
void CreateFriendListListener ()
 
void CreatePresenceListener ()
 
virtual bool CheckShutdown () override
 
virtual void CompleteShutdown () override
 

Private Attributes

std::shared_ptr< CoreAPImCoreApi
 
std::shared_ptr< ICoreApiClientmCoreApiClient
 
std::shared_ptr< SocialAPIInternalData > mInternalData
 
std::shared_ptr< UserRepositorymUserRepository
 
std::shared_ptr< TaskRunnermTaskRunner
 
FeatureFlags mEnabledFeatures
 

Detailed Description

Provides the main social functionality.

The following properties must be set before calling Initialize().

Member Typedef Documentation

◆ DismissRecommendedFriendCallback

◆ FetchFriendListCallback

using ttv::social::SocialAPI::FetchFriendListCallback = std::function<void(TTV_ErrorCode ec, const std::vector<Friend>& friends)>

◆ FetchFriendRequestsCallback

using ttv::social::SocialAPI::FetchFriendRequestsCallback = std::function<void(TTV_ErrorCode ec, const std::vector<FriendRequest>& requests)>

◆ FetchFriendStatusCallback

◆ FetchPresenceSettingsCallback

◆ FetchRecommendedFriendsCallback

using ttv::social::SocialAPI::FetchRecommendedFriendsCallback = std::function<void(TTV_ErrorCode ec, const std::vector<UserInfo>& recommendedFriends)>

◆ FetchUnreadFriendRequestCountCallback

using ttv::social::SocialAPI::FetchUnreadFriendRequestCountCallback = std::function<void(TTV_ErrorCode ec, uint32_t requestCount)>

◆ InitializeCallback

using ttv::IModule::InitializeCallback = std::function<void(TTV_ErrorCode ec)>
inherited

◆ MarkAllFriendRequestsReadCallback

◆ PostPresenceCallback

◆ SetPresenceSettingsCallback

◆ ShutdownCallback

using ttv::IModule::ShutdownCallback = std::function<void(TTV_ErrorCode ec)>
inherited

◆ UpdateFriendshipCallback

Member Enumeration Documentation

◆ State

enum ttv::IModule::State
stronginherited
Enumerator
Uninitialized 
Initializing 
Initialized 
ShuttingDown 

Constructor & Destructor Documentation

◆ SocialAPI()

ttv::social::SocialAPI::SocialAPI ( )

◆ ~SocialAPI()

virtual ttv::social::SocialAPI::~SocialAPI ( )
virtual

Member Function Documentation

◆ AddPlayingActivity()

TTV_ErrorCode ttv::social::SocialAPI::AddPlayingActivity ( UserId  userId,
GameId  gameId,
const std::string &  gameDisplayContext,
PresenceActivityToken activityToken 
)

Adds a playing activity to the user's list of activities. gameId is the id of the game being played. gameDisplayContext is an optional string that specifies additional context about the game. Returns a unique token that corresponds to that activity.

◆ AddWatchingActivity()

TTV_ErrorCode ttv::social::SocialAPI::AddWatchingActivity ( UserId  userId,
ChannelId  channelId,
PresenceActivityToken activityToken 
)

Adds a watching activity to the user's list of activities. channelId is the id of the channel being watched. Returns a unique token that corresponds to that activity.

◆ CheckShutdown()

virtual bool ttv::social::SocialAPI::CheckShutdown ( )
overrideprivatevirtual

Reimplemented from ttv::ModuleBase.

◆ CompleteShutdown()

virtual void ttv::social::SocialAPI::CompleteShutdown ( )
overrideprivatevirtual

Reimplemented from ttv::ModuleBase.

◆ CoreUserLoggedIn()

void ttv::social::SocialAPI::CoreUserLoggedIn ( std::shared_ptr< User user)
private

◆ CoreUserLoggedOut()

void ttv::social::SocialAPI::CoreUserLoggedOut ( std::shared_ptr< User user)
private

◆ CreateFriendListListener()

void ttv::social::SocialAPI::CreateFriendListListener ( )
private

◆ CreatePresenceListener()

void ttv::social::SocialAPI::CreatePresenceListener ( )
private

◆ DismissRecommendedFriend()

TTV_ErrorCode ttv::social::SocialAPI::DismissRecommendedFriend ( UserId  userId,
UserId  dismissUserId,
const DismissRecommendedFriendCallback callback 
)

Initiates an async dimissal of the named user from the recommended friend list. The result will be notified via ISocialAPIListener::SocialDismissRecommendedFriendComplete.

◆ FetchFriendList()

TTV_ErrorCode ttv::social::SocialAPI::FetchFriendList ( UserId  userId,
const FetchFriendListCallback callback 
)

Initiates an async retrieval of the friend list. The result will be notified via ISocialAPIListener::SocialFetchFriendListComplete.

◆ FetchFriendRequests()

TTV_ErrorCode ttv::social::SocialAPI::FetchFriendRequests ( UserId  userId,
const FetchFriendRequestsCallback callback 
)

Initiates an async retrieval of outstanding friend requests. The result will be notified via ISocialAPIListener::SocialFetchFriendRequestsComplete.

◆ FetchFriendStatus()

TTV_ErrorCode ttv::social::SocialAPI::FetchFriendStatus ( UserId  userId,
UserId  otherUserId,
const FetchFriendStatusCallback callback 
)

Initiates an async retrieval of the relationship between two users. The result will be notified via the passed-in callback. This does not update any internal cache.

◆ FetchPresenceSettings()

TTV_ErrorCode ttv::social::SocialAPI::FetchPresenceSettings ( UserId  userId,
const FetchPresenceSettingsCallback callback 
)

Initiates an async retrieval of presence settings from the backend. The result will be returned via the passed-in callback.

◆ FetchRecommendedFriends()

TTV_ErrorCode ttv::social::SocialAPI::FetchRecommendedFriends ( UserId  userId,
const FetchRecommendedFriendsCallback callback 
)

Initiates an async retrieval of recommended friends. The result will be notified via ISocialAPIListener::SocialFetchRecommendedFriendsComplete.

◆ FetchUnreadFriendRequestCount()

TTV_ErrorCode ttv::social::SocialAPI::FetchUnreadFriendRequestCount ( UserId  userId,
const FetchUnreadFriendRequestCountCallback callback 
)

Initiates an async retrieval of the number of unread friend requests. The result will be notified via ISocialAPIListener::SocialFetchUnreadFriendRequestsCountComplete.

◆ GetAutomaticPresencePostingEnabled()

TTV_ErrorCode ttv::social::SocialAPI::GetAutomaticPresencePostingEnabled ( UserId  userId,
bool &  enabled 
)

Determines whether or not the presence system is automatically posting the user's presence.

◆ GetComponentContainer()

std::shared_ptr<ComponentContainer> ttv::ModuleBase::GetComponentContainer ( )
inlineprotectedinherited

Returns the common ComponentContainer which hosts all components which live at the module level.

◆ GetFriendListForUser()

TTV_ErrorCode ttv::social::SocialAPI::GetFriendListForUser ( UserId  userId,
std::shared_ptr< FriendList > &  friendList 
)
private

◆ GetModuleName()

virtual std::string ttv::social::SocialAPI::GetModuleName ( ) const
overridevirtual

Returns the name of the module.

Implements ttv::IModule.

◆ GetPresenceForUser()

TTV_ErrorCode ttv::social::SocialAPI::GetPresenceForUser ( UserId  userId,
std::shared_ptr< Presence > &  presence 
)
private

◆ GetState()

virtual State ttv::ModuleBase::GetState ( ) const
overridevirtualinherited

Returns the current state of the module.

Implements ttv::IModule.

◆ Initialize()

virtual TTV_ErrorCode ttv::social::SocialAPI::Initialize ( const InitializeCallback callback)
overridevirtual

Initializes the module asynchronously. The module state will be reported in IModuleListener::ModuleStateChanged(). No other calls should be made into the module until the module state is either State::Initialized or State::Uninitialized. You should only expect changes to the module state if this method succeeds.

Reimplemented from ttv::ModuleBase.

◆ Invoke()

template<typename T >
void ttv::ModuleBase::Invoke ( std::function< void(std::shared_ptr< T >)>  callback)
inlineprotectedinherited

Invokes the callback for the module listeners.

◆ MarkAllFriendRequestsRead()

TTV_ErrorCode ttv::social::SocialAPI::MarkAllFriendRequestsRead ( UserId  userId,
const MarkAllFriendRequestsReadCallback callback 
)

Asynchronously marks all friend requests as read. The result will be notified via ISocialAPIListener::SocialMarkAllFriendRequestsReadComplete. NOTE: This does not reject any requsts.

◆ NotifyStateChange()

void ttv::ModuleBase::NotifyStateChange ( )
protectedinherited

◆ PostPresence()

TTV_ErrorCode ttv::social::SocialAPI::PostPresence ( UserId  userId,
const PostPresenceCallback callback 
)

Manually pings the backend presence service to indicate that the client is still alive. This normally does not need to be done since presence is automatically maintained internally. Use this only in circumstances where the client was offline for a period of time. The result will be returned via the passed-in callback.

◆ RegisterInitializeCallback()

void ttv::ModuleBase::RegisterInitializeCallback ( const InitializeCallback callback)
inlineprotectedinherited

◆ RegisterShutdownCallback()

void ttv::ModuleBase::RegisterShutdownCallback ( const ShutdownCallback callback)
inlineprotectedinherited

◆ RemoveActivity()

TTV_ErrorCode ttv::social::SocialAPI::RemoveActivity ( UserId  userId,
PresenceActivityToken  activityToken 
)

Removes the activity that corresponds to the passed in activity token.

◆ SetAutomaticPresencePostingEnabled()

TTV_ErrorCode ttv::social::SocialAPI::SetAutomaticPresencePostingEnabled ( UserId  userId,
bool  enabled 
)

Specifies whether or not the presence system should automatically posting the user's presence.

◆ SetCoreApi()

TTV_ErrorCode ttv::social::SocialAPI::SetCoreApi ( const std::shared_ptr< CoreAPI > &  coreApi)

◆ SetEnabledFeatures()

TTV_ErrorCode ttv::social::SocialAPI::SetEnabledFeatures ( const FeatureFlags features)

◆ SetListener()

TTV_ErrorCode ttv::social::SocialAPI::SetListener ( const std::shared_ptr< ISocialAPIListener > &  listener)

◆ SetPresenceSessionAvailability()

TTV_ErrorCode ttv::social::SocialAPI::SetPresenceSessionAvailability ( UserId  userId,
PresenceSessionAvailability  availability 
)

Sets the presence availability mode for the given user.

◆ SetPresenceSettings()

TTV_ErrorCode ttv::social::SocialAPI::SetPresenceSettings ( UserId  userId,
const PresenceSettings settings,
const SetPresenceSettingsCallback callback 
)

Applies the given presence settings.

Parameters
[in]userIdThe id of the user we're changing the presence settings of.
[in]settingsSettings include a user's presence override and whether they're sharing their current activity. A presence override means that the user will appear as that presence availability to their friends regardless of the states of their sessions. If a user sets their presence as UserAvailability::None, then their sessions determine their availability.
[in]callbackCallback that returns the result PresenceSettings.
Returns
  • TTV_EC_SUCCESS: We've sent the request to update the presence settings.
  • TTV_EC_SHUT_DOWN: Social API is not initialized.
  • TTV_EC_REQUEST_PENDING: There's already a request to set the presence settings.
  • TTV_EC_NEED_TO_LOGIN: The user is not logged in.

◆ Shutdown()

virtual TTV_ErrorCode ttv::social::SocialAPI::Shutdown ( const ShutdownCallback callback)
overridevirtual

Initiates an asynchronous shutdown of the module. The module state will be reported in IModuleListener::ModuleStateChanged(). No other calls should be made into the module until the module state is either State::Initialized or State::Uninitialized. All modules that depend on this module need to be shutdown first. You should only expect changes to the module state if this method succeeds.

Reimplemented from ttv::ModuleBase.

◆ Update()

virtual TTV_ErrorCode ttv::social::SocialAPI::Update ( )
overridevirtual

Updates the internal state of the module and fires any pending callbacks.

Reimplemented from ttv::ModuleBase.

◆ UpdateFriendship()

TTV_ErrorCode ttv::social::SocialAPI::UpdateFriendship ( UserId  userId,
UserId  otherUserId,
FriendAction  action,
const UpdateFriendshipCallback callback 
)

Initiates an async change of status with a friend. This is used to send, accept and reject friend requests and remove an existing friend. The result will be notified via ISocialAPIListener::SocialUpdateFriendshipComplete.

Member Data Documentation

◆ mCoreApi

std::shared_ptr<CoreAPI> ttv::social::SocialAPI::mCoreApi
private

◆ mCoreApiClient

std::shared_ptr<ICoreApiClient> ttv::social::SocialAPI::mCoreApiClient
private

◆ mEnabledFeatures

FeatureFlags ttv::social::SocialAPI::mEnabledFeatures
private

◆ mInternalData

std::shared_ptr<SocialAPIInternalData> ttv::social::SocialAPI::mInternalData
private

◆ mLastReportedState

State ttv::ModuleBase::mLastReportedState
protectedinherited

◆ mListeners

EventSource<IModuleListener> ttv::ModuleBase::mListeners
protectedinherited

The registered listeners. These listeners extend IModuleListener and will be of the type required for the module.

◆ mState

State ttv::ModuleBase::mState
protectedinherited

◆ mTaskRunner

std::shared_ptr<TaskRunner> ttv::social::SocialAPI::mTaskRunner
private

◆ mUserRepository

std::shared_ptr<UserRepository> ttv::social::SocialAPI::mUserRepository
private

The documentation for this class was generated from the following file: