Skip to content

Commit

Permalink
Рефакторинг GroupUpdate (#1238)
Browse files Browse the repository at this point in the history
* Интерфейс-маркер для возмжных обновлений от группы

* Первый круг ада (рефакторинга)

* Второй круг ада (рефакторинга) GroupUpdate

* Пометил Obsolete все что в дальнейшем будет не нужно
  • Loading branch information
HencoDesu authored Jun 11, 2022
1 parent bc1b5c4 commit 5c8f70f
Show file tree
Hide file tree
Showing 38 changed files with 573 additions and 159 deletions.
2 changes: 1 addition & 1 deletion VkNet/Enums/SafetyEnums/GroupChangeSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace VkNet.Model.GroupUpdate
/// Событие о изменении настроек сообщества
/// </summary>
[Serializable]
public class GroupChangeSettings
public class GroupChangeSettings : IGroupUpdate
{
/// <summary>
/// Идентификатор пользователя, который внёс изменения;
Expand Down
3 changes: 3 additions & 0 deletions VkNet/Enums/SafetyEnums/GroupUpdateType.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;

namespace VkNet.Enums.SafetyEnums
{
/// <summary>
/// Тип обновления
/// </summary>
[Obsolete("Типы обновлений теперь проверяются в GroupUpdate")]
public sealed class GroupUpdateType : SafetyEnum<GroupUpdateType>
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion VkNet/Enums/SafetyEnums/LikeAdd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace VkNet.Model.GroupUpdate
/// Событие о новой отметке "Мне нравится"
/// </summary>
[Serializable]
public class LikeAdd
public class LikeAdd : IGroupUpdate
{
/// <summary>
/// Идентификатор пользователя, который поставил отметку.
Expand Down
2 changes: 1 addition & 1 deletion VkNet/Enums/SafetyEnums/LikeRemove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace VkNet.Model.GroupUpdate
/// Событие о снятии отметке "Мне нравится"
/// </summary>
[Serializable]
public class LikeRemove
public class LikeRemove : IGroupUpdate
{
/// <summary>
/// Идентификатор пользователя, который убрал отметку.
Expand Down
2 changes: 1 addition & 1 deletion VkNet/Enums/SafetyEnums/MessageTypingState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace VkNet.Model.GroupUpdate
/// Объект, который содержит информацию о статусе печатании
/// </summary>
[Serializable]
public class MessageTypingState
public class MessageTypingState : IGroupUpdate
{
/// <summary>
/// Идентификатор пользователя, который набирает текст.
Expand Down
2 changes: 1 addition & 1 deletion VkNet/Enums/SafetyEnums/VkPayTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace VkNet.Model.GroupUpdate
/// платёж через VK Pay
/// </summary>
[Serializable]
public class VkPayTransaction
public class VkPayTransaction : IGroupUpdate
{
/// <summary>
/// Идентификатор пользователя-отправителя перевода.
Expand Down
3 changes: 2 additions & 1 deletion VkNet/Model/Attachments/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using VkNet.Enums;
using VkNet.Model.GroupUpdate;
using VkNet.Utils;

namespace VkNet.Model.Attachments
Expand All @@ -12,7 +13,7 @@ namespace VkNet.Model.Attachments
/// См. описание http://vk.com/dev/audio_object
/// </summary>
[Serializable]
public class Audio : MediaAttachment
public class Audio : MediaAttachment, IGroupUpdate
{
/// <inheritdoc />
protected override string Alias => "audio";
Expand Down
3 changes: 2 additions & 1 deletion VkNet/Model/Attachments/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Newtonsoft.Json.Converters;
using VkNet.Enums;
using VkNet.Model.Attachments;
using VkNet.Model.GroupUpdate;
using VkNet.Model.Keyboard;
using VkNet.Utils;
using VkNet.Utils.JsonConverter;
Expand All @@ -17,7 +18,7 @@ namespace VkNet.Model
/// </summary>
[DebuggerDisplay("[{PeerId}-{Id}] {Text}")]
[Serializable]
public class Message : MediaAttachment
public class Message : MediaAttachment, IGroupUpdate
{
/// <inheritdoc />
protected override string Alias => "message";
Expand Down
3 changes: 2 additions & 1 deletion VkNet/Model/Attachments/Photo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.ObjectModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using VkNet.Model.GroupUpdate;
using VkNet.Utils;

namespace VkNet.Model.Attachments
Expand All @@ -13,7 +14,7 @@ namespace VkNet.Model.Attachments
/// См. описание http://vk.com/dev/photo
/// </remarks>
[Serializable]
public class Photo : MediaAttachment
public class Photo : MediaAttachment, IGroupUpdate
{
/// <inheritdoc />
protected override string Alias => "photo";
Expand Down
3 changes: 2 additions & 1 deletion VkNet/Model/Attachments/Video.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using VkNet.Infrastructure;
using VkNet.Model.GroupUpdate;
using VkNet.Utils;

namespace VkNet.Model.Attachments
Expand All @@ -16,7 +17,7 @@ namespace VkNet.Model.Attachments
/// </remarks>
[DebuggerDisplay("Id = {Id}, Title = {Title}")]
[Serializable]
public class Video : MediaAttachment
public class Video : MediaAttachment, IGroupUpdate
{
/// <inheritdoc />
protected override string Alias => "video";
Expand Down
19 changes: 18 additions & 1 deletion VkNet/Model/GroupUpdate/BoardPost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace VkNet.Model.GroupUpdate
/// (<c>CommentBoard</c> с дополнительными полями)
/// </summary>
[Serializable]
public class BoardPost : CommentBoard
public class BoardPost : CommentBoard, IGroupUpdate
{
/// <summary>
/// Идентификатор обсуждения
Expand Down Expand Up @@ -39,5 +39,22 @@ public class BoardPost : CommentBoard
TopicOwnerId = response["topic_owner_id"]
};
}

/// <summary>
/// Преобразование класса <see cref="BoardPost" /> в <see cref="VkParameters" />
/// </summary>
/// <param name="response"> Ответ сервера. </param>
/// <returns> Результат преобразования в <see cref="BoardPost" /> </returns>
public static implicit operator BoardPost(VkResponse response)
{
if (response == null)
{
return null;
}

return response.HasToken()
? FromJson(response)
: null;
}
}
}
19 changes: 18 additions & 1 deletion VkNet/Model/GroupUpdate/BoardPostDelete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace VkNet.Model.GroupUpdate
/// Удаление комментария в обсуждении (<c>BoardPostDelete</c>)
/// </summary>
[Serializable]
public class BoardPostDelete
public class BoardPostDelete : IGroupUpdate
{
/// <summary>
/// Идентификатор комментария
Expand Down Expand Up @@ -37,5 +37,22 @@ public static BoardPostDelete FromJson(VkResponse response)
TopicOwnerId = response["topic_owner_id"],
};
}

/// <summary>
/// Преобразование класса <see cref="Message" /> в <see cref="VkParameters" />
/// </summary>
/// <param name="response"> Ответ сервера. </param>
/// <returns> Результат преобразования в <see cref="Message" /> </returns>
public static implicit operator BoardPostDelete(VkResponse response)
{
if (response == null)
{
return null;
}

return response.HasToken()
? FromJson(response)
: null;
}
}
}
19 changes: 18 additions & 1 deletion VkNet/Model/GroupUpdate/DonutChanged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace VkNet.Model.GroupUpdate
/// Добавление участника или заявки на вступление в сообщество
/// </summary>
[Serializable]
public class DonutChanged
public class DonutChanged : IGroupUpdate
{
/// <summary>
/// Идентификатор пользователя
Expand Down Expand Up @@ -53,5 +53,22 @@ public static DonutChanged FromJson(VkResponse response)

return groupJoin;
}

/// <summary>
/// Преобразование класса <see cref="DonutChanged" /> в <see cref="VkParameters" />
/// </summary>
/// <param name="response"> Ответ сервера. </param>
/// <returns> Результат преобразования в <see cref="DonutChanged" /> </returns>
public static implicit operator DonutChanged(VkResponse response)
{
if (response == null)
{
return null;
}

return response.HasToken()
? FromJson(response)
: null;
}
}
}
19 changes: 18 additions & 1 deletion VkNet/Model/GroupUpdate/DonutEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace VkNet.Model.GroupUpdate
/// Добавление участника или заявки на вступление в сообщество
/// </summary>
[Serializable]
public class DonutEnd
public class DonutEnd : IGroupUpdate
{
/// <summary>
/// Идентификатор пользователя
Expand All @@ -29,5 +29,22 @@ public static DonutEnd FromJson(VkResponse response)

return groupJoin;
}

/// <summary>
/// Преобразование класса <see cref="DonutEnd" /> в <see cref="VkParameters" />
/// </summary>
/// <param name="response"> Ответ сервера. </param>
/// <returns> Результат преобразования в <see cref="DonutEnd" /> </returns>
public static implicit operator DonutEnd(VkResponse response)
{
if (response == null)
{
return null;
}

return response.HasToken()
? FromJson(response)
: null;
}
}
}
19 changes: 18 additions & 1 deletion VkNet/Model/GroupUpdate/DonutNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace VkNet.Model.GroupUpdate
/// Добавление участника или заявки на вступление в сообщество
/// </summary>
[Serializable]
public class DonutNew
public class DonutNew : IGroupUpdate
{
/// <summary>
/// Идентификатор пользователя
Expand Down Expand Up @@ -41,5 +41,22 @@ public static DonutNew FromJson(VkResponse response)

return groupJoin;
}

/// <summary>
/// Преобразование класса <see cref="DonutNew" /> в <see cref="VkParameters" />
/// </summary>
/// <param name="response"> Ответ сервера. </param>
/// <returns> Результат преобразования в <see cref="DonutNew" /> </returns>
public static implicit operator DonutNew(VkResponse response)
{
if (response == null)
{
return null;
}

return response.HasToken()
? FromJson(response)
: null;
}
}
}
19 changes: 18 additions & 1 deletion VkNet/Model/GroupUpdate/DonutWithdraw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace VkNet.Model.GroupUpdate
/// Добавление участника или заявки на вступление в сообщество
/// </summary>
[Serializable]
public class DonutWithdraw
public class DonutWithdraw : IGroupUpdate
{
/// <summary>
/// Произошла ли ошибка
Expand Down Expand Up @@ -49,5 +49,22 @@ public static DonutWithdraw FromJson(VkResponse response)

return groupJoin;
}

