private LineLiveMessageContext CreateMessageContext(ParseMessage.IMessage message, ParseMessage.IUser sender, string raw, bool isInitialComment) { LineLiveMessageContext messageContext; if (message is ParseMessage.IMessageData comment) { var user = GetUser(sender.Id.ToString()); var isFirstComment = _first.IsFirstComment(user.UserId); var m = new LineLiveComment(raw) { Text = comment.Message, IsNgMessage = comment.IsNgMessage, PostedAt = SitePluginCommon.Utils.UnixtimeToDateTime(comment.SentAt), UserIconUrl = sender.IconUrl, UserId = sender.Id, DisplayName = sender.DisplayName, }; var metadata = new MessageMetadata(m, _options, _siteOptions, user, this, isFirstComment) { IsInitialComment = isInitialComment, SiteContextGuid = SiteContextGuid, }; var methods = new LineLiveMessageMethods(); messageContext = new LineLiveMessageContext(m, metadata, methods); } else if (message is ParseMessage.ILove love) { var user = GetUser(sender.Id.ToString()); var isFirstComment = _first.IsFirstComment(user.UserId); var str = sender.DisplayName + "さんがハートを送りました!"; var m = new LineLiveItem(raw) { CommentItems = Common.MessagePartFactory.CreateMessageItems(str), PostedAt = SitePluginCommon.Utils.UnixtimeToDateTime(love.SentAt), UserIconUrl = sender.IconUrl, UserId = sender.Id, DisplayName = sender.DisplayName, }; var metadata = new MessageMetadata(m, _options, _siteOptions, user, this, isFirstComment) { IsInitialComment = isInitialComment, SiteContextGuid = SiteContextGuid, }; var methods = new LineLiveMessageMethods(); messageContext = new LineLiveMessageContext(m, metadata, methods); } else if (message is ParseMessage.IFollowStartData follow) { var user = GetUser(sender.Id.ToString()); var isFirstComment = _first.IsFirstComment(user.UserId); var msg = sender.DisplayName + "さんがフォローしました!"; var m = new LineLiveItem(raw) { CommentItems = Common.MessagePartFactory.CreateMessageItems(msg), PostedAt = SitePluginCommon.Utils.UnixtimeToDateTime(follow.FollowedAt), UserIconUrl = sender.IconUrl, UserId = sender.Id, DisplayName = sender.DisplayName, }; var metadata = new MessageMetadata(m, _options, _siteOptions, user, this, isFirstComment) { IsInitialComment = isInitialComment, SiteContextGuid = SiteContextGuid, }; var methods = new LineLiveMessageMethods(); messageContext = new LineLiveMessageContext(m, metadata, methods); } else if (message is ParseMessage.IGiftMessage gift) { var user = GetUser(sender.Id.ToString()); var isFirstComment = _first.IsFirstComment(user.UserId); if (_loveIconUrlDict.ContainsKey(gift.ItemId)) { gift.Url = _loveIconUrlDict[gift.ItemId]; } else { gift.Url = ""; } List <IMessagePart> messageItems; if (gift.ItemId == "limited-love-gift" || string.IsNullOrEmpty(gift.Url)) { //{"type":"giftMessage","data":{"message":"","type":"LOVE","itemId":"limited-love-gift","quantity":1,"displayName":"limited.love.gift.item","sender":{"id":2903515,"hashedId":"715i4MKqyv","displayName":"上杉The Times","iconUrl":"https://scdn.line-apps.com/obs/0hmNs42D-0MmFOTR9H8JtNNnYQNBY3YzEpNmkpRHdEbQI3LnYxIX97UGIdaVdjKXVjd3ktVGNEP1VjenU1ew/f64x64","hashedIconId":"0hmNs42D-0MmFOTR9H8JtNNnYQNBY3YzEpNmkpRHdEbQI3LnYxIX97UGIdaVdjKXVjd3ktVGNEP1VjenU1ew","isGuest":false,"isBlocked":false},"isNGGift":false,"sentAt":1531445716,"key":"2426265.29035150000000000000","blockedByCms":false}} var msg = sender.DisplayName + "さんがハートで応援ポイントを送りました!"; messageItems = new List <IMessagePart> { MessagePartFactory.CreateMessageText(msg) }; } else { var msg = sender.DisplayName + "さんが" + gift.Quantity + "コインプレゼントしました!"; messageItems = new List <IMessagePart> { MessagePartFactory.CreateMessageText(msg), new MessageImage { Url = gift.Url } }; } var m = new LineLiveItem(raw) { CommentItems = messageItems, PostedAt = SitePluginCommon.Utils.UnixtimeToDateTime(gift.SentAt), UserIconUrl = sender.IconUrl, UserId = sender.Id, DisplayName = sender.DisplayName, }; var metadata = new MessageMetadata(m, _options, _siteOptions, user, this, isFirstComment) { IsInitialComment = isInitialComment, SiteContextGuid = SiteContextGuid, }; var methods = new LineLiveMessageMethods(); messageContext = new LineLiveMessageContext(m, metadata, methods); } else { messageContext = null; } return(messageContext); }
//ParseMessage.IMessage _message; // public LineLiveCommentViewModel(ICommentOptions options, ILineLiveSiteOptions siteOptions, ParseMessage.ILove data, ParseMessage.IUser sender, IUser user, ICommentProvider cp) : // base(options, user, cp, false) // { // MessageType = MessageType.BroadcastInfo; // _siteOptions = siteOptions; // _message = data; // CommentProvider = cp; // var msg = sender.DisplayName + "さんがハートを送りました!"; // MessageItems = new List<IMessagePart> { MessagePartFactory.CreateMessageText(msg) }; // Init(); // } // public LineLiveCommentViewModel(ICommentOptions options, ILineLiveSiteOptions siteOptions, ParseMessage.IGiftMessage data, ParseMessage.IUser sender, IUser user, ICommentProvider cp) : //base(options, user, cp, false) // { // MessageType = MessageType.BroadcastInfo; // _siteOptions = siteOptions; // _message = data; // CommentProvider = cp; // //2018/07/13 // if (data.ItemId == "limited-love-gift" || string.IsNullOrEmpty(data.Url)) // { // //{"type":"giftMessage","data":{"message":"","type":"LOVE","itemId":"limited-love-gift","quantity":1,"displayName":"limited.love.gift.item","sender":{"id":2903515,"hashedId":"715i4MKqyv","displayName":"上杉The Times","iconUrl":"https://scdn.line-apps.com/obs/0hmNs42D-0MmFOTR9H8JtNNnYQNBY3YzEpNmkpRHdEbQI3LnYxIX97UGIdaVdjKXVjd3ktVGNEP1VjenU1ew/f64x64","hashedIconId":"0hmNs42D-0MmFOTR9H8JtNNnYQNBY3YzEpNmkpRHdEbQI3LnYxIX97UGIdaVdjKXVjd3ktVGNEP1VjenU1ew","isGuest":false,"isBlocked":false},"isNGGift":false,"sentAt":1531445716,"key":"2426265.29035150000000000000","blockedByCms":false}} // var msg = sender.DisplayName + "さんがハートで応援ポイントを送りました!"; // MessageItems = new List<IMessagePart> { MessagePartFactory.CreateMessageText(msg) }; // } // else // { // var msg = sender.DisplayName + "さんが" + data.Quantity + "コインプレゼントしました!"; // MessageItems = new List<IMessagePart> { MessagePartFactory.CreateMessageText(msg), new MessageImage { Url = data.Url } }; // } // Init(); // } // public LineLiveCommentViewModel(ICommentOptions options, ILineLiveSiteOptions siteOptions, ParseMessage.IFollowStartData data, ParseMessage.IUser sender, IUser user, ICommentProvider cp) : // base(options, user, cp, false) // { // MessageType = MessageType.BroadcastInfo; // _siteOptions = siteOptions; // _message = data; // CommentProvider = cp; // var msg = sender.DisplayName + "さんがフォローしました!"; // MessageItems = new List<IMessagePart> { MessagePartFactory.CreateMessageText(msg) }; // Init(); // } public LineLiveCommentViewModel(ICommentOptions options, ILineLiveSiteOptions siteOptions, ParseMessage.IMessageData data, ParseMessage.IUser sender, IUser user, ICommentProvider cp) : base(options, user, cp, false) { MessageType = MessageType.Comment; _siteOptions = siteOptions; //_message = data; UserId = sender.Id.ToString(); Id = ""; if (siteOptions.IsAutoSetNickname) { var nick = ExtractNickname(data.Message); if (!string.IsNullOrEmpty(nick)) { user.Nickname = nick; } } SetNameItems(); MessageItems = new List <IMessagePart> { MessagePartFactory.CreateMessageText(data.Message) }; Thumbnail = new MessageImage { Url = sender.IconUrl }; PostTime = Tools.FromUnixTime(data.SentAt).ToString("HH:mm:ss"); Init(); NameItemsInternal = new List <IMessagePart> { MessagePartFactory.CreateMessageText(sender.DisplayName) }; User.Name = NameItemsInternal; }