Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Televerse v1.26.2 #297

Merged
merged 4 commits into from
Sep 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🔥 Can we avoid redundant accesses?
We took internal copies
HeySreelal committed Sep 28, 2024
commit 01c33e3b2ec6c7414780013453c443408883e385
62 changes: 56 additions & 6 deletions lib/src/televerse/context/context.dart
Original file line number Diff line number Diff line change
@@ -70,30 +70,64 @@ class Context {
return msg?.text?.clean.split(' ').sublist(1) ?? [];
}

/// (Internal) Arbitary message getter
///
/// Populated when `msg` is first accessed.
Message? __msg;

/// The thread id
int? _threadId([int? id]) {
bool isInTopic = msg?.isTopicMessage ?? false;
return id ?? (isInTopic ? msg?.messageThreadId : null);
}

/// (Internal) Chat Instance.
///
/// Will be populated when `ctx.chat` is first accessed.
Chat? _chat;

/// A shorthand getter for the [Chat] instance from the update.
///
/// This can be any of `msg.chat` or `myChatMember.chat` or `chatMember.chat` or `chatJoinRequest.chat` or `messageReaction.chat` or `messageReactionCount.chat` or `chatBoost.chat` or `removedChatBoost.chat`.
Chat? get chat => update.chat;
Chat? get chat {
if (_chat != null) {
return _chat!;
}
_chat = update.chat;
return _chat;
}

/// (Internal) The user isntance from the udpate.
///
/// Populated when `from` is first accessed.
User? _from;

/// A shorthand getter for the [User] instance from the update.
User? get from => update.from;
User? get from {
if (_from != null) return _from;
_from = update.from;
return _from;
}

/// (Internal) The File ID.
///
/// Populated when the `fileId` is initially accessed.
String? __fileId;

/// Internal getter for the file id
String? get _fileId {
return msg?.photo?.last.fileId ??
if (__fileId != null) {
return __fileId;
}
__fileId = msg?.photo?.last.fileId ??
msg?.animation?.fileId ??
msg?.audio?.fileId ??
msg?.document?.fileId ??
msg?.video?.fileId ??
msg?.videoNote?.fileId ??
msg?.voice?.fileId ??
msg?.sticker?.fileId;
return __fileId;
}

/// The File ID if the incoming message contains a File of any kind.
@@ -106,21 +140,37 @@ class Context {
return chat?.id;
}

/// (Internal) Message ID.
///
/// Populated when the `messageId` is first accessed.
int? __msgId;

/// The message id for internal use
int? get _msgId {
return msg?.messageId ??
if (__msgId != null) return __msgId;

__msgId = msg?.messageId ??
messageReaction?.messageId ??
messageReactionCount?.messageId ??
callbackQuery?.message?.messageId;
return __msgId;
}

/// The Message ID of the incoming message.
int? get messageId => _msgId;

/// (Internal) Inline Message ID
///
/// Populated when `inlineMessageId` is first accessed.
String? __inlineMsgId;

/// Internal getter for inline message id
String? get _inlineMsgId {
return callbackQuery?.inlineMessageId ??
chosenInlineResult?.inlineMessageId;
if (__inlineMsgId != null) return __inlineMsgId;

__inlineMsgId =
callbackQuery?.inlineMessageId ?? chosenInlineResult?.inlineMessageId;
return __inlineMsgId;
}

/// Inline Message ID from the incoming update.
6 changes: 5 additions & 1 deletion lib/src/televerse/context/properties.dart
Original file line number Diff line number Diff line change
@@ -5,7 +5,11 @@ extension ContextUpdateMerger on Context {
/// This is a shorthand getter for the [Message] recieved in the current context
///
/// This can either be `Message` or `Channel Post` or `Edited Message` or `Edited Channel Post` or `Callback Query Message`.
Message? get msg => update.msg;
Message? get msg {
if (__msg != null) return __msg;
__msg = update.msg;
return __msg;
}

/// The incoming message.
Message? get message => update.message;