/// <summary>
/// Преобразование класса <see cref="DonutWithdraw" /> в <see cref="VkParameters" />
/// </summary>
/// <param name="response"> Ответ сервера. </param>
/// <returns> Результат преобразования в <see cref="DonutWithdraw" /> </returns>
public static implicit operator DonutWithdraw(VkResponse response)
{
if (response == null)
{
return null;
}

return response.HasToken()
? FromJson(response)
: null;
}
}
}
19 changes: 18 additions & 1 deletion VkNet/Model/GroupUpdate/GroupChangePhoto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace VkNet.Model.GroupUpdate
/// Изменение главного фото
/// </summary>
[Serializable]
public class GroupChangePhoto
public class GroupChangePhoto : IGroupUpdate
{
/// <summary>
/// Идентификатор пользователя, который внес изменения
Expand All @@ -32,5 +32,22 @@ public static GroupChangePhoto FromJson(VkResponse response)
Photo = response["photo"]
};
}

/// <summary>
/// Преобразование класса <see cref="GroupChangePhoto" /> в <see cref="VkParameters" />
/// </summary>
/// <param name="response"> Ответ сервера. </param>
/// <returns> Результат преобразования в <see cref="GroupChangePhoto" /> </returns>
public static implicit operator GroupChangePhoto(VkResponse response)
{
if (response == null)
{
return null;
}

return response.HasToken()
? FromJson(response)
: null;
}
}
}
19 changes: 18 additions & 1 deletion VkNet/Model/GroupUpdate/GroupJoin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace VkNet.Model.GroupUpdate
/// Добавление участника или заявки на вступление в сообщество
/// </summary>
[Serializable]
public class GroupJoin
public class GroupJoin : IGroupUpdate
{
/// <summary>
/// Идентификатор пользователя
Expand All @@ -36,5 +36,22 @@ public static GroupJoin FromJson(VkResponse response)

return groupJoin;
}

/// <summary>
/// Преобразование класса <see cref="GroupJoin" /> в <see cref="VkParameters" />
/// </summary>
/// <param name="response"> Ответ сервера. </param>
/// <returns> Результат преобразования в <see cref="GroupJoin" /> </returns>
public static implicit operator GroupJoin(VkResponse response)
{
if (response == null)
{
return null;
}

return response.HasToken()
? FromJson(response)
: null;
}
}
}
Loading

0 comments on commit 5c8f70f

Please sign in to comment.