Skip to content

Commit 1a20d0d

Browse files
committed
YouTubeLiveのメンバー マイルストーン チャットに対応
1 parent 69cbeb4 commit 1a20d0d

File tree

5 files changed

+57
-48
lines changed

5 files changed

+57
-48
lines changed

MultiCommentViewer/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
[assembly: InternalsVisibleTo("MultiCommentViewerTests")]
55

6-
[assembly: AssemblyVersion("0.6.11")]
6+
[assembly: AssemblyVersion("0.6.12")]

MultiCommentViewer/ViewModels/CommentViewModel/McvYouTubeLiveCommentViewModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ public McvYouTubeLiveCommentViewModel(YouTubeLiveSitePlugin.IYouTubeLiveMembersh
144144
_message = comment;
145145

146146
_nameItems = comment.NameItems;
147-
MessageItems = comment.CommentItems;
147+
var messageItems = new List<IMessagePart>();
148+
messageItems.AddRange(comment.HeaderPrimaryTextItems);
149+
messageItems.AddRange(comment.HeaderSubTextItems);
150+
messageItems.AddRange(comment.CommentItems);
151+
MessageItems = messageItems;
148152
Thumbnail = comment.UserIcon;
149153
Id = comment.Id.ToString();
150154
PostTime = comment.PostedAt.ToString("HH:mm:ss");

YouTubeLiveIF/Message.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public interface IYouTubeLiveMembership : IYouTubeLiveMessage
5050
{
5151
IEnumerable<IMessagePart> NameItems { get; }
5252
IEnumerable<IMessagePart> CommentItems { get; }
53+
IEnumerable<IMessagePart> HeaderPrimaryTextItems { get; }
54+
IEnumerable<IMessagePart> HeaderSubTextItems { get; }
5355
IMessageImage UserIcon { get; }
5456
DateTime PostedAt { get; }
5557
string Id { get; }

YouTubeLiveSitePlugin/Message.cs

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ internal class YouTubeLiveMembership : MessageBase2, IYouTubeLiveMembership
3535
public string Id { get; set; }
3636
public IEnumerable<IMessagePart> NameItems { get; set; }
3737
public IEnumerable<IMessagePart> CommentItems { get; set; }
38+
public IEnumerable<IMessagePart> HeaderPrimaryTextItems { get; set; }
39+
public IEnumerable<IMessagePart> HeaderSubTextItems { get; set; }
3840
//public string UserName { get; set; }
3941
public string UserId { get; set; }
4042
public DateTime PostedAt { get; set; }
@@ -53,19 +55,15 @@ internal class YouTubeLiveMembership : MessageBase2, IYouTubeLiveMembership
5355
// };
5456
// PostedAt = SitePluginCommon.Utils.UnixtimeToDateTime(comment.TimestampUsec / (1000 * 1000));
5557
//}
56-
public YouTubeLiveMembership(MemberShip member) : base("")
58+
public YouTubeLiveMembership(MemberShip text) : base("")
5759
{
58-
//UserId = member.UserId;
59-
//Id = member.Id;
60-
//CommentItems = member.MessageItems;
61-
//NameItems = member.NameItems;
62-
//UserIcon = new Common.MessageImage
63-
//{
64-
// Height = member.ThumbnailHeight,
65-
// Width = member.ThumbnailWidth,
66-
// Url = member.ThumbnailUrl,
67-
//};
68-
//PostedAt = SitePluginCommon.Utils.UnixtimeToDateTime(member.TimestampUsec / (1000 * 1000));
60+
UserId = text.AuthorExternalChannelId;
61+
Id = text.Id;
62+
CommentItems = MessageBase.Convert(text.MessageItems);
63+
NameItems = MessageBase.Convert(text.AuthorName, text.AuthorBadges);
64+
UserIcon = MessageBase.Convert(text.AuthorPhoto);
65+
PostedAt = MessageBase.Convert(text.TimestampUsec);
66+
6967
}
7068
}
7169
internal class YouTubeLiveSuperchat : MessageBase2, IYouTubeLiveSuperchat
@@ -83,26 +81,12 @@ internal class YouTubeLiveSuperchat : MessageBase2, IYouTubeLiveSuperchat
8381

8482
public YouTubeLiveSuperchat(SuperChat text) : base("")
8583
{
86-
UserId = text.AuthorExternalChannelId;//.UserId;
84+
UserId = text.AuthorExternalChannelId;
8785
Id = text.Id;
88-
CommentItems = text.MessageItems.Select(a => MessageConverter.Parse(a)).ToList();
89-
var nameItems = new List<IMessagePart>();
90-
if (text.AuthorName != null)
91-
{
92-
nameItems.Add(Common.MessagePartFactory.CreateMessageText(text.AuthorName));
93-
}
94-
foreach (var badge in text.AuthorBadges)
95-
{
96-
97-
}
98-
NameItems = nameItems;
99-
UserIcon = new Common.MessageImage
100-
{
101-
Height = text.AuthorPhoto.Height,
102-
Width = text.AuthorPhoto.Width,
103-
Url = text.AuthorPhoto.Url,
104-
};
105-
PostedAt = SitePluginCommon.Utils.UnixtimeToDateTime(text.TimestampUsec / (1000 * 1000));
86+
CommentItems = MessageBase.Convert(text.MessageItems);
87+
NameItems = MessageBase.Convert(text.AuthorName, text.AuthorBadges);
88+
UserIcon = MessageBase.Convert(text.AuthorPhoto);
89+
PostedAt = MessageBase.Convert(text.TimestampUsec);
10690
PurchaseAmount = text.PurchaseAmount;
10791
}
10892
}
@@ -121,32 +105,51 @@ internal class YouTubeLiveComment : MessageBase2, IYouTubeLiveComment
121105

122106
public YouTubeLiveComment(TextMessage text) : base("")
123107
{
124-
UserId = text.AuthorExternalChannelId;//.UserId;
108+
UserId = text.AuthorExternalChannelId;
125109
Id = text.Id;
126-
CommentItems = text.MessageItems.Select(a => MessageConverter.Parse(a)).ToList();
110+
CommentItems = MessageBase.Convert(text.MessageItems);
111+
NameItems = MessageBase.Convert(text.AuthorName, text.AuthorBadges);
112+
UserIcon = MessageBase.Convert(text.AuthorPhoto);
113+
PostedAt = MessageBase.Convert(text.TimestampUsec);
114+
}
115+
116+
}
117+
static class MessageBase
118+
{
119+
public static DateTime Convert(long timestampUsec)
120+
{
121+
return SitePluginCommon.Utils.UnixtimeToDateTime(timestampUsec / (1000 * 1000));
122+
}
123+
public static IMessageImage Convert(Thumbnail2 authorPhoto)
124+
{
125+
return new Common.MessageImage
126+
{
127+
Height = authorPhoto.Height,
128+
Width = authorPhoto.Width,
129+
Url = authorPhoto.Url,
130+
};
131+
}
132+
public static IEnumerable<IMessagePart> Convert(IReadOnlyList<ryu_s.YouTubeLive.Message.IMessagePart> items)
133+
{
134+
return items.Select(a => MessageConverter.Parse(a)).ToList();
135+
}
136+
public static IEnumerable<IMessagePart> Convert(string? authorName, List<IAuthorBadge> authorBadges)
137+
{
127138
var nameItems = new List<IMessagePart>();
128-
if (text.AuthorName != null)
139+
if (authorName != null)
129140
{
130-
nameItems.Add(Common.MessagePartFactory.CreateMessageText(text.AuthorName));
141+
nameItems.Add(Common.MessagePartFactory.CreateMessageText(authorName));
131142
}
132143
var badges = new List<IMessagePart>();
133-
foreach (var badge in text.AuthorBadges)
144+
foreach (var badge in authorBadges)
134145
{
135146
var parsed = MessageConverter.Parse(badge);
136147
if (parsed == null) continue;
137148
badges.Add(parsed);
138149
}
139150
nameItems.AddRange(badges);
140-
NameItems = nameItems;
141-
UserIcon = new Common.MessageImage
142-
{
143-
Height = text.AuthorPhoto.Height,
144-
Width = text.AuthorPhoto.Width,
145-
Url = text.AuthorPhoto.Url,
146-
};
147-
PostedAt = SitePluginCommon.Utils.UnixtimeToDateTime(text.TimestampUsec / (1000 * 1000));
151+
return nameItems;
148152
}
149-
150153
}
151154
static class MessageConverter
152155
{

0 commit comments

Comments
 (0)