Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions 30 include/tgbot/EventBroadcaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "tgbot/types/PollAnswer.h"
#include "tgbot/types/ChatMemberUpdated.h"
#include "tgbot/types/ChatJoinRequest.h"
#include "tgbot/types/MessageReactionUpdated.h"
#include "tgbot/types/MessageReactionCountUpdated.h"
#include "tgbot/types/SuccessfulPayment.h"

#include <functional>
Expand Down Expand Up @@ -44,6 +46,8 @@ friend EventHandler;
typedef std::function<void (const PollAnswer::Ptr)> PollAnswerListener;
typedef std::function<void (const ChatMemberUpdated::Ptr)> ChatMemberUpdatedListener;
typedef std::function<void (const ChatJoinRequest::Ptr)> ChatJoinRequestListener;
typedef std::function<void (const MessageReactionUpdated::Ptr)> MessageReactionUpdatedListener;
typedef std::function<void (const MessageReactionCountUpdated::Ptr)> MessageReactionCountUpdatedListener;
typedef std::function<void (const Message::Ptr, const SuccessfulPayment::Ptr)> SuccessfulPaymentListener;

/**
Expand Down Expand Up @@ -204,6 +208,22 @@ friend EventHandler;
_onChatJoinRequestListeners.push_back(listener);
}

/**
* @brief Registers listener which receives new incoming message reaction update event.
* @param listener Listener.
*/
inline void onMessageReaction(const MessageReactionUpdatedListener& listener) {
_onMessageReactionUpdatedListener.push_back(listener);
}

/**
* @brief Registers listener which receives new incoming message reaction count update event.
* @param listener Listener.
*/
inline void onMessageReactionCount(const MessageReactionCountUpdatedListener& listener) {
_onMessageReactionCountUpdatedListener.push_back(listener);
}

/**
* @brief Registers listener which receives information about successful payments.
* This listener is triggered when a successful payment is received by the bot.
Expand Down Expand Up @@ -293,6 +313,14 @@ friend EventHandler;
broadcast<ChatJoinRequestListener, ChatJoinRequest::Ptr>(_onChatJoinRequestListeners, result);
}

inline void broadcastMessageReactionUpdated(const MessageReactionUpdated::Ptr& messageReaction) const {
broadcast<MessageReactionUpdatedListener, MessageReactionUpdated::Ptr>(_onMessageReactionUpdatedListener, messageReaction);
}

inline void broadcastMessageReactionCountUpdated(const MessageReactionCountUpdated::Ptr& messageReactionCount) const {
broadcast<MessageReactionCountUpdatedListener, MessageReactionCountUpdated::Ptr>(_onMessageReactionCountUpdatedListener, messageReactionCount);
}

inline void broadcastSuccessfulPayment(const Message::Ptr& message) const {
if (!message || !message->successfulPayment) {
return;
Expand All @@ -318,6 +346,8 @@ friend EventHandler;
std::vector<ChatMemberUpdatedListener> _onMyChatMemberListeners;
std::vector<ChatMemberUpdatedListener> _onChatMemberListeners;
std::vector<ChatJoinRequestListener> _onChatJoinRequestListeners;
std::vector<MessageReactionUpdatedListener> _onMessageReactionUpdatedListener;
std::vector<MessageReactionCountUpdatedListener> _onMessageReactionCountUpdatedListener;
std::vector<SuccessfulPaymentListener> _onSuccessfulPaymentListeners;

};
Expand Down
6 changes: 6 additions & 0 deletions 6 src/EventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ void EventHandler::handleUpdate(const Update::Ptr& update) const {
if (update->chatJoinRequest != nullptr) {
_broadcaster.broadcastChatJoinRequest(update->chatJoinRequest);
}
if (update->messageReaction != nullptr) {
_broadcaster.broadcastMessageReactionUpdated(update->messageReaction);
}
if (update->messageReactionCount != nullptr) {
_broadcaster.broadcastMessageReactionCountUpdated(update->messageReactionCount);
}
}

void EventHandler::handleMessage(const Message::Ptr& message) const {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.