2019-01-24 16:43:03 +08:00
|
|
|
|
// 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.
|
2018-06-08 10:41:54 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using JetBrains.Annotations;
|
2018-06-08 10:41:54 +08:00
|
|
|
|
using Newtonsoft.Json;
|
2021-11-04 17:02:44 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2021-11-15 13:38:14 +08:00
|
|
|
|
using osu.Game.Extensions;
|
2018-06-08 10:41:54 +08:00
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Online.API.Requests.Responses
|
|
|
|
|
{
|
2022-02-23 16:12:38 +08:00
|
|
|
|
[JsonObject(MemberSerialization.OptIn)]
|
2021-11-04 17:02:44 +08:00
|
|
|
|
public class APIUser : IEquatable<APIUser>, IUser
|
2018-06-08 10:41:54 +08:00
|
|
|
|
{
|
2022-03-28 21:20:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A user ID which can be used to represent any system user which is not attached to a user profile.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public const int SYSTEM_USER_ID = 0;
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
[JsonProperty(@"id")]
|
|
|
|
|
public int Id { get; set; } = 1;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"join_date")]
|
|
|
|
|
public DateTimeOffset JoinDate;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"username")]
|
2023-10-17 16:48:51 +08:00
|
|
|
|
public string Username { get; set; } = string.Empty;
|
2021-11-04 17:02:44 +08:00
|
|
|
|
|
|
|
|
|
[JsonProperty(@"previous_usernames")]
|
|
|
|
|
public string[] PreviousUsernames;
|
|
|
|
|
|
2024-02-10 07:15:27 +08:00
|
|
|
|
[JsonProperty(@"rank_highest")]
|
|
|
|
|
[CanBeNull]
|
|
|
|
|
public UserRankHighest RankHighest;
|
|
|
|
|
|
|
|
|
|
public class UserRankHighest
|
|
|
|
|
{
|
|
|
|
|
[JsonProperty(@"rank")]
|
|
|
|
|
public int Rank;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"updated_at")]
|
|
|
|
|
public DateTimeOffset UpdatedAt;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-08 07:49:11 +08:00
|
|
|
|
[JsonProperty(@"country_code")]
|
|
|
|
|
private string countryCodeString;
|
2022-07-16 09:06:25 +08:00
|
|
|
|
|
2022-07-18 13:40:43 +08:00
|
|
|
|
public CountryCode CountryCode
|
2022-07-16 09:06:25 +08:00
|
|
|
|
{
|
2023-11-08 07:49:11 +08:00
|
|
|
|
get => Enum.TryParse(countryCodeString, out CountryCode result) ? result : CountryCode.Unknown;
|
|
|
|
|
set => countryCodeString = value.ToString();
|
2022-07-16 09:06:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-07 01:21:44 +08:00
|
|
|
|
public readonly Bindable<UserStatus?> Status = new Bindable<UserStatus?>();
|
2021-11-04 17:02:44 +08:00
|
|
|
|
|
|
|
|
|
public readonly Bindable<UserActivity> Activity = new Bindable<UserActivity>();
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"profile_colour")]
|
|
|
|
|
public string Colour;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"avatar_url")]
|
|
|
|
|
public string AvatarUrl;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"cover_url")]
|
|
|
|
|
public string CoverUrl
|
|
|
|
|
{
|
|
|
|
|
get => Cover?.Url;
|
|
|
|
|
set => Cover = new UserCover { Url = value };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"cover")]
|
|
|
|
|
public UserCover Cover;
|
|
|
|
|
|
|
|
|
|
public class UserCover
|
|
|
|
|
{
|
|
|
|
|
[JsonProperty(@"custom_url")]
|
|
|
|
|
public string CustomUrl;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"url")]
|
|
|
|
|
public string Url;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"id")]
|
|
|
|
|
public int? Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"is_admin")]
|
|
|
|
|
public bool IsAdmin;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"is_supporter")]
|
|
|
|
|
public bool IsSupporter;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"support_level")]
|
|
|
|
|
public int SupportLevel;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"is_gmt")]
|
|
|
|
|
public bool IsGMT;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"is_qat")]
|
|
|
|
|
public bool IsQAT;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"is_bng")]
|
|
|
|
|
public bool IsBNG;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"is_bot")]
|
2021-11-05 12:38:48 +08:00
|
|
|
|
public bool IsBot { get; set; }
|
2021-11-04 17:02:44 +08:00
|
|
|
|
|
|
|
|
|
[JsonProperty(@"is_active")]
|
|
|
|
|
public bool Active;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"is_online")]
|
|
|
|
|
public bool IsOnline;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"pm_friends_only")]
|
|
|
|
|
public bool PMFriendsOnly;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"interests")]
|
|
|
|
|
public string Interests;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"occupation")]
|
|
|
|
|
public string Occupation;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"title")]
|
|
|
|
|
public string Title;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"location")]
|
|
|
|
|
public string Location;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"last_visit")]
|
|
|
|
|
public DateTimeOffset? LastVisit;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"twitter")]
|
|
|
|
|
public string Twitter;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"discord")]
|
|
|
|
|
public string Discord;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"website")]
|
|
|
|
|
public string Website;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"post_count")]
|
|
|
|
|
public int PostCount;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"comments_count")]
|
|
|
|
|
public int CommentsCount;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"follower_count")]
|
|
|
|
|
public int FollowerCount;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"mapping_follower_count")]
|
|
|
|
|
public int MappingFollowerCount;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"favourite_beatmapset_count")]
|
|
|
|
|
public int FavouriteBeatmapsetCount;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"graveyard_beatmapset_count")]
|
|
|
|
|
public int GraveyardBeatmapsetCount;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"loved_beatmapset_count")]
|
|
|
|
|
public int LovedBeatmapsetCount;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"ranked_beatmapset_count")]
|
|
|
|
|
public int RankedBeatmapsetCount;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"pending_beatmapset_count")]
|
|
|
|
|
public int PendingBeatmapsetCount;
|
|
|
|
|
|
2022-04-22 12:55:39 +08:00
|
|
|
|
[JsonProperty(@"guest_beatmapset_count")]
|
|
|
|
|
public int GuestBeatmapsetCount;
|
|
|
|
|
|
2022-12-07 15:36:11 +08:00
|
|
|
|
[JsonProperty(@"nominated_beatmapset_count")]
|
|
|
|
|
public int NominatedBeatmapsetCount;
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
[JsonProperty(@"scores_best_count")]
|
|
|
|
|
public int ScoresBestCount;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"scores_first_count")]
|
|
|
|
|
public int ScoresFirstCount;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"scores_recent_count")]
|
|
|
|
|
public int ScoresRecentCount;
|
|
|
|
|
|
2022-02-11 02:23:38 +08:00
|
|
|
|
[JsonProperty(@"scores_pinned_count")]
|
|
|
|
|
public int ScoresPinnedCount;
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
[JsonProperty(@"beatmap_playcounts_count")]
|
2021-12-10 13:15:00 +08:00
|
|
|
|
public int BeatmapPlayCountsCount;
|
2021-11-04 17:02:44 +08:00
|
|
|
|
|
2021-12-28 13:44:19 +08:00
|
|
|
|
[JsonProperty(@"playstyle")]
|
2021-12-10 13:15:00 +08:00
|
|
|
|
private string[] playStyle
|
2021-11-04 17:02:44 +08:00
|
|
|
|
{
|
2022-12-27 06:12:53 +08:00
|
|
|
|
set => PlayStyles = value?.Select(str => Enum.Parse<APIPlayStyle>(str, true)).ToArray();
|
2021-11-04 17:02:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public APIPlayStyle[] PlayStyles;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"playmode")]
|
|
|
|
|
public string PlayMode;
|
|
|
|
|
|
2024-07-13 16:26:45 +08:00
|
|
|
|
[JsonProperty(@"profile_hue")]
|
|
|
|
|
public int? ProfileHue;
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
[JsonProperty(@"profile_order")]
|
|
|
|
|
public string[] ProfileOrder;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"kudosu")]
|
|
|
|
|
public KudosuCount Kudosu;
|
|
|
|
|
|
|
|
|
|
public class KudosuCount
|
|
|
|
|
{
|
|
|
|
|
[JsonProperty(@"total")]
|
|
|
|
|
public int Total;
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"available")]
|
|
|
|
|
public int Available;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UserStatistics statistics;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// User statistics for the requested ruleset (in the case of a <see cref="GetUserRequest"/> or <see cref="GetFriendsRequest"/> response).
|
|
|
|
|
/// Otherwise empty.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[JsonProperty(@"statistics")]
|
|
|
|
|
public UserStatistics Statistics
|
|
|
|
|
{
|
|
|
|
|
get => statistics ??= new UserStatistics();
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (statistics != null)
|
|
|
|
|
// we may already have rank history populated
|
|
|
|
|
value.RankHistory = statistics.RankHistory;
|
|
|
|
|
|
|
|
|
|
statistics = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"rank_history")]
|
2021-11-05 12:38:37 +08:00
|
|
|
|
private APIRankHistory rankHistory
|
2021-11-04 17:02:44 +08:00
|
|
|
|
{
|
2022-09-27 11:46:15 +08:00
|
|
|
|
set => Statistics.RankHistory = value;
|
2021-11-04 17:02:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-29 06:43:49 +08:00
|
|
|
|
[JsonProperty(@"active_tournament_banners")]
|
|
|
|
|
public TournamentBanner[] TournamentBanners;
|
2023-02-01 07:02:59 +08:00
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
[JsonProperty("badges")]
|
|
|
|
|
public Badge[] Badges;
|
|
|
|
|
|
|
|
|
|
[JsonProperty("user_achievements")]
|
2021-11-05 12:38:37 +08:00
|
|
|
|
public APIUserAchievement[] Achievements;
|
2021-11-04 17:02:44 +08:00
|
|
|
|
|
|
|
|
|
[JsonProperty("monthly_playcounts")]
|
2021-12-10 13:15:00 +08:00
|
|
|
|
public APIUserHistoryCount[] MonthlyPlayCounts;
|
2021-11-04 17:02:44 +08:00
|
|
|
|
|
|
|
|
|
[JsonProperty("replays_watched_counts")]
|
|
|
|
|
public APIUserHistoryCount[] ReplaysWatchedCounts;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// All user statistics per ruleset's short name (in the case of a <see cref="GetUsersRequest"/> response).
|
|
|
|
|
/// Otherwise empty. Can be altered for testing purposes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
// todo: this should likely be moved to a separate UserCompact class at some point.
|
|
|
|
|
[JsonProperty("statistics_rulesets")]
|
|
|
|
|
[CanBeNull]
|
|
|
|
|
public Dictionary<string, UserStatistics> RulesetsStatistics { get; set; }
|
|
|
|
|
|
2023-01-11 12:11:38 +08:00
|
|
|
|
[JsonProperty("groups")]
|
|
|
|
|
public APIUserGroup[] Groups;
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
public override string ToString() => Username;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A user instance for displaying locally created system messages.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly APIUser SYSTEM_USER = new APIUser
|
|
|
|
|
{
|
2022-03-28 21:20:56 +08:00
|
|
|
|
Id = SYSTEM_USER_ID,
|
2021-11-04 17:02:44 +08:00
|
|
|
|
Username = "system",
|
|
|
|
|
Colour = @"9c0101",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public int OnlineID => Id;
|
|
|
|
|
|
2021-11-15 13:38:14 +08:00
|
|
|
|
public bool Equals(APIUser other) => this.MatchesOnlineID(other);
|
2022-07-18 13:43:41 +08:00
|
|
|
|
|
|
|
|
|
#pragma warning disable 649
|
|
|
|
|
private class Country
|
|
|
|
|
{
|
|
|
|
|
[JsonProperty(@"code")]
|
|
|
|
|
public string Code;
|
|
|
|
|
}
|
|
|
|
|
#pragma warning restore 649
|
2018-06-08 10:41:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|