Skip to content

Commit cbb1b33

Browse files
committed
feat: add message_reaction update and message_reaction_count update support
1 parent 39f7a8f commit cbb1b33

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

include/tgbot/EventBroadcaster.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "tgbot/types/PollAnswer.h"
1313
#include "tgbot/types/ChatMemberUpdated.h"
1414
#include "tgbot/types/ChatJoinRequest.h"
15+
#include "tgbot/types/MessageReactionUpdated.h"
16+
#include "tgbot/types/MessageReactionCountUpdated.h"
1517
#include "tgbot/types/SuccessfulPayment.h"
1618

1719
#include <functional>
@@ -44,6 +46,8 @@ friend EventHandler;
4446
typedef std::function<void (const PollAnswer::Ptr)> PollAnswerListener;
4547
typedef std::function<void (const ChatMemberUpdated::Ptr)> ChatMemberUpdatedListener;
4648
typedef std::function<void (const ChatJoinRequest::Ptr)> ChatJoinRequestListener;
49+
typedef std::function<void (const MessageReactionUpdated::Ptr)> MessageReactionUpdatedListener;
50+
typedef std::function<void (const MessageReactionCountUpdated::Ptr)> MessageReactionCountUpdatedListener;
4751
typedef std::function<void (const Message::Ptr, const SuccessfulPayment::Ptr)> SuccessfulPaymentListener;
4852

4953
/**
@@ -204,6 +208,22 @@ friend EventHandler;
204208
_onChatJoinRequestListeners.push_back(listener);
205209
}
206210

211+
/**
212+
* @brief Registers listener which receives new incoming message reaction update event.
213+
* @param listener Listener.
214+
*/
215+
inline void onMessageReaction(const MessageReactionUpdatedListener& listener) {
216+
_onMessageReactionUpdatedListener.push_back(listener);
217+
}
218+
219+
/**
220+
* @brief Registers listener which receives new incoming message reaction count update event.
221+
* @param listener Listener.
222+
*/
223+
inline void onMessageReactionCount(const MessageReactionCountUpdatedListener& listener) {
224+
_onMessageReactionCountUpdatedListener.push_back(listener);
225+
}
226+
207227
/**
208228
* @brief Registers listener which receives information about successful payments.
209229
* This listener is triggered when a successful payment is received by the bot.
@@ -293,6 +313,14 @@ friend EventHandler;
293313
broadcast<ChatJoinRequestListener, ChatJoinRequest::Ptr>(_onChatJoinRequestListeners, result);
294314
}
295315

316+
inline void broadcastMessageReactionUpdated(const MessageReactionUpdated::Ptr& messageReaction) const {
317+
broadcast<MessageReactionUpdatedListener, MessageReactionUpdated::Ptr>(_onMessageReactionUpdatedListener, messageReaction);
318+
}
319+
320+
inline void broadcastMessageReactionCountUpdated(const MessageReactionCountUpdated::Ptr& messageReactionCount) const {
321+
broadcast<MessageReactionCountUpdatedListener, MessageReactionCountUpdated::Ptr>(_onMessageReactionCountUpdatedListener, messageReactionCount);
322+
}
323+
296324
inline void broadcastSuccessfulPayment(const Message::Ptr& message) const {
297325
if (!message || !message->successfulPayment) {
298326
return;
@@ -318,6 +346,8 @@ friend EventHandler;
318346
std::vector<ChatMemberUpdatedListener> _onMyChatMemberListeners;
319347
std::vector<ChatMemberUpdatedListener> _onChatMemberListeners;
320348
std::vector<ChatJoinRequestListener> _onChatJoinRequestListeners;
349+
std::vector<MessageReactionUpdatedListener> _onMessageReactionUpdatedListener;
350+
std::vector<MessageReactionCountUpdatedListener> _onMessageReactionCountUpdatedListener;
321351
std::vector<SuccessfulPaymentListener> _onSuccessfulPaymentListeners;
322352

323353
};

src/EventHandler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ void EventHandler::handleUpdate(const Update::Ptr& update) const {
4545
if (update->chatJoinRequest != nullptr) {
4646
_broadcaster.broadcastChatJoinRequest(update->chatJoinRequest);
4747
}
48+
if (update->messageReaction != nullptr) {
49+
_broadcaster.broadcastMessageReactionUpdated(update->messageReaction);
50+
}
51+
if (update->messageReactionCount != nullptr) {
52+
_broadcaster.broadcastMessageReactionCountUpdated(update->messageReactionCount);
53+
}
4854
}
4955

5056
void EventHandler::handleMessage(const Message::Ptr& message) const {

0 commit comments

Comments
 (0)