private void NotifyNewPosts(PostClass[] notifyPosts, string soundFile, int addCount, bool newMentions)
{
if (this._cfgCommon.ReadOwnPost)
{
if (notifyPosts != null && notifyPosts.Length > 0 && notifyPosts.All(x => x.UserId == tw.UserId))
return;
}
//新着通知
if (BalloonRequired())
{
if (notifyPosts != null && notifyPosts.Length > 0)
{
//Growlは一個ずつばらして通知。ただし、3ポスト以上あるときはまとめる
if (this._cfgCommon.IsUseNotifyGrowl)
{
StringBuilder sb = new StringBuilder();
bool reply = false;
bool dm = false;
foreach (PostClass post in notifyPosts)
{
if (!(notifyPosts.Length > 3))
{
sb.Clear();
reply = false;
dm = false;
}
if (post.IsReply && !post.IsExcludeReply) reply = true;
if (post.IsDm) dm = true;
if (sb.Length > 0) sb.Append(System.Environment.NewLine);
switch (this._cfgCommon.NameBalloon)
{
case MyCommon.NameBalloonEnum.UserID:
sb.Append(post.ScreenName).Append(" : ");
break;
case MyCommon.NameBalloonEnum.NickName:
sb.Append(post.Nickname).Append(" : ");
break;
}
sb.Append(post.TextFromApi);
if (notifyPosts.Length > 3)
{
if (notifyPosts.Last() != post) continue;
}
StringBuilder title = new StringBuilder();
GrowlHelper.NotifyType nt;
if (this._cfgCommon.DispUsername)
{
title.Append(tw.Username);
title.Append(" - ");
}
else
{
//title.Clear();
}
if (dm)
{
//NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
//NotifyIcon1.BalloonTipTitle += Application.ProductName + " [DM] " + Properties.Resources.RefreshDirectMessageText1 + " " + addCount.ToString() + Properties.Resources.RefreshDirectMessageText2;
title.Append(Application.ProductName);
title.Append(" [DM] ");
title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
nt = GrowlHelper.NotifyType.DirectMessage;
}
else if (reply)
{
//NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
//NotifyIcon1.BalloonTipTitle += Application.ProductName + " [Reply!] " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
title.Append(Application.ProductName);
title.Append(" [Reply!] ");
title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
nt = GrowlHelper.NotifyType.Reply;
}
else
{
//NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
//NotifyIcon1.BalloonTipTitle += Application.ProductName + " " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
title.Append(Application.ProductName);
title.Append(" ");
title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
nt = GrowlHelper.NotifyType.Notify;
}
string bText = sb.ToString();
if (string.IsNullOrEmpty(bText)) return;
var image = this.IconCache.TryGetFromCache(post.ImageUrl);
gh.Notify(nt, post.StatusId.ToString(), title.ToString(), bText, image == null ? null : image.Image, post.ImageUrl);
}
}
else
{
StringBuilder sb = new StringBuilder();
bool reply = false;
bool dm = false;
foreach (PostClass post in notifyPosts)
{
if (post.IsReply && !post.IsExcludeReply) reply = true;
if (post.IsDm) dm = true;
if (sb.Length > 0) sb.Append(System.Environment.NewLine);
switch (this._cfgCommon.NameBalloon)
{
case MyCommon.NameBalloonEnum.UserID:
sb.Append(post.ScreenName).Append(" : ");
break;
case MyCommon.NameBalloonEnum.NickName:
sb.Append(post.Nickname).Append(" : ");
break;
}
sb.Append(post.TextFromApi);
}
//if (SettingDialog.DispUsername) { NotifyIcon1.BalloonTipTitle = tw.Username + " - "; } else { NotifyIcon1.BalloonTipTitle = ""; }
StringBuilder title = new StringBuilder();
ToolTipIcon ntIcon;
if (this._cfgCommon.DispUsername)
{
title.Append(tw.Username);
title.Append(" - ");
}
else
{
//title.Clear();
}
if (dm)
{
//NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
//NotifyIcon1.BalloonTipTitle += Application.ProductName + " [DM] " + Properties.Resources.RefreshDirectMessageText1 + " " + addCount.ToString() + Properties.Resources.RefreshDirectMessageText2;
ntIcon = ToolTipIcon.Warning;
title.Append(Application.ProductName);
title.Append(" [DM] ");
title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
}
else if (reply)
{
//NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
//NotifyIcon1.BalloonTipTitle += Application.ProductName + " [Reply!] " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
ntIcon = ToolTipIcon.Warning;
title.Append(Application.ProductName);
title.Append(" [Reply!] ");
title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
}
else
{
//NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
//NotifyIcon1.BalloonTipTitle += Application.ProductName + " " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
ntIcon = ToolTipIcon.Info;
title.Append(Application.ProductName);
title.Append(" ");
title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
}
string bText = sb.ToString();
if (string.IsNullOrEmpty(bText)) return;
//NotifyIcon1.BalloonTipText = sb.ToString();
//NotifyIcon1.ShowBalloonTip(500);
NotifyIcon1.BalloonTipTitle = title.ToString();
NotifyIcon1.BalloonTipText = bText;
NotifyIcon1.BalloonTipIcon = ntIcon;
NotifyIcon1.ShowBalloonTip(500);
}
}
}
//サウンド再生
if (!_initial && this._cfgCommon.PlaySound && !string.IsNullOrEmpty(soundFile))
{
try
{
string dir = Application.StartupPath;
if (Directory.Exists(Path.Combine(dir, "Sounds")))
{
dir = Path.Combine(dir, "Sounds");
}
using (SoundPlayer player = new SoundPlayer(Path.Combine(dir, soundFile)))
{
player.Play();
}
}
catch (Exception)
{
}
}
//mentions新着時に画面ブリンク
if (!_initial && this._cfgCommon.BlinkNewMentions && newMentions && Form.ActiveForm == null)
{
NativeMethods.FlashMyWindow(this.Handle, NativeMethods.FlashSpecification.FlashTray, 3);
}
}