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

Add support for secret chat messages in the SimpleEventHandler! #1401

Closed
wants to merge 2 commits into from
Closed

Add support for secret chat messages in the SimpleEventHandler! #1401

wants to merge 2 commits into from

Conversation

mtalaeii
Copy link
Contributor

@mtalaeii mtalaeii commented Sep 3, 2023

  • Add Media types for DecryptedMedia
  • Separate PrivateMessage classes

- Add Media types for DecryptedMedia
- Separate PrivateMessage classes
@danog danog changed the title Add support for secret chats messages! Add support for secret chat messages in the SimpleEventHandler! Sep 5, 2023
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/

namespace danog\MadelineProto\EventHandler\Message\Private;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls don't change the namespace, put both SecretMessage and PrivateMessage in the Message namespace

@@ -132,6 +143,9 @@ public function wrapMedia(array $media, bool $protected = false): ?Media
if ($has_document_photo) {
return new DocumentPhoto($this, $media, $has_document_photo, $protected);
}
if ($media['_'] === 'decryptedMessageMediaDocument') {
return new Media\Decrypted\Document($this, $media, $protected);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that creating separate classes for secret media is not the way to go, instead we could just add some fields to the existing media classes that will only be populated in secret chats (i.e. fields that are not present for normal media)


final class SecretMessage extends AbstractPrivateMessage
{
/** Content of the message */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to duplicate these properties, we can just re-use the ones in privatemessage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot_20230906_160100
As these properties is readonly i cant rewrite it directly with out duplicate it in SecretMessage class and as private chat id is different from secret chat id again i cant include it in PrivateMessage class!!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, these properties are already present in PrivateMessage, they can be populated directly by the constructor of PrivateMessage, there's no need to populate them in SecretMessage.
The chatId is also present in AbstractMessage, it's just slightly different for secret chats (and in this case, the logic to handle the distinction can also be present in AbstractMessage)

{
parent::__construct($API, $rawMessage, $info);
$decryptedMessage = $rawMessage['decrypted_message'];
$this->chatId = $rawMessage['chat_id'];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->chatId = DialogId::fromSecretChatId($rawMessage['chat_id'])

and $this->senderId = $info['bot_api_id'];

@mtalaeii
Copy link
Contributor Author

mtalaeii commented Sep 5, 2023

I'm gonna to make this pr as draft as these days i have some stuff todos so please keep it open and dont close it.
I will fix it soon thanks!!

@mtalaeii mtalaeii marked this pull request as draft September 5, 2023 21:47
@mtalaeii mtalaeii closed this Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants