public YouTubeLiveMessageMetadata(IYouTubeLiveMessage message, ICommentOptions options, IYouTubeLiveSiteOptions siteOptions, IUser user, ICommentProvider cp, bool isFirstComment) { _options = options; _siteOptions = siteOptions; User = user; CommentProvider = cp; _isFirstComment = isFirstComment; options.PropertyChanged += Options_PropertyChanged; }
//private YouTubeLiveMessageContext CreateMessageContext2(InternalMembership comment, bool isInitialComment) //{ // IYouTubeLiveMessage message; // IEnumerable<IMessagePart> commentItems; // IEnumerable<IMessagePart> nameItems; // var a = new YouTubeLiveMembership(comment); // message = a; // nameItems = a.NameItems; // commentItems = a.CommentItems; // var metadata = CreateMetadata(message, isInitialComment); // var methods = new YouTubeLiveMessageMethods(); // if (_siteOptions.IsAutoSetNickname) // { // var user = metadata.User; // var messageText = Common.MessagePartsTools.ToText(commentItems); // var nick = SitePluginCommon.Utils.ExtractNickname(messageText); // if (!string.IsNullOrEmpty(nick)) // { // user.Nickname = nick; // } // } // metadata.User.Name = nameItems; // return new YouTubeLiveMessageContext(message, metadata, methods); //} //private YouTubeLiveMessageContext CreateMessageContext2(InternalSuperChat superChat, bool isInitialComment) //{ // IYouTubeLiveMessage message; // IEnumerable<IMessagePart> commentItems; // IEnumerable<IMessagePart> nameItems; // var a = new YouTubeLiveSuperchat(superChat); // message = a; // nameItems = a.NameItems; // commentItems = a.CommentItems; // var metadata = CreateMetadata(message, isInitialComment); // var methods = new YouTubeLiveMessageMethods(); // if (_siteOptions.IsAutoSetNickname) // { // var user = metadata.User; // var messageText = Common.MessagePartsTools.ToText(commentItems); // var nick = SitePluginCommon.Utils.ExtractNickname(messageText); // if (!string.IsNullOrEmpty(nick)) // { // user.Nickname = nick; // } // } // metadata.User.Name = nameItems; // return new YouTubeLiveMessageContext(message, metadata, methods); //} //private YouTubeLiveMessageContext CreateMessageContext2(InternalComment comment, bool isInitialComment) //{ // IYouTubeLiveMessage message; // IEnumerable<IMessagePart> commentItems; // IEnumerable<IMessagePart> nameItems; // var a = new YouTubeLiveComment(comment); // message = a; // nameItems = a.NameItems; // commentItems = a.CommentItems; // var metadata = CreateMetadata(message, isInitialComment); // var methods = new YouTubeLiveMessageMethods(); // if (_siteOptions.IsAutoSetNickname) // { // var user = metadata.User; // var messageText = Common.MessagePartsTools.ToText(commentItems); // var nick = SitePluginCommon.Utils.ExtractNickname(messageText); // if (!string.IsNullOrEmpty(nick)) // { // user.Nickname = nick; // } // } // metadata.User.Name = nameItems; // return new YouTubeLiveMessageContext(message, metadata, methods); //} //private YouTubeLiveMessageContext CreateMessageContext(CommentData commentData, bool isInitialComment) //{ // IYouTubeLiveMessage message; // IEnumerable<IMessagePart> commentItems; // IEnumerable<IMessagePart> nameItems; // if (commentData.IsPaidMessage) // { // var superchat = new YouTubeLiveSuperchat(commentData); // message = superchat; // nameItems = superchat.NameItems; // commentItems = superchat.CommentItems; // } // else // { // var comment = new YouTubeLiveComment(commentData); // message = comment; // nameItems = comment.NameItems; // commentItems = comment.CommentItems; // } // var metadata = CreateMetadata(message, isInitialComment); // var methods = new YouTubeLiveMessageMethods(); // if (_siteOptions.IsAutoSetNickname) // { // var user = metadata.User; // var messageText = Common.MessagePartsTools.ToText(commentItems); // var nick = SitePluginCommon.Utils.ExtractNickname(messageText); // if (!string.IsNullOrEmpty(nick)) // { // user.Nickname = nick; // } // } // metadata.User.Name = nameItems; // return new YouTubeLiveMessageContext(message, metadata, methods); //} private YouTubeLiveMessageMetadata CreateMetadata(IYouTubeLiveMessage message, bool isInitialComment) { string userId = null; if (message is IYouTubeLiveComment comment) { userId = comment.UserId; } else if (message is IYouTubeLiveSuperchat superchat) { userId = superchat.UserId; } else if (message is IYouTubeLiveMembership membership) { userId = membership.UserId; } bool isFirstComment; IUser user; if (userId != null) { if (_userCommentCountDict.ContainsKey(userId)) { _userCommentCountDict[userId]++; isFirstComment = false; } else { _userCommentCountDict.Add(userId, 1); isFirstComment = true; } user = GetUser(userId); } else { isFirstComment = false; user = null; } var metadata = new YouTubeLiveMessageMetadata(message, _options, _siteOptions, user, this, isFirstComment) { IsInitialComment = isInitialComment, SiteContextGuid = SiteContextGuid, }; return(metadata); }
public YouTubeLiveMessageContext(IYouTubeLiveMessage message, YouTubeLiveMessageMetadata metadata, IMessageMethods methods) { Message = message; Metadata = metadata; Methods = methods; }