예제 #1
0
        private FeedItem CreatePhotoPhotoTagItem(NewsItem newsFeedItem, List <Group> groups, List <User> profiles)
        {
            FeedItem feedItem     = new FeedItem();
            WallPost fromNewsItem = WallPost.CreateFromNewsItem(newsFeedItem);

            feedItem.DefaultTarget       = "/default";
            feedItem.Author.DisplayName  = fromNewsItem.GetAuthorDisplayName(groups, profiles);
            feedItem.Author.RemoteId     = RemoteIdHelper.GenerateUniqueRemoteId(fromNewsItem.from_id.ToString(), RemoteIdHelper.RemoteIdItemType.UserOrGroup);
            feedItem.Author.Username     = feedItem.Author.DisplayName;
            feedItem.ReactionDisplayKind = (ReactionDisplayKind)0;
            feedItem.Timestamp           = new DateTimeOffset(ExtensionsBase.UnixTimeStampToDateTime((double)fromNewsItem.date, true));
            feedItem.Style    = (FeedItemStyle)1;
            feedItem.RemoteId = RemoteIdHelper.GenerateUniqueRemoteId(fromNewsItem.GloballyUniqueId, RemoteIdHelper.RemoteIdItemType.WallPost);
            string photoTagFeedText = this.GetPhotoPhotoTagFeedText(newsFeedItem, groups, profiles);

            if (string.IsNullOrEmpty(photoTagFeedText))
            {
                return(null);
            }
            feedItem.PrimaryContent.Title = photoTagFeedText;
            string photosMode = "Photos";

            if (newsFeedItem.Photo_tags != null && newsFeedItem.Photo_tags.Count > 0)
            {
                photosMode = "PhotoTags";
            }
            this.ProcessAttachmentsIntoFeedItem(fromNewsItem, feedItem, null, null, photosMode);
            if (((ICollection <FeedMediaThumbnail>)feedItem.Thumbnails).Count > 0)
            {
                feedItem.DefaultTarget = feedItem.Thumbnails[0].Target;
            }
            return(feedItem);
        }
예제 #2
0
        public async Task MarkFeedAsStale(long ownerId)
        {
            if (ownerId == 0L)
            {
                ownerId = AppGlobalStateManager.Current.LoggedInUserId;
            }
            string remoteId = RemoteIdHelper.GenerateUniqueRemoteId(ownerId.ToString(), RemoteIdHelper.RemoteIdItemType.UserOrGroup);

            try
            {
                await SocialManager.MarkFeedAsStaleAsync(remoteId, FeedType.Contact);
            }
            catch
            {
            }
            try
            {
                await SocialManager.MarkFeedAsStaleAsync(remoteId, FeedType.Dashboard);
            }
            catch
            {
            }
            try
            {
                await SocialManager.MarkFeedAsStaleAsync(remoteId, FeedType.Home);
            }
            catch
            {
            }
        }
예제 #3
0
        private NewsFeedGetParams CreateNewsFeedGetParams(FeedOperationDetails op)
        {
            NewsFeedGetParams newsFeedGetParams = new NewsFeedGetParams();

            //if (op.Direction == null)
            //    Debugger.Break();
            if (!string.IsNullOrEmpty(op.FeedItemRemoteId))
            {
                newsFeedGetParams = RemoteIdHelper.GetNewsFeedGetParamsBy(op.FeedItemRemoteId, op.ItemCount);
            }
            newsFeedGetParams.NewsListId = -10;
            return(newsFeedGetParams);
        }
예제 #4
0
        public async Task UpdateCommentsCount(long toId, long postId, int currentCount)
        {
            string uniqueRemoteId = RemoteIdHelper.GenerateUniqueRemoteId(new WallPost()
            {
                to_id = toId,
                id    = postId
            }.GloballyUniqueId, RemoteIdHelper.RemoteIdItemType.WallPost);

            try
            {
                await SocialManager.UpdateReactionDisplayCountAsync(uniqueRemoteId, currentCount);
            }
            catch
            {
            }
        }
