Merge remote-tracking branch 'refs/remotes/ppy/master' into beatmap-listing-expanded

This commit is contained in:
Andrei Zavatski
2020-03-06 01:27:51 +03:00
286 changed files with 6276 additions and 2706 deletions

View File

@ -10,27 +10,32 @@ namespace osu.Game.Online.API.Requests
{
public class GetCommentsRequest : APIRequest<CommentBundle>
{
private readonly long id;
private readonly int page;
private readonly long commentableId;
private readonly CommentableType type;
private readonly CommentsSortCriteria sort;
private readonly int page;
private readonly long? parentId;
public GetCommentsRequest(CommentableType type, long id, CommentsSortCriteria sort = CommentsSortCriteria.New, int page = 1)
public GetCommentsRequest(long commentableId, CommentableType type, CommentsSortCriteria sort = CommentsSortCriteria.New, int page = 1, long? parentId = null)
{
this.commentableId = commentableId;
this.type = type;
this.sort = sort;
this.id = id;
this.page = page;
this.parentId = parentId;
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.AddParameter("commentable_id", commentableId.ToString());
req.AddParameter("commentable_type", type.ToString().Underscore().ToLowerInvariant());
req.AddParameter("commentable_id", id.ToString());
req.AddParameter("sort", sort.ToString().ToLowerInvariant());
req.AddParameter("page", page.ToString());
req.AddParameter("sort", sort.ToString().ToLowerInvariant());
if (parentId != null)
req.AddParameter("parent_id", parentId.ToString());
return req;
}

View File

@ -0,0 +1,19 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Game.Online.Multiplayer;
namespace osu.Game.Online.API.Requests
{
public class GetRoomRequest : APIRequest<Room>
{
private readonly int roomId;
public GetRoomRequest(int roomId)
{
this.roomId = roomId;
}
protected override string Target => $"rooms/{roomId}";
}
}

View File

@ -4,8 +4,6 @@
using Newtonsoft.Json;
using osu.Game.Users;
using System;
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Online.API.Requests.Responses
{
@ -17,8 +15,6 @@ namespace osu.Game.Online.API.Requests.Responses
[JsonProperty(@"parent_id")]
public long? ParentId { get; set; }
public readonly List<Comment> ChildComments = new List<Comment>();
public Comment ParentComment { get; set; }
[JsonProperty(@"user_id")]
@ -71,7 +67,5 @@ namespace osu.Game.Online.API.Requests.Responses
public bool HasMessage => !string.IsNullOrEmpty(Message);
public bool IsVoted { get; set; }
public int DeletedChildrenCount => ChildComments.Count(c => c.IsDeleted);
}
}

View File

@ -9,31 +9,8 @@ namespace osu.Game.Online.API.Requests.Responses
{
public class CommentBundle
{
private List<Comment> comments;
[JsonProperty(@"comments")]
public List<Comment> Comments
{
get => comments;
set
{
comments = value;
comments.ForEach(child =>
{
if (child.ParentId != null)
{
comments.ForEach(parent =>
{
if (parent.Id == child.ParentId)
{
parent.ChildComments.Add(child);
child.ParentComment = parent;
}
});
}
});
}
}
public List<Comment> Comments { get; set; }
[JsonProperty(@"has_more")]
public bool HasMore { get; set; }
@ -58,6 +35,7 @@ namespace osu.Game.Online.API.Requests.Responses
userVotes = value;
Comments.ForEach(c => c.IsVoted = value.Contains(c.Id));
IncludedComments.ForEach(c => c.IsVoted = value.Contains(c.Id));
}
}
@ -81,6 +59,15 @@ namespace osu.Game.Online.API.Requests.Responses
if (c.EditedById == u.Id)
c.EditedUser = u;
});
IncludedComments.ForEach(c =>
{
if (c.UserId == u.Id)
c.User = u;
if (c.EditedById == u.Id)
c.EditedUser = u;
});
});
}
}