Skip to content

Commit

Permalink
Annictに関するUIのロジック実装 silane#7
Browse files Browse the repository at this point in the history
  • Loading branch information
noriokun4649 committed Feb 18, 2021
1 parent 9713488 commit e31e2bb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions TVTComment/Model/ChatService/TwitterChatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TwitterChatServiceSettings
public string ApiSecret { get; set; } = "";
public string ApiAccessToken { get; set; } = "";
public string ApiAccessSecret { get; set; } = "";
public string AnnictAccessToken { get; set; } = "";
}

class TwitterChatService : IChatService
Expand Down Expand Up @@ -47,6 +48,10 @@ public string ApiAccessSecret
{
get { return settings.ApiAccessSecret; }
}
public string AnnictAccessToken
{
get { return settings.AnnictAccessToken; }
}

public TwitterChatService(TwitterChatServiceSettings settings, ChannelDatabase channelDatabase, string filepath)
{
Expand Down Expand Up @@ -148,6 +153,11 @@ public void Logout()
settings.ApiAccessSecret = "";
}

public void SetAnnictToken(string token)
{
settings.AnnictAccessToken = token;
}

public void Dispose()
{
}
Expand Down
36 changes: 36 additions & 0 deletions TVTComment/ViewModels/SettingsWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Windows.Input;
using TVTComment.Model.TwitterUtils;
using TVTComment.Model.TwitterUtils.AnnictUtils;

namespace TVTComment.ViewModels
{
Expand All @@ -31,6 +32,8 @@ class SettingsWindowViewModel : BindableBase
public ObservableValue<string> TwitterApiAccessSecret { get; } = new ObservableValue<string>();
public ObservableValue<string> TwitterStatus { get; } = new ObservableValue<string>();
public ObservableValue<string> TwitterPinCode { get; } = new ObservableValue<string>();
public ObservableValue<string> AnnictAccessToken { get; } = new ObservableValue<string>();
public ObservableValue<string> AnnictPin { get; } = new ObservableValue<string>();

public Model.ChatService.NichanChatService.BoardInfo SelectedNichanBoard { get; set; }

Expand All @@ -42,6 +45,8 @@ class SettingsWindowViewModel : BindableBase
public ICommand LogoutTwitterCommand { get; }
public ICommand OpenTwitter { get; }
public ICommand EnterTwitter { get; }
public ICommand AnnictOAuthOpenCommand { get; }
public ICommand AnnictOAuthCertificationCommand { get; }

public InteractionRequest<Notification> AlertRequest { get; } = new InteractionRequest<Notification>();

Expand All @@ -55,6 +60,7 @@ class SettingsWindowViewModel : BindableBase

public SettingsWindowViewModel(Model.TVTComment model)
{
var annict = new AnnictAuthentication("jh7atLhJwvYqsSPUFg5w-GAJ5ZzaAerTONYMLMWouds", "mkvE7k2UZktun5A_GHKH-0K60kKWGK_RJKYMmU1bQPg");
DefaultChatCollectServices = new ShellContents.DefaultChatCollectServicesViewModel(model);

niconico = model.ChatServices.OfType<Model.ChatService.NiconicoChatService>().Single();
Expand Down Expand Up @@ -166,11 +172,36 @@ public SettingsWindowViewModel(Model.TVTComment model)
SyncTwitterStatus();
});

AnnictOAuthOpenCommand = new DelegateCommand(() => {
try
{
Process.Start(new ProcessStartInfo(annict.GetAuthorizeUri().ToString()) { UseShellExecute = true });
}
catch (Exception e)
{
AlertRequest.Raise(new Notification { Title = "TVTCommentエラー", Content = e.Message });
}
});

AnnictOAuthCertificationCommand = new DelegateCommand(() => {
try
{
var token = annict.GetToken(AnnictPin.Value);
twitter.SetAnnictToken(token);
}
catch (Exception e)
{
AlertRequest.Raise(new Notification { Title = "TVTCommentエラー", Content = e.Message });
}
SyncAnnictStatus();
});

ChatPreserveCount = model.ChatModule.ChatPreserveCount;

SyncNiconicoUserStatus();
SyncNichanSettings();
SyncTwitterStatus();
SyncAnnictStatus();
}

private void SyncNiconicoUserStatus()
Expand Down Expand Up @@ -200,5 +231,10 @@ private void SyncTwitterStatus()
TwitterApiAccessSecret.Value = twitter.ApiAccessSecret;
TwitterStatus.Value = twitter.IsLoggedin ? twitter.UserName + "としてログイン中" : "未ログイン";
}

private void SyncAnnictStatus()
{
AnnictAccessToken.Value = twitter.AnnictAccessToken;
}
}
}

0 comments on commit e31e2bb

Please sign in to comment.