using OpenTween.Models;
using OpenTween.OpenTweenCustomControl;
using OpenTween.Setting;
+using OpenTween.SocialProtocol;
+using OpenTween.SocialProtocol.Twitter;
using OpenTween.Thumbnail;
namespace OpenTween
// 設定ファイル
private readonly SettingManager settings;
- // twitter解析部
- private readonly Twitter tw;
+ // ユーザーアカウント
+ private readonly AccountCollection accounts;
+
+#pragma warning disable SA1300
+ private Twitter tw => ((TwitterAccount)this.accounts.Primary).Legacy; // AccountCollection への移行用
+#pragma warning restore SA1300
// Growl呼び出し部
private readonly GrowlHelper gh = new(ApplicationSettings.ApplicationName);
private readonly ThumbnailGenerator thumbGenerator;
/// <summary>発言履歴</summary>
- private readonly List<StatusTextHistory> history = new();
-
- /// <summary>発言履歴カレントインデックス</summary>
- private int hisIdx;
+ private readonly StatusTextHistory history = new();
// 発言投稿時のAPI引数(発言編集時に設定。手書きreplyでは設定されない)
PrevSearch,
}
- private readonly record struct StatusTextHistory(
- string Status,
- (PostId StatusId, string ScreenName)? InReplyTo = null
- );
-
private readonly HookGlobalHotkey hookGlobalHotkey;
public TweenMain(
SettingManager settingManager,
TabInformations tabInfo,
- Twitter twitter,
+ AccountCollection accounts,
ImageCache imageCache,
IconAssetsManager iconAssets,
ThumbnailGenerator thumbGenerator
{
this.settings = settingManager;
this.statuses = tabInfo;
- this.tw = twitter;
+ this.accounts = accounts;
this.iconCache = imageCache;
this.iconAssets = iconAssets;
this.thumbGenerator = thumbGenerator;
this.recommendedStatusFooter = " [TWNv" + Regex.Replace(MyCommon.FileVersion.Replace(".", ""), "^0*", "") + "]";
- this.history.Add(new StatusTextHistory(""));
- this.hisIdx = 0;
this.inReplyTo = null;
// 各種ダイアログ設定
_ = this.saveConfigDebouncer.Call();
}
- private void RefreshTimeline()
+ internal void RefreshTimeline()
{
var curListView = this.CurrentListView;
private void StatusTextHistoryBack()
{
- if (!string.IsNullOrWhiteSpace(this.StatusText.Text))
- this.history[this.hisIdx] = new StatusTextHistory(this.StatusText.Text, this.inReplyTo);
-
- this.hisIdx -= 1;
- if (this.hisIdx < 0)
- this.hisIdx = 0;
-
- var historyItem = this.history[this.hisIdx];
+ this.history.SetCurrentItem(this.StatusText.Text, this.inReplyTo);
+ var historyItem = this.history.Back();
this.inReplyTo = historyItem.InReplyTo;
this.StatusText.Text = historyItem.Status;
this.StatusText.SelectionStart = this.StatusText.Text.Length;
private void StatusTextHistoryForward()
{
- if (!string.IsNullOrWhiteSpace(this.StatusText.Text))
- this.history[this.hisIdx] = new StatusTextHistory(this.StatusText.Text, this.inReplyTo);
-
- this.hisIdx += 1;
- if (this.hisIdx > this.history.Count - 1)
- this.hisIdx = this.history.Count - 1;
-
- var historyItem = this.history[this.hisIdx];
+ this.history.SetCurrentItem(this.StatusText.Text, this.inReplyTo);
+ var historyItem = this.history.Forward();
this.inReplyTo = historyItem.InReplyTo;
this.StatusText.Text = historyItem.Status;
this.StatusText.SelectionStart = this.StatusText.Text.Length;
return;
}
- this.history[this.history.Count - 1] = new StatusTextHistory(this.StatusText.Text, this.inReplyTo);
-
if (this.settings.Common.Nicoms)
{
this.StatusText.SelectionStart = this.StatusText.Text.Length;
uploadService = this.ImageSelector.Model.GetService(serviceName);
}
+ this.history.AddLast(this.StatusText.Text, this.inReplyTo);
+
this.inReplyTo = null;
this.StatusText.Text = "";
- this.history.Add(new StatusTextHistory(""));
- this.hisIdx = this.history.Count - 1;
if (!this.settings.Common.FocusLockToStatusText)
this.CurrentListView.Focus();
this.urlUndoBuffer = null;
{
this.settings.ApplySettings();
- if (MyCommon.IsNullOrEmpty(this.settings.Common.Token))
- this.tw.ClearAuthInfo();
-
- var account = this.settings.Common.SelectedAccount;
- if (account != null)
- this.tw.Initialize(account.GetTwitterCredential(), account.Username, account.UserId);
- else
- this.tw.Initialize(new TwitterCredentialNone(), "", 0L);
-
- this.tw.RestrictFavCheck = this.settings.Common.RestrictFavCheck;
- this.tw.ReadOwnPost = this.settings.Common.ReadOwnPost;
-
+ this.accounts.LoadFromSettings(this.settings.Common);
this.ImageSelector.Model.InitializeServices(this.tw, this.tw.Configuration);
try
ttl.Append("Ver:").Append(MyCommon.GetReadableVersion());
break;
case MyCommon.DispTitleEnum.Post:
- if (this.history != null && this.history.Count > 1)
- ttl.Append(this.history[this.history.Count - 2].Status.Replace("\r\n", " "));
+ if (this.history.Peek() is { } lastItem)
+ ttl.Append(lastItem.Status.Replace("\r\n", " "));
break;
case MyCommon.DispTitleEnum.UnreadRepCount:
ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText1, this.statuses.MentionTab.UnreadCount + this.statuses.DirectMessageTab.UnreadCount);