private async void LoadSection(ProfileContentType type)
        {
            items.Clear();
            page = 0;

            Profile profile = await api.GetProfileAsync(username, type);

            if (firstLoad)
            {
                Score     = profile.Score;
                Rants     = profile.RantsCount;
                Upvoted   = profile.UpvotedCount;
                Comments  = profile.CommentsCount;
                Viewed    = profile.ViewedCount;
                Favorites = profile.FavoritesCount;

                if (profile.AvatarImage != null)
                {
                    Avatar = api.GetAvatar(profile.AvatarImage);
                }

                firstLoad = false;
            }

            AddItems(profile);

            if (items.Count > 0)
            {
                window.ItemsListBox.ScrollIntoView(items[0]);
            }
        }
 public ApplicationProfile(string applicationName, string profileName, ProfileContentType type)
 {
     this.ApplicationName = applicationName;
     this.ProfileName     = profileName;
     this.ContentType     = type;
     this.CreateDate      = DateTime.Now;
     this.LastUpdate      = DateTime.Now;
 }
Пример #3
0
        private string MakeMessage(ProfileContentType type, string user)
        {
            switch (type)
            {
            case ProfileContentType.Upvoted:
                return(user + " +1'd a rant");

            case ProfileContentType.Rants:
                return("New rant by " + user);

            default:
                return(null);
            }
        }
Пример #4
0
        //TODO: NEed lastTime? IsRead should be enough?
        //Check if isRead is stored even if Filter is false
        private void AddTo(long lastTime, string username, ProfileContentType type, List <Dtos.Rant> rants, List <ViewModels.Rant> added)
        {
            foreach (var rant in rants)
            {
                if (rant.CreatedTime > lastTime)
                {
                    if (!history.IsRead(rant.Id))
                    {
                        ViewModels.Rant r = new ViewModels.Rant(rant);
                        r.UpdateText = MakeMessage(type, username);

                        added.Add(r);
                    }
                }
            }
        }
        private async void LoadMore()
        {
            page++;

            int skip = page * V1.Constants.ProfileDataSkip;

            ProfileContentType type = (ProfileContentType)SelectedSection;

            int total = GetTotal(type);

            if (total < skip)
            {
                return;
            }

            Profile profile = await api.GetProfileAsync(username, (ProfileContentType)SelectedSection, skip);

            AddItems(profile);
        }
        private int GetTotal(ProfileContentType type)
        {
            switch (type)
            {
            case ProfileContentType.Comments:
                return(Comments);

            case ProfileContentType.Favorites:
                return(Favorites);

            case ProfileContentType.Rants:
                return(Rants);

            case ProfileContentType.Upvoted:
                return(Upvoted);

            case ProfileContentType.Viewed:
                return(Viewed);

            default:
                throw new NotImplementedException();
            }
        }
Пример #7
0
        /// <summary>
        /// Requests profile details to the rest-api.
        /// </summary>
        /// <param name="username">Username of the profile to request.</param>
        /// <exception cref="ArgumentException">Thrown when <paramref name="username"/> is empty.</exception>
        /// <inheritdoc />
        public async Task <Profile> GetProfileAsync(string username, ProfileContentType type = ProfileContentType.Rants, int skip = 0)
        {
            if (string.IsNullOrEmpty(username))
            {
                throw new ArgumentException("Must be non-empty.", nameof(username));
            }

            var userId = await GetUserId(username);

            if (userId == null)
            {
                return(null);
            }

            Parameters paramz = new Parameters();

            paramz.Add("content", type.ToString().ToLower());
            paramz.Add("skip", skip.ToString());

            string url      = MakeUrl($"/api/users/{userId}", paramz);
            var    response = await client.GetAsync(url);

            var responseText = await response.Content.ReadAsStringAsync();

            JObject obj     = JObject.Parse(responseText);
            Profile profile = obj["profile"].ToObject <Profile>();

            //Add Data
            JObject content = obj["profile"]["content"]["content"] as JObject;

            string sectionName = type.ToString().ToLower();

            JObject counts = obj["profile"]["content"]["counts"] as JObject;

            profile.RantsCount     = GetCount(counts, "rants");
            profile.CommentsCount  = GetCount(counts, "comments");
            profile.UpvotedCount   = GetCount(counts, "upvoted");
            profile.FavoritesCount = GetCount(counts, "favorites");
            profile.ViewedCount    = GetCount(counts, "viewed");

            //Avatar Image
            var    img = obj["profile"]["avatar"]["i"];
            string avt = img == null? null : img.ToString();

            profile.AvatarImage = avt;

            //TODO: Collab

            JArray data = content[sectionName] as JArray;

            if (data != null)
            {
                List <Rant>    rantsList    = new List <Rant>();
                List <Comment> commentsList = new List <Comment>();

                foreach (JObject i in data)
                {
                    switch (type)
                    {
                    case ProfileContentType.Rants:
                    case ProfileContentType.Favorites:
                    case ProfileContentType.Upvoted:
                    case ProfileContentType.Viewed:
                        Rant rant = DataObject.Parse <Rant>(i);
                        rantsList.Add(rant);
                        break;

                    case ProfileContentType.Comments:
                        Comment comment = DataObject.Parse <Comment>(i);
                        commentsList.Add(comment);
                        break;
                    }
                }

                profile.Rants    = rantsList;
                profile.Comments = commentsList;
            }

            return(profile);
        }