Example #1
0
 private void ProcessAttachmentsIntoFeedItem(WallPost wallPost, FeedItem feedItem, string secContentTitle = null, string secContentMessage = null, string photosMode = "PhotosByIds")
 {
     if (secContentTitle == null && secContentMessage == null)
     {
         secContentTitle   = SocialDataManager.FormatSecondaryContentTitle(wallPost.attachments, wallPost.geo);
         secContentMessage = SocialDataManager.FormatSecondaryContentMessage(wallPost.attachments, wallPost.geo);
     }
     if (wallPost.attachments != null)
     {
         List <Photo> list = wallPost.attachments.Where <Attachment>((Func <Attachment, bool>)(a => a.photo != null)).Select <Attachment, Photo>((Func <Attachment, Photo>)(a => a.photo)).ToList <Photo>();
         string       str1 = CacheManager.TrySerializeToString((IBinarySerializable) new PhotosList()
         {
             Photos = list
         }).ForURL();
         foreach (Attachment attachment in wallPost.attachments)
         {
             if (attachment.photo != null)
             {
                 FeedMediaThumbnail feedMediaThumbnail = new FeedMediaThumbnail();
                 feedMediaThumbnail.ImageUrl = attachment.photo.src_big;
                 string str2 = string.Format("/default?Action=ShowPhotos&ViewerMode={0}&PhotosCount={1}&SelectedPhotoIndex={2}&Photos={3}&HideLayout=True", (object)photosMode, (object)list.Count, (object)((ICollection <FeedMediaThumbnail>)feedItem.Thumbnails).Count, (object)str1);
                 feedMediaThumbnail.Target = str2;
                 if (((ICollection <FeedMediaThumbnail>)feedItem.Thumbnails).Count < 3)
                 {
                     ((ICollection <FeedMediaThumbnail>)feedItem.Thumbnails).Add(feedMediaThumbnail);
                 }
             }
             if (attachment.link != null)
             {
                 FeedItemSharedStory sharedStoryFromLink = SocialDataManager.TryCreateSharedStoryFromLink(feedItem.Timestamp, attachment.link);
                 if (sharedStoryFromLink != null)
                 {
                     feedItem.SharedStory = sharedStoryFromLink;
                 }
             }
             if (attachment.Page != null)
             {
                 FeedItemSharedStory sharedStoryFromPage = this.TryCreateSharedStoryFromPage(feedItem.Timestamp, attachment.Page);
                 if (sharedStoryFromPage != null)
                 {
                     feedItem.SharedStory = sharedStoryFromPage;
                 }
             }
         }
     }
     if (string.IsNullOrEmpty(secContentTitle) || string.IsNullOrEmpty(secContentMessage))
     {
         return;
     }
     feedItem.SecondaryContent.Title   = secContentTitle;
     feedItem.SecondaryContent.Message = secContentMessage;
 }
Example #2
0
 private static string FormatVideoStr(VKClient.Common.Backend.DataObjects.Video video)
 {
     return(video.title + ", " + SocialDataManager.FormatDuration(video.duration));
 }
Example #3
0
 private static string FormatDocStr(Doc doc)
 {
     return(doc.title + ", " + SocialDataManager.FormatSize((double)doc.size));
 }
