| | | 1 | | namespace TeleFlow.Annotations; |
| | | 2 | | /// <summary> |
| | | 3 | | /// Restricts a handler or handler class to specific forum message thread ids. |
| | | 4 | | /// </summary> |
| | | 5 | | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] |
| | | 6 | | public sealed class MessageThreadIdAttribute : TeleFlowAttribute |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Creates a message thread id filter. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <param name="messageThreadIds">Telegram message thread ids allowed to match.</param> |
| | 9 | 12 | | public MessageThreadIdAttribute(params long[] messageThreadIds) |
| | | 13 | | { |
| | 9 | 14 | | ArgumentNullException.ThrowIfNull(messageThreadIds); |
| | | 15 | | |
| | 9 | 16 | | if (messageThreadIds.Length == 0) |
| | | 17 | | { |
| | 0 | 18 | | throw new ArgumentException("At least one Telegram message thread id must be specified.", nameof(messageThre |
| | | 19 | | } |
| | | 20 | | |
| | 18 | 21 | | if (messageThreadIds.Any(static messageThreadId => messageThreadId <= 0)) |
| | | 22 | | { |
| | 0 | 23 | | throw new ArgumentException("Telegram message thread ids must be positive.", nameof(messageThreadIds)); |
| | | 24 | | } |
| | | 25 | | |
| | 9 | 26 | | MessageThreadIds = messageThreadIds.ToArray(); |
| | 9 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Telegram message thread ids allowed to match. |
| | | 31 | | /// </summary> |
| | | 32 | | public IReadOnlyList<long> MessageThreadIds { get; } |
| | | 33 | | } |