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

#include <chatuserthreads.h>

Inheritance diagram for ttv::chat::ChatUserThreads:
ttv::UserComponent ttv::Component ttv::IComponent

Classes

class  InternalThreadListener
 
class  PubSubTopicListener
 

Public Types

using SendMessageCallback = std::function< void(TTV_ErrorCode ec, MessageId messageId)>
 
using FetchThreadDataPageCallback = std::function< void(TTV_ErrorCode ec, const std::vector< ThreadData > &page, uint32_t total)>
 
using FetchThreadDataCallback = std::function< void(TTV_ErrorCode ec, const ThreadData &data)>
 
using FetchUnreadCountsCallback = std::function< void(TTV_ErrorCode ec, const UnreadThreadCounts &counts)>
 
enum  State { State::Uninitialized, State::Initialized, State::ShuttingDown, State::Inert }
 

Public Member Functions

 ChatUserThreads (std::shared_ptr< User > user)
 
virtual ~ChatUserThreads ()
 
void SetTokenizationOptions (const TokenizationOptions &options)
 
void SetUserRepository (std::shared_ptr< UserRepository > repository)
 
void SetSettingRepository (std::shared_ptr< SettingRepository > settings)
 
void SetBitsConfigRepository (std::shared_ptr< BitsConfigRepository > repository)
 
void SetListener (std::shared_ptr< IChatUserThreadsListener > listener)
 
virtual TTV_ErrorCode Initialize () override
 
virtual void Update () override
 
virtual TTV_ErrorCode Shutdown () override
 
virtual std::string GetLoggerName () const override
 
virtual void OnUserInfoFetchComplete (TTV_ErrorCode ec) override
 
TTV_ErrorCode SendMessageToUser (UserId userId, const std::string &message, WhisperMessage &placeholderMessage, const SendMessageCallback &callback)
 
TTV_ErrorCode FetchThreadDataPage (uint32_t offset, uint32_t pageSize, const FetchThreadDataPageCallback &callback)
 
TTV_ErrorCode FetchThreadData (const std::string &threadId, const FetchThreadDataCallback &callback)
 
TTV_ErrorCode RemoveThread (const std::string &threadId)
 
TTV_ErrorCode RemoveThreadWithUser (UserId userId)
 
TTV_ErrorCode FetchUnreadCounts (const FetchUnreadCountsCallback &callback)
 
TTV_ErrorCode FetchChatDisplayInfo ()
 
TTV_ErrorCode FetchEmoteSets ()
 
std::shared_ptr< ChatUserThreadGetThread (const std::string &threadId)
 
virtual void SetTaskRunner (std::shared_ptr< TaskRunner > taskRunner)
 
std::shared_ptr< TaskRunnerGetTaskRunner ()
 
virtual State GetState () const override
 

Static Public Member Functions

static std::string GenerateThreadId (UserId a, UserId b)
 
static std::string GetComponentName ()
 

Protected Member Functions

virtual bool CheckShutdown () override
 
virtual void CompleteShutdown () override
 
virtual void OnUserLogInComplete (TTV_ErrorCode ec)
 
virtual void OnUserLogOutComplete (TTV_ErrorCode ec)
 
virtual void OnUserAuthenticationIssue (std::shared_ptr< const OAuthToken > oauthToken, TTV_ErrorCode ec)
 
void Log (TTV_MessageLevel level, const char *format,...)
 
TTV_ErrorCode StartTask (std::shared_ptr< Task > task)
 
void CompleteTask (Task *task)
 
bool IsTaskRunning (Task *task) const
 
virtual void SetState (State state)
 
virtual void SetClientState (State state)
 
virtual void SetServerState (State state)
 

Protected Attributes

std::weak_ptr< UsermUser
 
bool mOAuthIssue
 Whether or not the internal updates of the component are on hold because of an issue with the OAuth token. More...
 
ClientServerValue< StatemState
 
std::shared_ptr< TaskRunnermTaskRunner
 
std::vector< std::shared_ptr< Task > > mRunningTasks
 
std::mutex mTaskMutex
 
uint64_t mShutdownTimeMilliseconds
 

Private Member Functions

void OnTopicSubscribeStateChanged (const std::string &topic, PubSubClient::SubscribeState::Enum state, TTV_ErrorCode ec)
 
void OnTopicMessageReceived (const std::string &topic, const json::Value &msg)
 
void OnMetadataFetchComplete (ChatUserThread *source, TTV_ErrorCode ec)
 
void OnRealtimeMessageReceived (ChatUserThread *source, const WhisperMessage &message)
 
void OnParticipantsUpdated (ChatUserThread *source, const std::vector< ChatUserInfo > &participants)
 
void OnMuteStatusChanged (ChatUserThread *source, bool muted)
 
void OnUnreadMessageWindowChanged (ChatUserThread *source, MessageId lastMessageId, MessageId lastReadMessageId)
 
TTV_ErrorCode SubscribeTopics ()
 
TTV_ErrorCode SendMessageWithThread (const std::shared_ptr< ChatUserThread > &thread, UserId otherUserId, const std::string &message, const SendMessageCallback &callback)
 
void ProcessSentNonce (const std::string &nonce, MessageId messageId, TTV_ErrorCode ec)
 
void UpdateCachedThreadWithLiveMessage (const WhisperMessage &message)
 
void MergeThreads (const std::vector< ThreadData > &threadList)
 
std::shared_ptr< ChatUserThreadCreateThread (const std::string &threadId, const ThreadData *data)
 
void BumpThread (const std::string &threadId)
 
TTV_ErrorCode SyncCachedThreads ()
 
TTV_ErrorCode TokenizeLocalMessage (const std::shared_ptr< User > &user, const std::string &message, const std::string &threadId, WhisperMessage &chatMessage)
 
TTV_ErrorCode FetchBitsConfig ()
 
void RequestUnreadCounts ()
 

Private Attributes

std::weak_ptr< UserRepositorymUserRepository
 
std::shared_ptr< SettingRepositorymSettingRepository
 
std::shared_ptr< BitsConfigRepositorymBitsConfigRepository
 
std::shared_ptr< BitsConfigurationmBitsConfiguration
 
std::map< std::string, std::shared_ptr< ChatUserThread > > mThreadMap
 The mapping of thread id to thread. More...
 
std::vector< std::shared_ptr< ChatUserThread > > mThreadList
 The ordered list of cached threads, sorted by decreasing timestamp. More...
 
std::map< std::string, SendMessageCallbackmPendingSentCallbacksByNonce
 Sent message nonces on which we are waiting for an acknowledgement from the server. More...
 
std::shared_ptr< ChatGetUnreadMessageCountTaskmChatGetUnreadMessageCountTask
 
std::shared_ptr< ChatGetDisplayInfoTaskmChatGetDisplayInfoTask
 
std::shared_ptr< ChatUserThread::ListenermInternalThreadListener
 
EventSource< IChatUserThreadsListenermListeners
 
std::shared_ptr< PagedRequestFetchermThreadPageFetcher
 
std::shared_ptr< PubSubClientmPubSub
 
std::shared_ptr< PubSubTopicListenermPubSubTopicListener
 
std::shared_ptr< PubSubTopicListenerHelpermPubSubTopicListenerHelper
 
std::string mWhisperPubSubTopic
 The topic used to subscribe for realtime whisper events. More...
 
ChatUserInfo mChatUserInfo
 The cached user info for the local user. More...
 
WaitForExpiry mUnreadSyncTimer
 When to update the unread count information from the backend. More...
 
WaitForExpiry mUserChatDisplayFetchTimer
 When to fetch the enabled badges and user color info from the backend. More...
 
RetryTimer mCachedThreadSyncTimer
 When to refresh the content of cached threads. More...
 
RetryTimer mFetchBitsConfigRetryTimer
 
std::unique_ptr< UnreadThreadCachemUnreadThreadCache
 
CallbackQueue< FetchUnreadCountsCallbackmUnreadCountCallbacks
 
