Skip to content

Commit

Permalink
Merge pull request #373 from opentween/fix-account-state
Browse files Browse the repository at this point in the history
設定画面を閉じる度にFollowerIdsなどが空の状態にリセットされる不具合を修正
  • Loading branch information
upsilon authored Jun 14, 2024
2 parents 7e6f5ea + 398afe4 commit 914608c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
==== Unreleased
* FIX: Cookie使用時に「Listの発言取得に公式RTを含める」の設定が適用されない不具合を修正
* FIX: Twitterアカウントでの画像を添付したツイートの投稿がエラーになる不具合を修正
* FIX: 設定画面を閉じた直後に取得されるツイートが全て両思い表示になる不具合を修正

==== Ver 3.15.0(2024/06/14)
* NEW: Misskeyでのノート投稿時のファイル添付に対応しました
Expand Down
12 changes: 4 additions & 8 deletions OpenTween/SocialProtocol/Misskey/MisskeyAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ISocialProtocolClient ISocialAccount.Client

public bool IsDisposed { get; private set; }

public MisskeyAccountState AccountState { get; private set; } = new();
public MisskeyAccountState AccountState { get; } = new();

ISocialAccountState ISocialAccount.AccountState
=> this.AccountState;
Expand Down Expand Up @@ -71,14 +71,10 @@ public void Initialize(UserAccount accountSettings, SettingCommon settingCommon)
{
Debug.Assert(accountSettings.UniqueKey == this.UniqueKey.Id, "UniqueKey must be same as current value.");

var serverUri = new Uri($"https://{accountSettings.ServerHostname}/");
this.AccountState = new(serverUri, new(accountSettings.UserId), accountSettings.Username)
{
AuthorizedScopes = accountSettings.Scopes,
HasUnrecoverableError = false,
};
this.AccountState.UpdateFromSettings(accountSettings);
this.AccountState.HasUnrecoverableError = false;

var apiBaseUri = new Uri(serverUri, "/api/");
var apiBaseUri = new Uri(this.AccountState.ServerUri, "/api/");

var newConnection = new MisskeyApiConnection(apiBaseUri, accountSettings.TokenSecret, this.AccountState);
(this.connection, var oldConnection) = (newConnection, this.connection);
Expand Down
8 changes: 8 additions & 0 deletions OpenTween/SocialProtocol/Misskey/MisskeyAccountState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ public MisskeyAccountState(Uri serverUri, MisskeyUserId userId, string userName)
this.UserName = userName;
}

public void UpdateFromSettings(UserAccount accountSettings)
{
this.ServerUri = new($"https://{accountSettings.ServerHostname}/");
this.UserId = new(accountSettings.UserId);
this.UserName = accountSettings.Username;
this.AuthorizedScopes = accountSettings.Scopes;
}

/// <summary>ユーザー情報を更新します</summary>
public void UpdateFromUser(MisskeyUser self)
{
Expand Down
9 changes: 3 additions & 6 deletions OpenTween/SocialProtocol/Twitter/TwitterAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public string AccountType

public bool IsDisposed { get; private set; }

public TwitterAccountState AccountState { get; private set; } = new();
public TwitterAccountState AccountState { get; } = new();

ISocialAccountState ISocialAccount.AccountState
=> this.AccountState;
Expand Down Expand Up @@ -72,12 +72,9 @@ public void Initialize(UserAccount accountSettings, SettingCommon settingCommon)
Debug.Assert(accountSettings.UniqueKey == this.UniqueKey.Id, "UniqueKey must be same as current value.");

var credential = accountSettings.GetTwitterCredential();
var userId = new TwitterUserId(accountSettings.UserId);

this.AccountState = new TwitterAccountState(userId, accountSettings.Username)
{
HasUnrecoverableError = credential is TwitterCredentialNone,
};
this.AccountState.UpdateFromSettings(accountSettings);
this.AccountState.HasUnrecoverableError = credential is TwitterCredentialNone;

var newConnection = new TwitterApiConnection(credential, this.AccountState);
(this.apiConnection, var oldConnection) = (newConnection, this.apiConnection);
Expand Down
6 changes: 6 additions & 0 deletions OpenTween/SocialProtocol/Twitter/TwitterAccountState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public TwitterAccountState(TwitterUserId userId, string userName)
this.UserName = userName;
}

public void UpdateFromSettings(UserAccount accountSettings)
{
this.UserId = new(accountSettings.UserId);
this.UserName = accountSettings.Username;
}

/// <summary>ユーザー情報を更新します</summary>
public void UpdateFromUser(TwitterUser self)
{
Expand Down

0 comments on commit 914608c

Please sign in to comment.