Skip to content

Commit

Permalink
Merge pull request #1450 from mtalaeii/v8
Browse files Browse the repository at this point in the history
Fix #1444
  • Loading branch information
danog authored Dec 15, 2023
2 parents 7194a59 + 6c5f566 commit f43782c
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/EventHandler/Query/ChatTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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,
]
);
}
}

0 comments on commit f43782c

Please sign in to comment.