From 210537c432003b71dfc40d3dddd72e137b49a672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D9=8EAhJ?= Date: Thu, 2 Nov 2023 14:10:02 +0330 Subject: [PATCH] fix peer id , improve getIdInternal --- .../Channel/MessageViewsChanged.php | 2 +- src/EventHandler/Channel/UpdateChannel.php | 4 +- .../Delete/DeleteChannelMessages.php | 3 +- src/EventHandler/Query/ButtonQuery.php | 1 - src/EventHandler/Story/StoryReaction.php | 2 +- .../Typing/SupergroupUserTyping.php | 3 +- src/EventHandler/User/Blocked.php | 2 +- src/MTProtoTools/PeerHandler.php | 64 ++++++++++--------- 8 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/EventHandler/Channel/MessageViewsChanged.php b/src/EventHandler/Channel/MessageViewsChanged.php index 945653e08..15430b6f1 100644 --- a/src/EventHandler/Channel/MessageViewsChanged.php +++ b/src/EventHandler/Channel/MessageViewsChanged.php @@ -38,7 +38,7 @@ final class MessageViewsChanged extends Update public function __construct(MTProto $API, array $rawMessageViews) { parent::__construct($API); - $this->chatId = DialogId::fromSupergroupOrChannel($rawMessageViews['channel_id']); + $this->chatId = $API->getIdInternal($rawMessageViews); $this->id = $rawMessageViews['id']; $this->views = $rawMessageViews['views']; } diff --git a/src/EventHandler/Channel/UpdateChannel.php b/src/EventHandler/Channel/UpdateChannel.php index 2fbb65278..045b19392 100644 --- a/src/EventHandler/Channel/UpdateChannel.php +++ b/src/EventHandler/Channel/UpdateChannel.php @@ -29,9 +29,9 @@ final class UpdateChannel extends Update public readonly int $chatId; /** @internal */ - public function __construct(MTProto $API, array $rawMessageViews) + public function __construct(MTProto $API, array $rawUpdateChannel) { parent::__construct($API); - $this->chatId = DialogId::fromSupergroupOrChannel($rawMessageViews['channel_id']); + $this->chatId = $API->getIdInternal($rawUpdateChannel); } } diff --git a/src/EventHandler/Delete/DeleteChannelMessages.php b/src/EventHandler/Delete/DeleteChannelMessages.php index 9b29648a2..e62bfc145 100644 --- a/src/EventHandler/Delete/DeleteChannelMessages.php +++ b/src/EventHandler/Delete/DeleteChannelMessages.php @@ -18,7 +18,6 @@ namespace danog\MadelineProto\EventHandler\Delete; use danog\MadelineProto\MTProto; use danog\MadelineProto\EventHandler\Delete; -use danog\MadelineProto\MTProtoTools\DialogId; /** * Some messages in a [supergroup/channel](https://core.telegram.org/api/channel) were deleted. @@ -32,6 +31,6 @@ final class DeleteChannelMessages extends Delete public function __construct(MTProto $API, array $rawDelete) { parent::__construct($API, $rawDelete); - $this->chatId = DialogId::fromSupergroupOrChannel($rawDelete['channel_id']); + $this->chatId = $API->getIdInternal($rawDelete); } } diff --git a/src/EventHandler/Query/ButtonQuery.php b/src/EventHandler/Query/ButtonQuery.php index 78a50b5ab..f11702f63 100644 --- a/src/EventHandler/Query/ButtonQuery.php +++ b/src/EventHandler/Query/ButtonQuery.php @@ -17,7 +17,6 @@ namespace danog\MadelineProto\EventHandler\Query; use danog\MadelineProto\EventHandler\CallbackQuery; -use danog\MadelineProto\EventHandler\Query; use danog\MadelineProto\MTProto; use danog\MadelineProto\TL\Types\Bytes; use ReflectionClass; diff --git a/src/EventHandler/Story/StoryReaction.php b/src/EventHandler/Story/StoryReaction.php index 56da92a33..84c62f6da 100644 --- a/src/EventHandler/Story/StoryReaction.php +++ b/src/EventHandler/Story/StoryReaction.php @@ -36,7 +36,7 @@ final class StoryReaction extends Update public function __construct(MTProto $API, array $rawStory) { parent::__construct($API); - $this->senderId = $API->getIdInternal($rawStory['peer']); + $this->senderId = $API->getIdInternal($rawStory); $this->id = $rawStory['story_id']; $this->reaction = $rawStory['reaction']['emoticon'] ?? $rawStory['reaction']['document_id'] ?? null; } diff --git a/src/EventHandler/Typing/SupergroupUserTyping.php b/src/EventHandler/Typing/SupergroupUserTyping.php index 84043ded1..422366623 100644 --- a/src/EventHandler/Typing/SupergroupUserTyping.php +++ b/src/EventHandler/Typing/SupergroupUserTyping.php @@ -18,7 +18,6 @@ namespace danog\MadelineProto\EventHandler\Typing; use danog\MadelineProto\EventHandler\Typing; use danog\MadelineProto\MTProto; -use danog\MadelineProto\MTProtoTools\DialogId; /** * A user is typing in a [supergroup](https://core.telegram.org/api/channel). @@ -35,7 +34,7 @@ final class SupergroupUserTyping extends Typing public function __construct(MTProto $API, array $rawTyping) { parent::__construct($API, $rawTyping); - $this->chatId = DialogId::fromSupergroupOrChannel($rawTyping['channel_id']); + $this->chatId = $API->getIdInternal($rawTyping); $this->topicId = $rawTyping['top_msg_id'] ?? null; } } diff --git a/src/EventHandler/User/Blocked.php b/src/EventHandler/User/Blocked.php index c72f359fb..9bce03a38 100644 --- a/src/EventHandler/User/Blocked.php +++ b/src/EventHandler/User/Blocked.php @@ -39,6 +39,6 @@ final class Blocked extends Update parent::__construct($API); $this->blocked = $rawPeerBlocked['blocked']; $this->stories = $rawPeerBlocked['blocked_my_stories_from']; - $this->userId = $API->getIdInternal($rawPeerBlocked['peer_id']); + $this->userId = $API->getIdInternal($rawPeerBlocked); } } diff --git a/src/MTProtoTools/PeerHandler.php b/src/MTProtoTools/PeerHandler.php index 9c2869f1f..ea6fcb2f8 100644 --- a/src/MTProtoTools/PeerHandler.php +++ b/src/MTProtoTools/PeerHandler.php @@ -187,39 +187,31 @@ trait PeerHandler case 'updateDialogPinned': case 'updateDialogUnreadMark': case 'updateNotifySettings': - $id = $id['peer']; - // no break case 'updateDraftMessage': - case 'inputDialogPeer': - case 'dialogPeer': - case 'inputNotifyPeer': - case 'notifyPeer': - case 'dialog': - case 'help.proxyDataPromo': + case 'updateReadHistoryInbox': + case 'updateReadHistoryOutbox': case 'updateChatDefaultBannedRights': + case 'updateDeleteScheduledMessages': + case 'updateSentStoryReaction': + case 'updateBotCommands': + case 'updateBotChatInviteRequester': + case 'updatePendingJoinRequests': + case 'updateStory': + case 'dialog': + case 'dialogPeer': + case 'notifyPeer': + case 'help.proxyDataPromo': case 'folderPeer': + case 'inputDialogPeer': + case 'inputNotifyPeer': case 'inputFolderPeer': return $this->getIdInternal($id['peer']); - case 'inputUserFromMessage': - case 'inputPeerUserFromMessage': - return $id['user_id']; - case 'inputChannelFromMessage': - case 'inputPeerChannelFromMessage': - case 'updateChannelParticipant': - return DialogId::fromSupergroupOrChannel($id['channel_id']); case 'inputUserSelf': case 'inputPeerSelf': return $this->authorization['user']['id']; case 'user': - return $id['id']; case 'userFull': return $id['id']; - case 'inputPeerUser': - case 'inputUser': - case 'peerUser': - case 'messageEntityMentionName': - case 'messageActionChatDeleteUser': - return $id['user_id']; case 'messageActionChatJoinedByLink': return $id['inviter_id']; case 'chat': @@ -233,10 +225,7 @@ trait PeerHandler case 'channel': case 'channelFull': return DialogId::fromSupergroupOrChannel($id['id']); - case 'inputPeerChannel': - case 'inputChannel': - case 'peerChannel': - return DialogId::fromSupergroupOrChannel($id['channel_id']); + case 'updatePeerBlocked': case 'message': case 'messageService': if (!isset($id['from_id']) // No other option @@ -248,6 +237,11 @@ trait PeerHandler return $this->getIdInternal($id['peer_id']); } return $this->getIdInternal($id['from_id']); + case 'peerChannel': + case 'inputChannel': + case 'inputPeerChannel': + case 'inputChannelFromMessage': + case 'inputPeerChannelFromMessage': case 'updateChannelReadMessagesContents': case 'updateChannelAvailableMessages': case 'updateChannel': @@ -258,6 +252,10 @@ trait PeerHandler case 'updateDeleteChannelMessages': case 'updateChannelPinnedMessage': case 'updateChannelTooLong': + case 'updateChannelParticipant': + case 'updatePinnedChannelMessages': + case 'updateChannelMessageForwards': + case 'updateChannelUserTyping': return DialogId::fromSupergroupOrChannel($id['channel_id']); case 'updateChatParticipants': $id = $id['participants']; @@ -269,6 +267,7 @@ trait PeerHandler case 'updateChatAdmins': case 'updateChatPinnedMessage': return -$id['chat_id']; + case 'contact': case 'updateUserTyping': case 'updateUserStatus': case 'updateUserName': @@ -285,13 +284,18 @@ trait PeerHandler case 'updateBotShippingQuery': case 'updateUserPinnedMessage': case 'updateUser': - case 'contact': + case 'updateUserEmojiStatus': + case 'updateBotStopped': + case 'inputUserFromMessage': + case 'inputPeerUserFromMessage': + case 'inputPeerUser': + case 'inputUser': + case 'peerUser': + case 'messageEntityMentionName': + case 'messageActionChatDeleteUser': return $id['user_id']; case 'updatePhoneCall': return $id['phone_call']->getOtherID(); - case 'updateReadHistoryInbox': - case 'updateReadHistoryOutbox': - return $this->getIdInternal($id['peer']); case 'updateNewMessage': case 'updateNewChannelMessage': case 'updateEditMessage':