public static async Task<List<PostEntity>> GetConversation(PostEntity startingPost,
            UserAccountEntity userAccountEntity)
        {
            if (userAccountEntity.GetAccessToken().Equals("refresh"))
            {
                await Auth.RefreshAccessToken(userAccountEntity);
            }
            var conversationList = new List<PostEntity>();
            conversationList.Add(startingPost);
            if (startingPost.InReplyToStatusID == 0) return conversationList;
            PostEntity nextEntry =
                await StatusManager.GetPost(false, false, startingPost.InReplyToStatusID, userAccountEntity);
            conversationList.Add(nextEntry);
            while (nextEntry.InReplyToStatusID != 0)
            {
                nextEntry =
                    await StatusManager.GetPost(false, false, nextEntry.InReplyToStatusID, userAccountEntity);
                conversationList.Add(nextEntry);
            }

            return conversationList;
        }
Exemple #2
0
 public PostEntity Clone()
 {
     var entity = new PostEntity
     {
         CreatedAt = CreatedAt,
         CreatedDate = CreatedDate,
         FavoritedCount = FavoritedCount,
         ImageUrl = ImageUrl,
         InReplyToScreenName = InReplyToScreenName,
         InReplyToStatusID = InReplyToStatusID,
         InReplyToUserID = InReplyToUserID,
         IsFavorited = IsFavorited,
         IsSpreaded = IsSpreaded,
         Media = Media,
         ReplyStatus = ReplyStatus,
         SourceName = SourceName,
         SourceUrl = SourceUrl,
         SpreadCount = SpreadCount,
         SpreadStatus = SpreadStatus,
         StatusID = StatusID,
         Post = Post,
         User = User
     };
     return entity;
 }
Exemple #3
0
        public static List<PostEntity> Parse(String json, UserAccountEntity userAccountEntity)
        {
            var entity = new List<PostEntity>();
            JArray a = JArray.Parse(json);
            foreach (var jToken in a)
            {
                var o = (JObject) jToken;
                var post = new PostEntity
                {
                    CreatedAt = FixTime((String) o["created_at"]),
                    FavoritedCount = long.Parse((String) o["favorited_count"]),
                    InReplyToScreenName = (String) o["in_reply_to_screen_name"],
                    InReplyToStatusID =
                        long.Parse(String.IsNullOrEmpty((String) o["in_reply_to_status_id"])
                            ? "0"
                            : (String) o["in_reply_to_status_id"]),
                    InReplyToUserID =
                        long.Parse(String.IsNullOrEmpty((String) o["in_reply_to_user_id"])
                            ? "0"
                            : (String) o["in_reply_to_user_id"]),
                    IsFavorited = Boolean.Parse((String) o["favorited"]),
                    IsSpreaded = Boolean.Parse((String) o["spread"]),
                    CanBeFavorited = !Boolean.Parse((String) o["favorited"]),
                    CanBeSpread = !Boolean.Parse((String) o["spread"]),
                    ReplyStatus =
                        (JObject) o["reply_status"] == null
                            ? null
                            : ParsePost((JObject) o["reply_status"], userAccountEntity),
                    SourceName = (String) o["source"]["name"],
                    SourceUrl = (String) o["source"]["url"],
                    SpreadCount = long.Parse((String) o["spread_count"]),
                    SpreadStatus =
                        (JObject) o["spread_status"] == null
                            ? null
                            : ParsePost((JObject) o["spread_status"], userAccountEntity),
                    StatusID = long.Parse((String) o["id"]),
                    Post = (String) o["text"],
                    User = UserEntity.Parse(o["user"].ToString(), userAccountEntity),
                    ImageUrl =
                        (JObject) o["entities"]["media"] == null
                            ? null
                            : ParseEntities((JObject) o["entities"], "media_url_https"),
                    ImageLargeUrl =
                        (JObject) o["entities"]["media"] == null
                            ? null
                            : ParseEntities((JObject) o["entities"], "media_url_https") + "?large",
                    Media =
                        (JObject) o["entities"]["media"] == null ? null : ParseEntities((JObject) o["entities"], "type")
                };
                post.Links =
                    post.Post.Split("\t\n ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                        .Where(s => s.StartsWith("http://") || s.StartsWith("www."));
                post.IsCreator = post.User.UserID == userAccountEntity.GetUserEntity().UserID;
                post.CreatedDate = ToDate(post.CreatedAt);
                post.IsNotCreator = !post.IsCreator;
                if (post.Media != null)
                {
                    if (post.Media.Equals("photo"))
                    {
                        post.HasMediaString = "画像 ";
                        post.HasMedia = true;
                    }
                }
                if (post.SpreadStatus != null)
                {
                    post.SpreadStatus.SpreadBy = string.Format("{0}さんがイイネ!しました。", post.User.Name);
                    entity.Add(post.SpreadStatus);
                }
                else
                {
                    entity.Add(post);
                }
            }

            return entity;
        }
Exemple #4
0
 public static PostEntity ParsePost(JObject o, UserAccountEntity userAccountEntity)
 {
     var post = new PostEntity
     {
         CreatedAt = FixTime((String) o["created_at"]),
         FavoritedCount = long.Parse((String) o["favorited_count"]),
         InReplyToScreenName = (String) o["in_reply_to_screen_name"],
         InReplyToStatusID =
             long.Parse(String.IsNullOrEmpty((String) o["in_reply_to_status_id"])
                 ? "0"
                 : (String) o["in_reply_to_status_id"]),
         InReplyToUserID =
             long.Parse(String.IsNullOrEmpty((String) o["in_reply_to_user_id"])
                 ? "0"
                 : (String) o["in_reply_to_user_id"]),
         IsFavorited = Boolean.Parse((String) o["favorited"]),
         IsSpreaded = Boolean.Parse((String) o["spread"]),
         ReplyStatus =
             (JObject) o["reply_status"] == null
                 ? null
                 : ParsePost((JObject) o["reply_status"], userAccountEntity),
         SourceName = (String) o["source"]["name"],
         SourceUrl = (String) o["source"]["url"],
         SpreadCount = long.Parse((String) o["spread_count"]),
         SpreadStatus =
             (JObject) o["spread_status"] == null
                 ? null
                 : ParsePost((JObject) o["spread_status"], userAccountEntity),
         StatusID = long.Parse((String) o["id"]),
         Post = (String) o["text"],
         User = UserEntity.Parse(o["user"].ToString(), userAccountEntity),
         ImageUrl =
             (JObject) o["entities"]["media"] == null
                 ? null
                 : ParseEntities((JObject) o["entities"], "media_url_https"),
         ImageLargeUrl =
             (JObject) o["entities"]["media"] == null
                 ? null
                 : ParseEntities((JObject) o["entities"], "media_url_https") + "?large",
         Media = (JObject) o["entities"]["media"] == null ? null : ParseEntities((JObject) o["entities"], "type")
     };
     if (post.User != null)
     {
         post.IsCreator = post.User.UserID == userAccountEntity.GetUserEntity().UserID;
     }
     return post;
 }