-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
104 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/Kook.Net.Core/Entities/Users/IIntimacyRelationRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Kook; | ||
|
||
/// <summary> | ||
/// 表示一个通用的用户之间的亲密关系请求。 | ||
/// </summary> | ||
public interface IIntimacyRelationRequest : IFriendRequest | ||
{ | ||
/// <summary> | ||
/// 获取此亲密关系的关系类型。 | ||
/// </summary> | ||
IntimacyRelationType? IntimacyType { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Kook.Net.Rest/Entities/Users/RestIntimacyRelationRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace Kook.Rest; | ||
|
||
/// <summary> | ||
/// 表示一个基于 REST 的亲密关系请求。 | ||
/// </summary> | ||
public class RestIntimacyRelationRequest : RestFriendRequest, IIntimacyRelationRequest | ||
{ | ||
internal RestIntimacyRelationRequest(BaseKookClient kook, ulong id) | ||
: base(kook, id) | ||
{ } | ||
|
||
/// <inheritdoc /> | ||
public IntimacyRelationType? IntimacyType { get; internal set; } | ||
|
||
internal static new RestIntimacyRelationRequest Create(BaseKookClient kook, API.Rest.FriendState model) | ||
{ | ||
RestIntimacyRelationRequest entity = new(kook, model.Id); | ||
entity.Update(model); | ||
return entity; | ||
} | ||
|
||
internal override void Update(API.Rest.FriendState model) | ||
{ | ||
base.Update(model); | ||
IntimacyType = model.IntimacyType; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override Task AcceptAsync(RequestOptions? options = null) => | ||
UserHelper.HandleIntimacyRequestAsync(this, true, Kook, options); | ||
|
||
/// <inheritdoc /> | ||
public override Task DeclineAsync(RequestOptions? options = null) => | ||
UserHelper.HandleIntimacyRequestAsync(this, false, Kook, options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Kook.Net.Rest/Net/Converters/NullableDateTimeOffsetUnixTimeSecondsConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Kook.Net.Converters; | ||
|
||
internal class NullableDateTimeOffsetUnixTimeSecondsConverter : JsonConverter<DateTimeOffset?> | ||
{ | ||
/// <inheritdoc /> | ||
public override bool HandleNull => true; | ||
|
||
public override DateTimeOffset? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType == JsonTokenType.Null) | ||
return null; | ||
long tick = reader.GetInt64(); | ||
if (tick == 0) | ||
return null; | ||
|
||
return DateTimeOffset.FromUnixTimeSeconds(tick); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, DateTimeOffset? value, JsonSerializerOptions options) | ||
{ | ||
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER | ||
if (!value.HasValue || value == DateTimeOffset.MinValue || value == DateTimeOffset.UnixEpoch) | ||
#else | ||
if (!value.HasValue || value == DateTimeOffset.MinValue || value == new DateTimeOffset(621355968000000000L, TimeSpan.Zero)) | ||
#endif | ||
writer.WriteNullValue(); | ||
else | ||
writer.WriteNumberValue(value.Value.ToUnixTimeSeconds()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters