< Summary

Information
Class: TeleFlow.Telegram.Internal.Handlers.TelegramFilterContextFacts
Assembly: TeleFlow.Framework
File(s): /_/src/TeleFlow.Framework/Internal/Handlers/TelegramFilterContextFacts.cs
Line coverage
97%
Covered lines: 37
Uncovered lines: 1
Coverable lines: 38
Total lines: 71
Line coverage: 97.3%
Branch coverage
92%
Covered branches: 13
Total branches: 14
Branch coverage: 92.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
From(...)83.33%6692.85%
FromMessage(...)100%22100%
FromCallback(...)100%66100%

File(s)

/_/src/TeleFlow.Framework/Internal/Handlers/TelegramFilterContextFacts.cs

#LineLine coverage
 1using TeleFlow.Telegram.Schema.Types;
 2
 3namespace TeleFlow.Telegram.Internal.Handlers;
 4
 5/// <summary>
 6/// Captures destination, sender, and thread facts once before built-in filters evaluate an update.
 7/// It keeps Telegram's destination chat, actual sender user, and <c>sender_chat</c> provenance as separate concepts.
 8/// </summary>
 9internal readonly record struct TelegramFilterContextFacts(
 10    Chat? DestinationChat,
 11    User? SenderUser,
 12    Chat? SenderChat,
 13    long? MessageThreadId)
 14{
 15    public static TelegramFilterContextFacts From(TelegramUpdateContext context)
 16    {
 26617        return context switch
 26618        {
 16719            MessageContext messageContext => FromMessage(messageContext.TelegramMessage),
 26620
 9721            CallbackQueryContext callbackContext => FromCallback(callbackContext),
 26622
 223            ChatMemberUpdatedContext chatMemberContext => new TelegramFilterContextFacts(
 224                chatMemberContext.TelegramChat,
 225                SenderUser: null,
 226                SenderChat: null,
 227                MessageThreadId: null),
 26628
 029            _ => default
 26630        };
 31    }
 32
 33    private static TelegramFilterContextFacts FromMessage(Message message)
 34    {
 16735        var senderChat = message.SenderChat;
 36
 16737        return new TelegramFilterContextFacts(
 16738            message.Chat,
 16739            senderChat is null ? message.From : null,
 16740            senderChat,
 16741            message.MessageThreadId);
 42    }
 43
 44    private static TelegramFilterContextFacts FromCallback(CallbackQueryContext context)
 45    {
 9746        if (context.TelegramCallbackQuery.Message is not { } maybeMessage)
 47        {
 3948            return new TelegramFilterContextFacts(
 3949                DestinationChat: null,
 3950                context.TelegramCallbackQuery.From,
 3951                SenderChat: null,
 3952                MessageThreadId: null);
 53        }
 54
 5855        if (maybeMessage.TryGetMessage(out var message) &&
 5856            message is not null)
 57        {
 2958            return new TelegramFilterContextFacts(
 2959                message.Chat,
 2960                context.TelegramCallbackQuery.From,
 2961                SenderChat: null,
 2962                message.MessageThreadId);
 63        }
 64
 2965        return new TelegramFilterContextFacts(
 2966            DestinationChat: null,
 2967            context.TelegramCallbackQuery.From,
 2968            SenderChat: null,
 2969            MessageThreadId: null);
 70    }
 71}