private async Task CreateClientAsync() { var auth = await this.preClient.ConnectWithCode(this.AccessToken); this.Client = new MastodonClient(this.appRegistration, auth); this.CurrentUser = (await this.Client.GetCurrentUser()).ToMastodonAccount(); this.PublicStreamingFunctionCounter = new ConnectionFunctionCounter <MastodonStatus>(new PublicTimelineFunction { Client = this.Client, StreamingInstanceUri = this.StreamingUri, }); var homeFunc = new HomeTimelineFunction { Client = this.Client, StreamingInstanceUri = this.StreamingUri, }; this.HomeStreamingFunctionCounter = new ConnectionFunctionCounter <MastodonStatus>(homeFunc); this.NotificationStreamingFunctionCounter = new ConnectionFunctionCompositionCounter <MastodonNotification, MastodonStatus>( new NotificationFunction(this.Client, homeFunc), this.HomeStreamingFunctionCounter ); }
private async Task <bool> CreateClientAsync(OAuthAccessTokenRepository tokenRepo) { Auth auth; if (!string.IsNullOrEmpty(this.AuthorizationCode)) { auth = await this.preClient.ConnectWithCode(this.AuthorizationCode); await tokenRepo.Save(this.InstanceUri, auth.AccessToken); } else { auth = new Auth { AccessToken = this.AccessToken }; } this.Client = new MastodonClient(this.appRegistration, auth); var user = await this.Client.GetCurrentUser(); // 自分のアカウント名が取得できてなかったら失敗とする if (string.IsNullOrEmpty(user?.AccountName)) { return(false); } this.CurrentUser = user.ToMastodonAccount(); this.PublicStreamingFunctionCounter = new ConnectionFunctionCounter <MastodonStatus>(new PublicTimelineFunction { Client = this.Client, StreamingInstanceUri = this.StreamingUri, }); var homeFunc = new HomeTimelineFunction { Client = this.Client, StreamingInstanceUri = this.StreamingUri, }; this.HomeStreamingFunctionCounter = new ConnectionFunctionCounter <MastodonStatus>(homeFunc); this.NotificationStreamingFunctionCounter = new ConnectionFunctionCompositionCounter <MastodonNotification, MastodonStatus>( new NotificationFunction(this.Client, homeFunc), this.HomeStreamingFunctionCounter ); return(true); }