uint32_t mMaxFetchedThreadOffset
 The maximum offset for loaded thread pages. More...
 
TokenizationOptions mTokenizationOptions
 
bool mBitsConfigFetchInFlight
 
bool mHasFetchedBitsConfig
 

Detailed Description

The collection of conversation threads from the perspective of a user.

Member Typedef Documentation

◆ FetchThreadDataCallback

◆ FetchThreadDataPageCallback

using ttv::chat::ChatUserThreads::FetchThreadDataPageCallback = std::function<void(TTV_ErrorCode ec, const std::vector<ThreadData>& page, uint32_t total)>

◆ FetchUnreadCountsCallback

◆ SendMessageCallback

using ttv::chat::ChatUserThreads::SendMessageCallback = std::function<void(TTV_ErrorCode ec, MessageId messageId)>

Member Enumeration Documentation

◆ State

enum ttv::IComponent::State
stronginherited
Enumerator
Uninitialized 
Initialized 
ShuttingDown 
Inert 

The component doesn't require shutting down.

Constructor & Destructor Documentation

◆ ChatUserThreads()

ttv::chat::ChatUserThreads::ChatUserThreads ( std::shared_ptr< User user)

◆ ~ChatUserThreads()

virtual ttv::chat::ChatUserThreads::~ChatUserThreads ( )
virtual

Member Function Documentation

◆ BumpThread()

void ttv::chat::ChatUserThreads::BumpThread ( const std::string &  threadId)
private

◆ CheckShutdown()

virtual bool ttv::chat::ChatUserThreads::CheckShutdown ( )
overrideprotectedvirtual

Reimplemented from ttv::Component.

◆ CompleteShutdown()

virtual void ttv::chat::ChatUserThreads::CompleteShutdown ( )
overrideprotectedvirtual

Reimplemented from ttv::UserComponent.

◆ CompleteTask()

void ttv::Component::CompleteTask ( Task task)
protectedinherited

◆ CreateThread()

std::shared_ptr<ChatUserThread> ttv::chat::ChatUserThreads::CreateThread ( const std::string &  threadId,
const ThreadData data 
)
private

◆ FetchBitsConfig()

TTV_ErrorCode ttv::chat::ChatUserThreads::FetchBitsConfig ( )
private

◆ FetchChatDisplayInfo()

TTV_ErrorCode ttv::chat::ChatUserThreads::FetchChatDisplayInfo ( )

Forces a fetch of the user's color and enabled badges.

◆ FetchEmoteSets()

TTV_ErrorCode ttv::chat::ChatUserThreads::FetchEmoteSets ( )

Forces a fetch of the user's avaiable emote set ids.

◆ FetchThreadData()

TTV_ErrorCode ttv::chat::ChatUserThreads::FetchThreadData ( const std::string &  threadId,
const FetchThreadDataCallback callback 
)

Asynchronously fetches the named thread. The OnThreadFetchComplete callback will be called with the result.

◆ FetchThreadDataPage()

TTV_ErrorCode ttv::chat::ChatUserThreads::FetchThreadDataPage ( uint32_t  offset,
uint32_t  pageSize,
const FetchThreadDataPageCallback callback 
)

Asynchronously fetches the specified page. The OnPageFetchComplete callback will be called with the result.

◆ FetchUnreadCounts()

TTV_ErrorCode ttv::chat::ChatUserThreads::FetchUnreadCounts ( const FetchUnreadCountsCallback callback)

Forces a fetch of the most recent unread counts.

◆ GenerateThreadId()

static std::string ttv::chat::ChatUserThreads::GenerateThreadId ( UserId  a,
UserId  b 
)
static

◆ GetComponentName()

static std::string ttv::chat::ChatUserThreads::GetComponentName ( )
inlinestatic

◆ GetLoggerName()

virtual std::string ttv::chat::ChatUserThreads::GetLoggerName ( ) const
overridevirtual

Implements ttv::Component.

◆ GetState()

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

Implements ttv::IComponent.

◆ GetTaskRunner()

std::shared_ptr<TaskRunner> ttv::Component::GetTaskRunner ( )
inlineinherited