Example #4
0
        public static string FormatSecondaryContentMessage(List <Attachment> attachments, Geo geo)
        {
            if (attachments == null)
            {
                attachments = new List <Attachment>();
            }
            bool              flag  = SocialDataManager.AreAllMultiAttachmentsOfOneType(attachments, geo);
            string            str1  = "";
            string            str2  = "";
            List <Attachment> list1 = attachments.Where <Attachment>((Func <Attachment, bool>)(a => a.video != null)).ToList <Attachment>();

            if (list1.Count > 0)
            {
                if (!flag)
                {
                    str2 = str2 + SocialDataManager.FormatSecondaryContentTitle(attachments, null) + Environment.NewLine;
                }
                foreach (Attachment attachment in list1)
                {
                    str2 = str2 + SocialDataManager.FormatVideoStr(attachment.video) + Environment.NewLine;
                }
            }
            if (str2 != "")
            {
                str1 = str1 + str2 + Environment.NewLine;
            }
            List <Attachment> list2 = attachments.Where <Attachment>((Func <Attachment, bool>)(a => a.audio != null)).ToList <Attachment>();
            string            str3  = "";

            if (list2.Count > 0)
            {
                if (!flag)
                {
                    str3 = SocialDataManager.FormatSecondaryContentTitle(attachments, null) + Environment.NewLine;
                }
                foreach (Attachment attachment in list2)
                {
                    str3 = str3 + SocialDataManager.FormatAudioStr(attachment.audio) + Environment.NewLine;
                }
            }
            if (str3 != "")
            {
                str1 = str1 + str3 + Environment.NewLine;
            }
            List <Attachment> list3 = attachments.Where <Attachment>((Func <Attachment, bool>)(a => a.doc != null)).ToList <Attachment>();
            string            str4  = "";

            if (list3.Count > 0)
            {
                if (!flag)
                {
                    str4 = SocialDataManager.FormatSecondaryContentTitle(attachments, null) + Environment.NewLine;
                }
                foreach (Attachment attachment in list3)
                {
                    str4 = str4 + SocialDataManager.FormatDocStr(attachment.doc) + Environment.NewLine;
                }
            }
            if (str4 != "")
            {
                str1 += str4;
            }
            List <Attachment> list4 = attachments.Where <Attachment>((Func <Attachment, bool>)(a => a.poll != null)).ToList <Attachment>();
            string            str5  = "";

            if (list4.Count > 0)
            {
                if (!flag)
                {
                    str5 = BaseResources.Poll + Environment.NewLine;
                }
                str5 = str5 + list4[0].poll.question + Environment.NewLine;
            }
            if (str5 != "")
            {
                str1 = str1 + str5 + Environment.NewLine;
            }
            List <Attachment> list5 = attachments.Where <Attachment>((Func <Attachment, bool>)(a => a.note != null)).ToList <Attachment>();
            string            str6  = "";

            if (list5.Count > 0)
            {
                if (!flag)
                {
                    str6 = SocialDataManager.FormatSecondaryContentTitle(attachments, null) + Environment.NewLine;
                }
                foreach (Attachment attachment in list5)
                {
                    str6 = str6 + SocialDataManager.FormatNoteStr(attachment.note) + Environment.NewLine;
                }
            }
            if (str6 != "")
            {
                str1 = str1 + str6 + Environment.NewLine;
            }
            return(str1);
        }
Example #5
0
        public static string FormatSecondaryContentTitle(List <Attachment> attachments, Geo geo)
        {
            if (attachments == null)
            {
                attachments = new List <Attachment>();
            }
            attachments = attachments.Where <Attachment>((Func <Attachment, bool>)(a =>
            {
                if (a.photo == null && a.link == null)
                {
                    return(a.Page == null);
                }
                return(false);
            })).ToList <Attachment>();
            int count = attachments.Count;

            if (geo != null)
            {
                ++count;
            }
            if (count == 0)
            {
                return("");
            }
            if (count == 1)
            {
                if (geo != null)
                {
                    return(BaseResources.Location);
                }
                Attachment attachment = attachments[0];
                if (attachment.video != null)
                {
                    return(BaseResources.Video);
                }
                if (attachment.audio != null)
                {
                    return(BaseResources.Audio);
                }
                if (attachment.doc != null)
                {
                    return(BaseResources.Document);
                }
                if (attachment.note != null)
                {
                    return(BaseResources.Note);
                }
                if (attachment.poll != null)
                {
                    return(BaseResources.Poll);
                }
            }
            if (count > 1)
            {
                if (!SocialDataManager.AreAllMultiAttachmentsOfOneType(attachments, geo))
                {
                    return(BaseResources.Attachments);
                }
                List <Attachment>       source1    = attachments;
                Func <Attachment, bool> predicate1 = (Func <Attachment, bool>)(a => a.video != null);
                if (source1.Where <Attachment>(predicate1).Count <Attachment>() > 0)
                {
                    return(BaseResources.Videos);
                }
                List <Attachment>       source2    = attachments;
                Func <Attachment, bool> predicate2 = (Func <Attachment, bool>)(a => a.audio != null);
                if (source2.Where <Attachment>(predicate2).Count <Attachment>() > 0)
                {
                    return(BaseResources.Audios);
                }
                List <Attachment>       source3    = attachments;
                Func <Attachment, bool> predicate3 = (Func <Attachment, bool>)(a => a.doc != null);
                if (source3.Where <Attachment>(predicate3).Count <Attachment>() > 0)
                {
                    return(BaseResources.Documents);
                }
                List <Attachment>       source4    = attachments;
                Func <Attachment, bool> predicate4 = (Func <Attachment, bool>)(a => a.note != null);
                if (source4.Where <Attachment>(predicate4).Count <Attachment>() > 0)
                {
                    return(BaseResources.Notes);
                }
                List <Attachment>       source5    = attachments;
                Func <Attachment, bool> predicate5 = (Func <Attachment, bool>)(a => a.poll != null);
                if (source5.Where <Attachment>(predicate5).Count <Attachment>() > 0)
                {
                    return(BaseResources.Poll);
                }
            }
            return("");
        }
Example #6
0
        private FeedItem CreateFeedItem(WallPost wallPost, List <Group> groups, List <User> profiles, bool allowFocusComments = true)
        {
            FeedItem feedItem = new FeedItem();
            string   format   = "/default?Action=WallPost&PostId={0}&OwnerId={1}&FocusComments={2}&PollId={3}&PollOwnerId={4}&HideLayout=True";
            long     num1     = 0;
            long     num2     = 0;

            if (wallPost.attachments != null)
            {
                Attachment attachment = wallPost.attachments.FirstOrDefault <Attachment>((Func <Attachment, bool>)(a => a.poll != null));
                if (attachment != null)
                {
                    num1 = attachment.poll.poll_id;
                    num2 = wallPost.IsRepost() ? wallPost.copy_history[0].owner_id : wallPost.to_id;
                }
            }
            feedItem.DefaultTarget = string.Format(format, (object)wallPost.id, (object)wallPost.to_id, allowFocusComments, (object)num1, (object)num2);
            string str1 = string.Format(format, (object)wallPost.id, (object)wallPost.to_id, false, num1, (object)num2);

            feedItem.PrimaryContent.Target   = str1;
            feedItem.SecondaryContent.Target = str1;
            feedItem.Author.DisplayName      = wallPost.GetAuthorDisplayName(groups, profiles);
            Actor  author1         = feedItem.Author;
            long   num3            = wallPost.from_id;
            string uniqueRemoteId1 = RemoteIdHelper.GenerateUniqueRemoteId(num3.ToString(), RemoteIdHelper.RemoteIdItemType.UserOrGroup);

            author1.RemoteId              = uniqueRemoteId1;
            feedItem.ReactionDisplayKind  = (ReactionDisplayKind)2;
            feedItem.ReactionDisplayCount = wallPost.comments == null ? 0 : wallPost.comments.count;
            feedItem.Timestamp            = new DateTimeOffset(ExtensionsBase.UnixTimeStampToDateTime((double)wallPost.date, true));
            feedItem.Style    = FeedItemStyle.Photo;
            feedItem.RemoteId = RemoteIdHelper.GenerateUniqueRemoteId(wallPost.GloballyUniqueId, RemoteIdHelper.RemoteIdItemType.WallPost);
            string secContentTitle   = SocialDataManager.FormatSecondaryContentTitle(wallPost.attachments, wallPost.geo);
            string secContentMessage = SocialDataManager.FormatSecondaryContentMessage(wallPost.attachments, wallPost.geo);

            if (wallPost.IsRepost())
            {
                string str2 = string.Format(format, (object)wallPost.copy_history[0].WallPostOrReplyPostId, (object)wallPost.copy_history[0].owner_id, (object)false, (object)num1, (object)num2);
                if (!string.IsNullOrEmpty(wallPost.text))
                {
                    feedItem.PrimaryContent.Message = TextPreprocessor.PreprocessText(wallPost.text);
                }
                else
                {
                    feedItem.PrimaryContent.Title = wallPost.GetIsMale(profiles) ? BaseResources.SharedPostMale : BaseResources.SharedPostFemale;
                }
                feedItem.ChildItem = new FeedChildItem();
                feedItem.ChildItem.PrimaryContent.Target   = str2;
                feedItem.ChildItem.SecondaryContent.Target = str2;
                bool isMale = false;
                if (wallPost.IsProfilePhotoUpdatePost(profiles, out isMale))
                {
                    feedItem.ChildItem.PrimaryContent.Title = isMale ? BaseResources.Photo_UpdatedProfileMale : BaseResources.Photo_UpdatedProfileFemale;
                }
                feedItem.ChildItem.Timestamp          = feedItem.Timestamp;
                feedItem.ChildItem.Author.DisplayName = wallPost.GetChildAuthorDisplayName(groups, profiles);
                Actor author2 = feedItem.ChildItem.Author;
                num3 = wallPost.GetChildItemFromId();
                string uniqueRemoteId2 = RemoteIdHelper.GenerateUniqueRemoteId(num3.ToString(), RemoteIdHelper.RemoteIdItemType.UserOrGroup);
                author2.RemoteId = uniqueRemoteId2;
                feedItem.ChildItem.DefaultTarget = str2;
                if (!string.IsNullOrWhiteSpace(wallPost.copy_history[0].text))
                {
                    feedItem.ChildItem.PrimaryContent.Message = TextPreprocessor.PreprocessText(wallPost.copy_history[0].text);
                }
                if (wallPost.copy_history[0].attachments != null)
                {
                    List <Attachment> attachments = wallPost.copy_history[0].attachments;
                    List <Photo>      list        = attachments.Where <Attachment>((Func <Attachment, bool>)(a => a.photo != null)).Select <Attachment, Photo>((Func <Attachment, Photo>)(a => a.photo)).ToList <Photo>();
                    string            str3        = CacheManager.TrySerializeToString((IBinarySerializable) new PhotosList()
                    {
                        Photos = list
                    }).ForURL();
                    foreach (Attachment attachment in attachments)
                    {
                        if (attachment.photo != null)
                        {
                            FeedMediaThumbnail feedMediaThumbnail = new FeedMediaThumbnail();
                            feedMediaThumbnail.ImageUrl = attachment.photo.src_big;
                            string str4 = string.Format("/default?Action=ShowPhotos&ViewerMode={0}&PhotosCount={1}&SelectedPhotoIndex={2}&Photos={3}&HideLayout=True", "PhotosByIds", list.Count, ((ICollection <FeedMediaThumbnail>)feedItem.ChildItem.Thumbnails).Count, str3);
                            feedMediaThumbnail.Target = str4;
                            if (((ICollection <FeedMediaThumbnail>)feedItem.ChildItem.Thumbnails).Count < 3)
                            {
                                ((ICollection <FeedMediaThumbnail>)feedItem.ChildItem.Thumbnails).Add(feedMediaThumbnail);
                            }
                        }
                        if (attachment.link != null)
                        {
                            FeedItemSharedStory sharedStoryFromLink = SocialDataManager.TryCreateSharedStoryFromLink(feedItem.Timestamp, attachment.link);
                            if (sharedStoryFromLink != null)
                            {
                                feedItem.ChildItem.SharedStory = sharedStoryFromLink;
                            }
                        }
                        if (attachment.Page != null)
                        {
                            FeedItemSharedStory sharedStoryFromPage = this.TryCreateSharedStoryFromPage(feedItem.Timestamp, attachment.Page);
                            if (sharedStoryFromPage != null)
                            {
                                feedItem.ChildItem.SharedStory = sharedStoryFromPage;
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(secContentTitle) && !string.IsNullOrEmpty(secContentMessage))
                {
                    feedItem.ChildItem.SecondaryContent.Title   = secContentTitle;
                    feedItem.ChildItem.SecondaryContent.Message = secContentMessage;
                }
                if (string.IsNullOrEmpty(feedItem.ChildItem.PrimaryContent.Message) && string.IsNullOrEmpty(feedItem.ChildItem.SecondaryContent.Title) && string.IsNullOrEmpty(feedItem.ChildItem.SecondaryContent.Message))
                {
                    string titleIfNecessary = this.GenerateTitleIfNecessary(wallPost.copy_history[0]);
                    if (!string.IsNullOrEmpty(titleIfNecessary))
                    {
                        feedItem.ChildItem.PrimaryContent.Title = titleIfNecessary;
                    }
                    else
                    {
                        Debugger.Break();
                        feedItem = null;
                    }
                }
            }
            else
            {
                bool isMale = false;
                if (wallPost.text != string.Empty)
                {
                    feedItem.PrimaryContent.Message = TextPreprocessor.PreprocessText(wallPost.text);
                }
                this.ProcessAttachmentsIntoFeedItem(wallPost, feedItem, secContentTitle, secContentMessage, "PhotosByIds");
                if (wallPost.IsProfilePhotoUpdatePost(profiles, out isMale))
                {
                    feedItem.PrimaryContent.Title = isMale ? BaseResources.Photo_UpdatedProfileMale : BaseResources.Photo_UpdatedProfileFemale;
                }
                if (string.IsNullOrEmpty(feedItem.PrimaryContent.Title) && string.IsNullOrEmpty(feedItem.PrimaryContent.Message) && (string.IsNullOrEmpty(feedItem.SecondaryContent.Title) && string.IsNullOrEmpty(feedItem.SecondaryContent.Message)))
                {
                    string titleIfNecessary = this.GenerateTitleIfNecessary(wallPost);
                    if (!string.IsNullOrEmpty(titleIfNecessary))
                    {
                        feedItem.PrimaryContent.Title = titleIfNecessary;
                    }
                    else
                    {
                        Debugger.Break();
                        feedItem = null;
                    }
                }
                if (wallPost.from_id != wallPost.to_id && feedItem != null)
                {
                    feedItem.PrimaryContent.Title = wallPost.GetFromToString(groups, profiles);
                }
            }
            return(feedItem);
        }