messages->deleteMessages() not deleting message in some types of groups
Closed this issue · 2 comments
UlrichBoehm commented
Description
When using $this->messages->deleteMessages(revoke: true, id: [$message->id])
within handleMessage()
the message is not deleted as soon as the group where the message is in is a modified group.
Reproduction
working part
- create a new group (default settings, no modifications)
- add user as admin with rights to delete messages
- add code from description
- write a message with a second user
- message gets deleted!
not working part
- now modify the group (set
Chat history for new members
to fromHidden
toVisible
) - save changes
- write a message with a second user
- message stays in chat!
Piagrammist commented
Changing the visibility of chat history in a freshly made group will convert it into a supergroup, which is considered to be a channel! You have to use channels.deleteMessages()
to delete any message in a supergroup/channel.
Here's a basic method to simplify the process:
use danog\DialogId\DialogId;
// EventHandler
protected function deleteMessages(int $chatId, array $ids, bool $revoke = true): array
{
if (DialogId::isSupergroupOrChannel($chatId)) {
return $this->channels->deleteMessages(channel: $chatId, id: $ids);
}
return $this->messages->deleteMessages(revoke: $revoke, id: $ids);
}
Please close the issue if this resolved your problem.
danog commented
You don't need this complex logic, you just have to use $message->delete(), which automatically chooses the correct method to use for you.