-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathBLiveCommentViewModel.cs
111 lines (109 loc) · 4 KB
/
BLiveCommentViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common;
using SitePlugin;
namespace BLiveSitePlugin
{
public interface IBLiveCommentViewModel : ICommentViewModel
{
string PostDate { get; }
string Elapsed { get; }
bool IsStamp { get; }
bool IsYell { get; }
}
class BLiveCommentViewModel : CommentViewModelBase, IBLiveCommentViewModel
{
public override MessageType MessageType { get; protected set; }
private ICommentOptions _options;
private readonly IBLiveSiteOptions _siteOptions;
public string PostDate { get; }
public string Elapsed { get; }
public override string UserId { get; }
public bool IsStamp { get; }
public bool IsYell { get; }
public BLiveCommentViewModel(IBLiveCommentData commentData, ICommentOptions options, IBLiveSiteOptions siteOptions, ICommentProvider commentProvider, bool isFirstComment, IUser user)
: base(options, user, commentProvider, isFirstComment)
{
MessageType = MessageType.Comment;
_options = options;
_siteOptions = siteOptions;
UserId = commentData.UserId;
Id = commentData.Id;
PostDate = commentData.PostTime.ToString("HH:mm:ss");
var elapsed = commentData.Elapsed;
Elapsed = Tools.ElapsedToString(elapsed);
IsStamp = commentData.Stamp != null;
IsYell = commentData.IsYell;
if (!string.IsNullOrEmpty(commentData.UserIconUrl))
{
Thumbnail = new MessageImage { Url = commentData.UserIconUrl };
}
if (siteOptions.IsAutoSetNickname)
{
var nick = ExtractNickname(commentData.Message);
if (!string.IsNullOrEmpty(nick))
{
user.Nickname = nick;
}
}
//Name
{
var nameItems = new List<IMessagePart>();
nameItems.Add(MessagePartFactory.CreateMessageText(commentData.Name));
nameItems.AddRange(commentData.NameIcons);
NameItemsInternal = nameItems;
}
//Message
{
var messageItems = new List<IMessagePart>();
if (commentData.IsYell)
{
MessageType = MessageType.BroadcastInfo;
messageItems.Add(MessagePartFactory.CreateMessageText("エールポイント:" + commentData.YellPoints + Environment.NewLine));
}
messageItems.Add(MessagePartFactory.CreateMessageText(commentData.Message));
if (commentData.Stamp != null)
{
MessageType = MessageType.BroadcastInfo;
messageItems.Add(commentData.Stamp);
}
MessageItems = messageItems;
}
Init();
}
protected virtual void PlaySound(string filePath)
{
var player = new System.Media.SoundPlayer(filePath);
player.Play();
}
public override async Task AfterCommentAdded()
{
await Task.Yield();
try
{
if (IsStamp)
{
if (_siteOptions.IsPlayStampMusic && !string.IsNullOrEmpty(_siteOptions.StampMusicFilePath))
{
PlaySound(_siteOptions.StampMusicFilePath);
}
}
if (IsYell)
{
if (_siteOptions.IsPlayYellMusic && !string.IsNullOrEmpty(_siteOptions.YellMusicFilePath))
{
PlaySound(_siteOptions.YellMusicFilePath);
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
}