Exemplo n.º 1
0
        public MessagesQueryResult MapSingle(VkNewsFeed feed, HashTagWord hashtag)
        {
            var results = new MessagesQueryResult();

            // vk doesn't return list of all hashtags in message
            // todo: consider parsing message for hashtags. But it might be too memory consuming operation.

            foreach (var post in feed.Feed)
            {
                var date = DateTimeOffset.FromUnixTimeSeconds(post.UnixTimeStamp).UtcDateTime;
                var user = FillUser(post, feed);
                //var message =
                //  new MessageQueryResult(0,
                //      post.Text,
                //      new List<HashTagQueryResult>
                //      {
                //          new HashTagQueryResult
                //          {
                //              HashTag = hashtag
                //          }
                //      },
                //      SocialMediaType.VK,
                //      date,
                //      post.Id.ToString(),
                //      user);
                //results.Messages.Add(message);
            }
            return(results);
        }
Exemplo n.º 2
0
        public List <CreateMessageCommand> MapBunch(VkNewsFeed feed)
        {
            var results = new List <CreateMessageCommand>();

            // vk doesn't return list of all hashtags in message
            // todo: consider parsing message for hashtags. But it might be too memory consuming operation.

            foreach (var post in feed.Feed)
            {
                var date = DateTimeOffset.FromUnixTimeSeconds(post.UnixTimeStamp).UtcDateTime;
                var user = FillUser(post, feed);

                var message = new CreateMessageCommand
                {
                    MessageText = post.Text,
                    HashTags    = ParseHashtags(post.Text).Select(x => new HashtagModel
                    {
                        HashTag   = new HashTagWord(x),
                        IsEnabled = false
                    }).ToList(),
                    MediaType = SocialMediaType.VK,
                    PostDate  = date,
                    NetworkId = post.Id.ToString(),
                    User      = user
                };
                results.Add(message);
            }
            return(results);
        }
Exemplo n.º 3
0
        private UserQueryResult FillUser(VkNewsSearchResult post, VkNewsFeed feed)
        {
            var id   = post.FromId;
            var user = new UserQueryResult();

            if (id > 0)
            {
                var profile = feed.Profiles.FirstOrDefault(x => x.Id == id);
                user.NetworkId   = id.ToString();
                user.UserName    = $"{profile.FirstName} {profile.LastName}";
                user.ProfileId   = profile.UserName;
                user.AvatarUrl50 = profile.PhotoLink50;
            }
            else
            {
                var vkGroup = feed.Groups.FirstOrDefault(x => x.Id == Math.Abs(id));
                user.NetworkId   = id.ToString();
                user.UserName    = $"{vkGroup.FirstName}";
                user.ProfileId   = vkGroup.UserName;
                user.AvatarUrl50 = vkGroup.PhotoLink50;
            }
            return(user);
        }