From 6c5f56631789a1ca963713d708ff8b594f132f6c Mon Sep 17 00:00:00 2001 From: Mahdi Date: Fri, 15 Dec 2023 13:09:33 +0330 Subject: [PATCH] Fix #1444 - Add some bound method to ChatTrait trait --- src/EventHandler/Query/ChatTrait.php | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/EventHandler/Query/ChatTrait.php b/src/EventHandler/Query/ChatTrait.php index ea934597c9..f6c1b70047 100644 --- a/src/EventHandler/Query/ChatTrait.php +++ b/src/EventHandler/Query/ChatTrait.php @@ -17,7 +17,10 @@ namespace danog\MadelineProto\EventHandler\Query; use danog\MadelineProto\EventHandler\Message; +use danog\MadelineProto\EventHandler\Message\ReportReason; +use danog\MadelineProto\EventHandler\Update; use danog\MadelineProto\MTProto; +use danog\MadelineProto\MTProtoTools\DialogId; use danog\MadelineProto\ParseMode; /** @internal */ @@ -65,4 +68,81 @@ public function editText( ); return $this->getClient()->wrapMessage($this->getClient()->extractMessage($result)); } + + /** + * Delete the message. + * + * @param boolean $revoke Whether to delete the message for all participants of the chat. + */ + public function delete(bool $revoke = true): void + { + $this->getClient()->methodCallAsyncRead( + DialogId::isSupergroupOrChannel($this->chatId) ? 'channels.deleteMessages' : 'messages.deleteMessages', + [ + 'channel' => $this->chatId, + 'id' => [$this->messageId], + 'revoke' => $revoke, + ] + ); + } + + /** + * Pin a message. + * + * @param bool $pmOneside Whether the message should only be pinned on the local side of a one-to-one chat + * @param bool $silent Pin the message silently, without triggering a notification + */ + public function pin(bool $pmOneside = false, bool $silent = false): void + { + $this->getClient()->methodCallAsyncRead( + 'messages.updatePinnedMessage', + [ + 'peer' => $this->chatId, + 'id' => $this->messageId, + 'pm_oneside' => $pmOneside, + 'silent' => $silent, + 'unpin' => false, + ] + ); + } + + /** + * Unpin a message. + * + * @param bool $pmOneside Whether the message should only be pinned on the local side of a one-to-one chat + * @param bool $silent Pin the message silently, without triggering a notification + */ + public function unpin(bool $pmOneside = false, bool $silent = false): ?Update + { + $result = $this->getClient()->methodCallAsyncRead( + 'messages.updatePinnedMessage', + [ + 'peer' => $this->chatId, + 'id' => $this->messageId, + 'pm_oneside' => $pmOneside, + 'silent' => $silent, + 'unpin' => true, + ] + ); + return $this->getClient()->wrapUpdate($result); + } + + /** + * Report a message in a chat for violation of telegram’s Terms of Service. + * + * @param ReportReason $reason Why are these messages being reported + * @param string $message Comment for report moderation + */ + public function report(ReportReason $reason, string $message): bool + { + return $this->getClient()->methodCallAsyncRead( + 'messages.report', + [ + 'reason' => ['_' => $reason->value], + 'message' => $message, + 'id' => [$this->messageId], + 'peer' => $this->chatId, + ] + ); + } }