Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1359 from TelegramBots/develop
Release v20-alpha.3
- Loading branch information
Showing
326 changed files
with
12,681 additions
and
4,314 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<PreferredUILang>en</PreferredUILang> | ||
</PropertyGroup> | ||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Reflection; | ||
using Newtonsoft.Json.Linq; | ||
using Telegram.Bot.Types.Enums; | ||
|
||
namespace Telegram.Bot.Converters; | ||
|
||
internal class ChatBoostSourceConverter : JsonConverter | ||
{ | ||
static readonly TypeInfo BaseType = typeof(ChatBoostSource).GetTypeInfo(); | ||
|
||
public override bool CanWrite => false; | ||
public override bool CanRead => true; | ||
public override bool CanConvert(Type objectType) => | ||
BaseType.IsAssignableFrom(objectType.GetTypeInfo()); | ||
|
||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) | ||
{ | ||
if (value is null) | ||
{ | ||
writer.WriteNull(); | ||
} | ||
else | ||
{ | ||
var jo = JObject.FromObject(value); | ||
jo.WriteTo(writer); | ||
} | ||
} | ||
|
||
public override object? ReadJson( | ||
JsonReader reader, | ||
Type objectType, | ||
object? existingValue, | ||
JsonSerializer serializer) | ||
{ | ||
var jo = JObject.Load(reader); | ||
var type = jo["source"]?.ToObject<ChatBoostSourceType>(); | ||
|
||
if (type is null) | ||
{ | ||
return null; | ||
} | ||
|
||
var actualType = type switch | ||
{ | ||
ChatBoostSourceType.Premium => typeof(ChatBoostSourcePremium), | ||
ChatBoostSourceType.GiftCode => typeof(ChatBoostSourceGiftCode), | ||
ChatBoostSourceType.Giveaway => typeof(ChatBoostSourceGiveaway), | ||
_ => throw new JsonSerializationException($"Unknown chat boost source value of '{jo["source"]}'") | ||
}; | ||
|
||
// Remove status because status property only has getter | ||
jo.Remove("source"); | ||
var value = Activator.CreateInstance(actualType)!; | ||
serializer.Populate(jo.CreateReader(), value); | ||
|
||
return value; | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
src/Telegram.Bot/Converters/MaybeInaccessibleMessageConverter.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,54 @@ | ||
using System.Reflection; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Telegram.Bot.Converters; | ||
|
||
internal class MaybeInaccessibleMessageConverter : JsonConverter | ||
{ | ||
static readonly TypeInfo BaseType = typeof(MaybeInaccessibleMessage).GetTypeInfo(); | ||
|
||
public override bool CanWrite => false; | ||
public override bool CanRead => true; | ||
public override bool CanConvert(Type objectType) => | ||
BaseType.IsAssignableFrom(objectType.GetTypeInfo()); | ||
|
||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) | ||
{ | ||
if (value is null) | ||
{ | ||
writer.WriteNull(); | ||
} | ||
else | ||
{ | ||
var jo = JObject.FromObject(value); | ||
jo.WriteTo(writer); | ||
} | ||
} | ||
|
||
public override object? ReadJson( | ||
JsonReader reader, | ||
Type objectType, | ||
object? existingValue, | ||
JsonSerializer serializer) | ||
{ | ||
var jo = JObject.Load(reader); | ||
var date = jo["date"]?.Value<int>(); | ||
|
||
if (date is null) | ||
{ | ||
return null; | ||
} | ||
|
||
var actualType = date switch | ||
{ | ||
0 => typeof(InaccessibleMessage), | ||
_ => typeof(Message), | ||
}; | ||
|
||
// Remove status because status property only has getter | ||
var value = Activator.CreateInstance(actualType)!; | ||
serializer.Populate(jo.CreateReader(), value); | ||
|
||
return value; | ||
} | ||
} |
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,59 @@ | ||
using System.Reflection; | ||
using Newtonsoft.Json.Linq; | ||
using Telegram.Bot.Types.Enums; | ||
|
||
namespace Telegram.Bot.Converters; | ||
|
||
internal class MessageOriginConverter : JsonConverter | ||
{ | ||
static readonly TypeInfo BaseType = typeof(MessageOrigin).GetTypeInfo(); | ||
|
||
public override bool CanWrite => false; | ||
public override bool CanRead => true; | ||
public override bool CanConvert(Type objectType) => | ||
BaseType.IsAssignableFrom(objectType.GetTypeInfo()); | ||
|
||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) | ||
{ | ||
if (value is null) | ||
{ | ||
writer.WriteNull(); | ||
} | ||
else | ||
{ | ||
var jo = JObject.FromObject(value); | ||
jo.WriteTo(writer); | ||
} | ||
} | ||
|
||
public override object? ReadJson( | ||
JsonReader reader, | ||
Type objectType, | ||
object? existingValue, | ||
JsonSerializer serializer) | ||
{ | ||
var jo = JObject.Load(reader); | ||
var type = jo["type"]?.ToObject<MessageOriginType>(); | ||
|
||
if (type is null) | ||
{ | ||
return null; | ||
} | ||
|
||
var actualType = type switch | ||
{ | ||
MessageOriginType.User => typeof(MessageOriginUser), | ||
MessageOriginType.HiddenUser => typeof(MessageOriginHiddenUser), | ||
MessageOriginType.Chat => typeof(MessageOriginChat), | ||
MessageOriginType.Channel => typeof(MessageOriginChannel), | ||
_ => throw new JsonSerializationException($"Unknown message origin type value of '{jo["type"]}'") | ||
}; | ||
|
||
// Remove status because status property only has getter | ||
jo.Remove("type"); | ||
var value = Activator.CreateInstance(actualType)!; | ||
serializer.Populate(jo.CreateReader(), value); | ||
|
||
return value; | ||
} | ||
} |
Oops, something went wrong.