예제 #5
0
        private async Task <bool> ProcessContactFeeds(List <FeedOperationDetails> fodList)
        {
            List <WallService.WallRequestData> requestData = new List <WallService.WallRequestData>();

            using (List <FeedOperationDetails> .Enumerator enumerator = fodList.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    FeedOperationDetails current = enumerator.Current;
                    requestData.Add(new WallService.WallRequestData()
                    {
                        UserId = RemoteIdHelper.GetItemIdByRemoteId(current.OwnerRemoteId),
                        Offset = this.GetRequiredOffset(current),
                        Count  = current.ItemCount
                    });
                }
            }
            BackendResult <List <WallData>, ResultCode> res = await WallService.Current.GetWallForManyUsers(requestData);

            if (res.ResultCode != ResultCode.Succeeded)
            {
                return(false);
            }
            for (int i = 0; i < fodList.Count && i < res.ResultData.Count; ++i)
            {
                FeedOperationDetails fod             = fodList[i];
                WallData             currentWallData = res.ResultData[i];
                int  nextOffset = this.GetRequiredOffset(fod) + currentWallData.wall.Count;
                Feed feed       = await SocialManager.OpenContactFeedAsync(fod);

                foreach (WallPost wallPost in currentWallData.wall)
                {
                    FeedItem feedItem = this.CreateFeedItem(wallPost, currentWallData.groups, currentWallData.profiles, true);
                    if (feedItem != null)
                    {
                        this.SetRequiredOffset(feedItem, nextOffset);
                        ((ICollection <FeedItem>)feed.Items).Add(feedItem);
                    }
                }
                await feed.SaveAsync();

                currentWallData = null;
            }
            return(true);
        }
예제 #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);
        }
예제 #7
0
        private async Task <bool> ProcessSingleDashboardRequest(FeedOperationDetails fod)
        {
            BackendResult <WallData, ResultCode> wall = await WallService.Current.GetWall(RemoteIdHelper.GetItemIdByRemoteId(fod.OwnerRemoteId), 0, 1, "owner");

            if (wall.ResultCode == ResultCode.Succeeded && wall.ResultData.wall.Count > 0)
            {
                WallPost wallPost = wall.ResultData.wall[0];
                FeedItem feedItem = this.CreateFeedItem(wallPost, wall.ResultData.groups, wall.ResultData.profiles, false);
                if (feedItem != null)
                {
                    DashboardItem dashboardItem = await SocialManager.OpenContactDashboardAsync(fod);

                    dashboardItem.DefaultTarget = feedItem.DefaultTarget;
                    dashboardItem.Timestamp     = new DateTimeOffset(ExtensionsBase.UnixTimeStampToDateTime((double)wallPost.date, true));
                    if (!string.IsNullOrEmpty(feedItem.PrimaryContent.Title) || !string.IsNullOrEmpty(feedItem.PrimaryContent.Message))
                    {
                        dashboardItem.Content.Title   = feedItem.PrimaryContent.Title;
                        dashboardItem.Content.Message = feedItem.PrimaryContent.Message;
                    }
                    else
                    {
                        dashboardItem.Content.Title   = feedItem.SecondaryContent.Title;
                        dashboardItem.Content.Message = feedItem.SecondaryContent.Message;
                    }
                    dashboardItem.Content.Target = feedItem.PrimaryContent.Target;
                    await dashboardItem.SaveAsync();

                    return(true);
                }
                wallPost = null;
                feedItem = null;
            }
            return(false);
        }
예제 #8
0
        private async Task <bool> ProcessConnectData(DownloadRichConnectDataOperation downloadRichConnectDataOperation)
        {
            ContactBindingManager store = await ContactBindings.GetAppContactBindingManagerAsync();

            ContactStore contactStore = await ContactStore.CreateOrOpenAsync();

            foreach (string id in (IEnumerable <string>)downloadRichConnectDataOperation.Ids)
            {
                string remoteId = id;
                try
                {
                    string         title          = (await contactStore.FindContactByRemoteIdAsync(remoteId)).DisplayName;
                    ContactBinding contactBinding = await store.GetContactBindingByRemoteIdAsync(remoteId);

                    ConnectTileData connectTileData = new ConnectTileData();
                    connectTileData.Title = title;
                    BackendResult <PhotosListWithCount, ResultCode> profilePhotos = await PhotosService.Current.GetProfilePhotos(RemoteIdHelper.GetItemIdByRemoteId(remoteId), 0, 3);

                    if (profilePhotos.ResultCode == ResultCode.Succeeded)
                    {
                        for (int index = 0; index < Math.Min(3, profilePhotos.ResultData.response.Count); ++index)
                        {
                            Photo            photo            = profilePhotos.ResultData.response[index];
                            ConnectTileImage connectTileImage = new ConnectTileImage();
                            connectTileImage.ImageUrl = photo.src_big;
                            ((ICollection <ConnectTileImage>)connectTileData.Images).Add(connectTileImage);
                        }
                    }
                    contactBinding.TileData = connectTileData;
                    await store.SaveContactBindingAsync(contactBinding);

                    title           = null;
                    contactBinding  = null;
                    connectTileData = null;
                }
                catch (Exception ex)
                {
                    Logger.Instance.Error("ProcessConnectData failed", ex);
                }
                remoteId = null;
            }
            return(true);
        }