◆ GetThread()

std::shared_ptr<ChatUserThread> ttv::chat::ChatUserThreads::GetThread ( const std::string &  threadId)

◆ Initialize()

virtual TTV_ErrorCode ttv::chat::ChatUserThreads::Initialize ( )
overridevirtual

Reimplemented from ttv::UserComponent.

◆ IsTaskRunning()

bool ttv::Component::IsTaskRunning ( Task task) const
protectedinherited

◆ Log()

void ttv::UserComponent::Log ( TTV_MessageLevel  level,
const char *  format,
  ... 
)
protectedinherited

◆ MergeThreads()

void ttv::chat::ChatUserThreads::MergeThreads ( const std::vector< ThreadData > &  threadList)
private

◆ OnMetadataFetchComplete()

void ttv::chat::ChatUserThreads::OnMetadataFetchComplete ( ChatUserThread source,
TTV_ErrorCode  ec 
)
private

◆ OnMuteStatusChanged()

void ttv::chat::ChatUserThreads::OnMuteStatusChanged ( ChatUserThread source,
bool  muted 
)
private

◆ OnParticipantsUpdated()

void ttv::chat::ChatUserThreads::OnParticipantsUpdated ( ChatUserThread source,
const std::vector< ChatUserInfo > &  participants 
)
private

◆ OnRealtimeMessageReceived()

void ttv::chat::ChatUserThreads::OnRealtimeMessageReceived ( ChatUserThread source,
const WhisperMessage message 
)
private

◆ OnTopicMessageReceived()

void ttv::chat::ChatUserThreads::OnTopicMessageReceived ( const std::string &  topic,
const json::Value msg 
)
private

◆ OnTopicSubscribeStateChanged()

void ttv::chat::ChatUserThreads::OnTopicSubscribeStateChanged ( const std::string &  topic,
PubSubClient::SubscribeState::Enum  state,
TTV_ErrorCode  ec 
)
private

◆ OnUnreadMessageWindowChanged()

void ttv::chat::ChatUserThreads::OnUnreadMessageWindowChanged ( ChatUserThread source,
MessageId  lastMessageId,
MessageId  lastReadMessageId 
)
private

◆ OnUserAuthenticationIssue()

virtual void ttv::UserComponent::OnUserAuthenticationIssue ( std::shared_ptr< const OAuthToken oauthToken,
TTV_ErrorCode  ec 
)
protectedvirtualinherited

◆ OnUserInfoFetchComplete()

virtual void ttv::chat::ChatUserThreads::OnUserInfoFetchComplete ( TTV_ErrorCode  ec)
overridevirtual

Reimplemented from ttv::UserComponent.

◆ OnUserLogInComplete()

virtual void ttv::UserComponent::OnUserLogInComplete ( TTV_ErrorCode  ec)
protectedvirtualinherited

◆ OnUserLogOutComplete()

virtual void ttv::UserComponent::OnUserLogOutComplete ( TTV_ErrorCode  ec)
protectedvirtualinherited

◆ ProcessSentNonce()

void ttv::chat::ChatUserThreads::ProcessSentNonce ( const std::string &  nonce,
MessageId  messageId,
TTV_ErrorCode  ec 
)
private

◆ RemoveThread()

TTV_ErrorCode ttv::chat::ChatUserThreads::RemoveThread ( const std::string &  threadId)

Removes the thread from the cache, if it exists.

◆ RemoveThreadWithUser()

TTV_ErrorCode ttv::chat::ChatUserThreads::RemoveThreadWithUser ( UserId  userId)

Removes the 1:1 thread with the given user from the cache, if it exists.

◆ RequestUnreadCounts()

void ttv::chat::ChatUserThreads::RequestUnreadCounts ( )
private

◆ SendMessageToUser()

TTV_ErrorCode ttv::chat::ChatUserThreads::SendMessageToUser ( UserId  userId,
const std::string &  message,
WhisperMessage placeholderMessage,
const SendMessageCallback callback 
)

