Skip to content

Commit

Permalink
Add support for method messages.changeConversationMemberRestrictions (#…
Browse files Browse the repository at this point in the history
…1610) (#1612)

#1610

## Список изменений
- Добавлена поддержка метода
messages.changeConversationMemberRestrictions

##### Обязательно выполните следующие пункты:
- [x] Проверьте что ваш код не содержит конфликтов, и исправьте их по
необходимости
- [x] Напишите тесты, и обязательно проверьте что не падают другие.

##### Внимание! Pull Request'ы с непройденными тестами не принимаются
  • Loading branch information
xiadosw authored Mar 14, 2024
1 parent 58fc173 commit 7bf8a7b
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 0 deletions.
22 changes: 22 additions & 0 deletions VkNet.Tests/Categories/Messages/MessagesCategoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,4 +1120,26 @@ public void SetMemberRole()
.BeTrue();

}

[Fact]
public void ChangeConversationMemberRestrictions()
{
Url = "https://api.vk.com/method/messages.changeConversationMemberRestrictions";
ReadCategoryJsonPath(nameof(ChangeConversationMemberRestrictions));

var response = Api.Messages.ChangeConversationMemberRestrictions(new()
{
PeerId = 1,
MemberIds = new List<long>
{
814412, 4245645
},
For = 60,
Action = ConversationMemberRestrictionsActionType.Ro
});

response.FailedMemberIds.Should()
.BeEquivalentTo(new List<long> { 814412 });

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"response": {
"failed_member_ids": [
814412
]
}
}
14 changes: 14 additions & 0 deletions VkNet/Abstractions/Category/Async/IMessagesCategoryAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,20 @@ Task<GetIntentUsersResult> GetIntentUsersAsync(MessagesGetIntentUsersParams getI
Task<bool> MarkAsUnreadConversationAsync(long peerId,
CancellationToken token = default);

/// <summary>
/// Устанавливает ограничения участнику чата.
/// </summary>
/// <param name="params">
/// Входные параметры запроса
/// </param>
/// <param name="token">Токен отмены операции</param>
/// <returns>
/// Возвращает список идентификаторов, к которым не удалось применить ограничения
/// </returns>
Task<MessagesChangeConversationMemberRestrictionsObject> ChangeConversationMemberRestrictionsAsync(
MessagesChangeConversationMemberRestrictionsParams @params,
CancellationToken token = default);

#region Obsoleted

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions VkNet/Abstractions/Category/IMessagesCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ GetRecentCallsResult GetRecentCalls(IEnumerable<string> fields, ulong? count = n
/// <inheritdoc cref="IMessagesCategoryAsync.SetMemberRoleAsync"/>
bool SetMemberRole(string role, long peerId, ulong memberId);

/// <inheritdoc cref="IMessagesCategoryAsync.ChangeConversationMemberRestrictionsAsync"/>
MessagesChangeConversationMemberRestrictionsObject ChangeConversationMemberRestrictions(
MessagesChangeConversationMemberRestrictionsParams @params);

#region Obsoleted

/// <inheritdoc cref="IMessagesCategoryAsync.DeleteDialogAsync"/>
Expand Down
6 changes: 6 additions & 0 deletions VkNet/Categories/Async/MessagesCategoryAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,10 @@ public Task<bool> SetMemberRoleAsync(string role,
CancellationToken token = default) =>
TypeHelper.TryInvokeMethodAsync(() =>
SetMemberRole(role, peerId, memberId), token);

/// <inheritdoc />
public Task<MessagesChangeConversationMemberRestrictionsObject> ChangeConversationMemberRestrictionsAsync(
MessagesChangeConversationMemberRestrictionsParams @params,
CancellationToken token = default) => TypeHelper.TryInvokeMethodAsync(() =>
ChangeConversationMemberRestrictions(@params), token);
}
19 changes: 19 additions & 0 deletions VkNet/Categories/MessagesCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1470,4 +1470,23 @@ public bool SetMemberRole(string role, long peerId, ulong memberId) => _vk.Call<
}
});

/// <inheritdoc />
public MessagesChangeConversationMemberRestrictionsObject
ChangeConversationMemberRestrictions(MessagesChangeConversationMemberRestrictionsParams @params) =>
_vk.Call<MessagesChangeConversationMemberRestrictionsObject>("messages.changeConversationMemberRestrictions",
new()
{
{
"peer_id", @params.PeerId
},
{
"member_ids", @params.MemberIds
},
{
"for", @params.For
},
{
"action", @params.Action
}
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json;
using VkNet.Utils.JsonConverter;

namespace VkNet.Enums.StringEnums;

/// <summary>
/// Ограничения участников разговора
/// </summary>
[StringEnum]
[JsonConverter(typeof(TolerantStringEnumConverter))]
public enum ConversationMemberRestrictionsActionType
{
/// <summary>
/// Read/write, пользователь может читать и отправлять сообщения в чат
/// </summary>
Rw,

/// <summary>
/// Read only, пользователь не может отправлять сообщения в чат
/// </summary>
Ro
}
18 changes: 18 additions & 0 deletions VkNet/Model/MessagesChangeConversationMemberRestrictionsObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.ObjectModel;
using Newtonsoft.Json;

namespace VkNet.Model;

/// <summary>
/// Результат выполнения запроса установки ограничений участнику чата
/// </summary>
[Serializable]
public class MessagesChangeConversationMemberRestrictionsObject
{
/// <summary>
/// Список идентификаторов, к которым не удалось применить ограничения
/// </summary>
[JsonProperty("failed_member_ids")]
public ReadOnlyCollection<long> FailedMemberIds { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using VkNet.Enums.StringEnums;

namespace VkNet.Model;

/// <summary>
/// Список параметров для метода messages.changeConversationMemberRestrictions
/// </summary>
[Serializable]
public class MessagesChangeConversationMemberRestrictionsParams
{
/// <summary>
/// Идентификатор назначения.
/// </summary>
[JsonProperty("peer_id")]
public long PeerId { get; set; }

/// <summary>
/// Идентификаторы пользователей.
/// </summary>
[JsonProperty("member_ids")]
public IEnumerable<long> MemberIds { get; set; }

/// <summary>
/// Время в секундах. Если нужно замутить навсегда, то указывать не нужно.
/// </summary>
[JsonProperty("for", NullValueHandling = NullValueHandling.Ignore)]
public long For { get; set; }

/// <summary>
/// Разрешенные действия.
/// </summary>
[JsonProperty("action")]
public ConversationMemberRestrictionsActionType Action { get; set; }
}

0 comments on commit 7bf8a7b

Please sign in to comment.