Sends a whisper to the given user. nonce: The unique id for the message which is used in other callbacks to confirm sending and deduplication.

◆ SendMessageWithThread()

TTV_ErrorCode ttv::chat::ChatUserThreads::SendMessageWithThread ( const std::shared_ptr< ChatUserThread > &  thread,
UserId  otherUserId,
const std::string &  message,
const SendMessageCallback callback 
)
private

◆ SetBitsConfigRepository()

void ttv::chat::ChatUserThreads::SetBitsConfigRepository ( std::shared_ptr< BitsConfigRepository repository)
inline

◆ SetClientState()

virtual void ttv::Component::SetClientState ( State  state)
protectedvirtualinherited

◆ SetListener()

void ttv::chat::ChatUserThreads::SetListener ( std::shared_ptr< IChatUserThreadsListener listener)

◆ SetServerState()

virtual void ttv::Component::SetServerState ( State  state)
protectedvirtualinherited

◆ SetSettingRepository()

void ttv::chat::ChatUserThreads::SetSettingRepository ( std::shared_ptr< SettingRepository settings)

◆ SetState()

virtual void ttv::Component::SetState ( State  state)
protectedvirtualinherited

◆ SetTaskRunner()

virtual void ttv::Component::SetTaskRunner ( std::shared_ptr< TaskRunner taskRunner)
virtualinherited

◆ SetTokenizationOptions()

void ttv::chat::ChatUserThreads::SetTokenizationOptions ( const TokenizationOptions options)
inline

◆ SetUserRepository()

void ttv::chat::ChatUserThreads::SetUserRepository ( std::shared_ptr< UserRepository repository)
inline

◆ Shutdown()

virtual TTV_ErrorCode ttv::chat::ChatUserThreads::Shutdown ( )
overridevirtual

Reimplemented from ttv::Component.

◆ StartTask()

TTV_ErrorCode ttv::Component::StartTask ( std::shared_ptr< Task task)
protectedinherited

◆ SubscribeTopics()

TTV_ErrorCode ttv::chat::ChatUserThreads::SubscribeTopics ( )
private

◆ SyncCachedThreads()

TTV_ErrorCode ttv::chat::ChatUserThreads::SyncCachedThreads ( )
private

◆ TokenizeLocalMessage()

TTV_ErrorCode ttv::chat::ChatUserThreads::TokenizeLocalMessage ( const std::shared_ptr< User > &  user,
const std::string &  message,
const std::string &  threadId,
WhisperMessage chatMessage 
)
private

◆ Update()

virtual void ttv::chat::ChatUserThreads::Update ( )
overridevirtual

Reimplemented from ttv::Component.

◆ UpdateCachedThreadWithLiveMessage()

void ttv::chat::ChatUserThreads::UpdateCachedThreadWithLiveMessage ( const WhisperMessage message)
private

Member Data Documentation

◆ mBitsConfigFetchInFlight

bool ttv::chat::ChatUserThreads::mBitsConfigFetchInFlight
private

◆ mBitsConfigRepository

std::shared_ptr<BitsConfigRepository> ttv::chat::ChatUserThreads::mBitsConfigRepository
private

◆ mBitsConfiguration

std::shared_ptr<BitsConfiguration> ttv::chat::ChatUserThreads::mBitsConfiguration
private

◆ mCachedThreadSyncTimer

RetryTimer ttv::chat::ChatUserThreads::mCachedThreadSyncTimer
private

When to refresh the content of cached threads.

◆ mChatGetDisplayInfoTask

std::shared_ptr<ChatGetDisplayInfoTask> ttv::chat::ChatUserThreads::mChatGetDisplayInfoTask
private

◆ mChatGetUnreadMessageCountTask

std::shared_ptr<ChatGetUnreadMessageCountTask> ttv::chat::ChatUserThreads::mChatGetUnreadMessageCountTask
private

◆ mChatUserInfo

ChatUserInfo ttv::chat::ChatUserThreads::mChatUserInfo
private

The cached user info for the local user.

◆ mFetchBitsConfigRetryTimer

RetryTimer ttv::chat::ChatUserThreads::mFetchBitsConfigRetryTimer
private

◆ mHasFetchedBitsConfig

bool ttv::chat::ChatUserThreads::mHasFetchedBitsConfig
private

◆ mInternalThreadListener

std::shared_ptr<ChatUserThread::Listener> ttv::chat::ChatUserThreads::mInternalThreadListener
private

◆ mListeners

EventSource<IChatUserThreadsListener> ttv::chat::ChatUserThreads::mListeners
private

◆ mMaxFetchedThreadOffset

uint32_t ttv::chat::ChatUserThreads::mMaxFetchedThreadOffset
private

The maximum offset for loaded thread pages.

◆ mOAuthIssue

bool ttv::UserComponent::mOAuthIssue
protectedinherited

Whether or not the internal updates of the component are on hold because of an issue with the OAuth token.

◆ mPendingSentCallbacksByNonce

std::map<std::string, SendMessageCallback> ttv::chat::ChatUserThreads::mPendingSentCallbacksByNonce
private

Sent message nonces on which we are waiting for an acknowledgement from the server.

◆ mPubSub

std::shared_ptr<PubSubClient> ttv::chat::ChatUserThreads::mPubSub
private

◆ mPubSubTopicListener

std::shared_ptr<PubSubTopicListener> ttv::chat::ChatUserThreads::mPubSubTopicListener
private

◆ mPubSubTopicListenerHelper

std::shared_ptr<PubSubTopicListenerHelper> ttv::chat::ChatUserThreads::mPubSubTopicListenerHelper
private

◆ mRunningTasks

std::vector<std::shared_ptr<Task> > ttv::Component::mRunningTasks
protectedinherited

◆ mSettingRepository

std::shared_ptr<SettingRepository> ttv::chat::ChatUserThreads::mSettingRepository
private

◆ mShutdownTimeMilliseconds

uint64_t ttv::Component::mShutdownTimeMilliseconds
protectedinherited

◆ mState

ClientServerValue<State> ttv::Component::mState
protectedinherited

◆ mTaskMutex

std::mutex ttv::Component::mTaskMutex
mutableprotectedinherited

◆ mTaskRunner

std::shared_ptr<TaskRunner> ttv::Component::mTaskRunner
protectedinherited

◆ mThreadList

std::vector<std::shared_ptr<ChatUserThread> > ttv::chat::ChatUserThreads::mThreadList
private

The ordered list of cached threads, sorted by decreasing timestamp.

◆ mThreadMap

std::map<std::string, std::shared_ptr<ChatUserThread> > ttv::chat::ChatUserThreads::mThreadMap
private

The mapping of thread id to thread.

◆ mThreadPageFetcher

std::shared_ptr<PagedRequestFetcher> ttv::chat::ChatUserThreads::mThreadPageFetcher
private

◆ mTokenizationOptions

TokenizationOptions ttv::chat::ChatUserThreads::mTokenizationOptions
private

◆ mUnreadCountCallbacks

CallbackQueue<FetchUnreadCountsCallback> ttv::chat::ChatUserThreads::mUnreadCountCallbacks
private

◆ mUnreadSyncTimer

WaitForExpiry ttv::chat::ChatUserThreads::mUnreadSyncTimer
private

When to update the unread count information from the backend.

◆ mUnreadThreadCache

std::unique_ptr<UnreadThreadCache> ttv::chat::ChatUserThreads::mUnreadThreadCache
private

◆ mUser

std::weak_ptr<User> ttv::UserComponent::mUser
protectedinherited

◆ mUserChatDisplayFetchTimer

WaitForExpiry ttv::chat::ChatUserThreads::mUserChatDisplayFetchTimer
private

When to fetch the enabled badges and user color info from the backend.

◆ mUserRepository

std::weak_ptr<UserRepository> ttv::chat::ChatUserThreads::mUserRepository
private

◆ mWhisperPubSubTopic

std::string ttv::chat::ChatUserThreads::mWhisperPubSubTopic
private

The topic used to subscribe for realtime whisper events.


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