mirror of
https://github.com/vicliu624/trail-mate.git
synced 2026-09-25 13:13:37 +00:00
fix(chat): make send feedback event driven
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
#include "ui_chat_runtime/chat_delivery_feedback_controller.h"
|
||||
|
||||
namespace ui_chat_runtime
|
||||
{
|
||||
|
||||
ChatDeliveryFeedbackController::ChatDeliveryFeedbackController(
|
||||
IChatDeliveryFeedbackPort& port)
|
||||
: port_(port)
|
||||
{
|
||||
}
|
||||
|
||||
void ChatDeliveryFeedbackController::onChatSendResult(
|
||||
chat::MessageId msg_id,
|
||||
bool success,
|
||||
const chat::ChatMessage* message)
|
||||
{
|
||||
if (msg_id == 0 || message == nullptr || message->from != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (alreadyNotified(msg_id, success))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
remember(msg_id, success);
|
||||
if (success)
|
||||
{
|
||||
port_.showChatDeliverySent(msg_id);
|
||||
return;
|
||||
}
|
||||
port_.showChatDeliveryFailed(msg_id);
|
||||
}
|
||||
|
||||
void ChatDeliveryFeedbackController::clear()
|
||||
{
|
||||
for (auto& item : recent_)
|
||||
{
|
||||
item = RecentResult{};
|
||||
}
|
||||
next_recent_ = 0;
|
||||
}
|
||||
|
||||
bool ChatDeliveryFeedbackController::alreadyNotified(chat::MessageId msg_id,
|
||||
bool success) const
|
||||
{
|
||||
for (const auto& item : recent_)
|
||||
{
|
||||
if (item.msg_id == msg_id && item.success == success)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ChatDeliveryFeedbackController::remember(chat::MessageId msg_id,
|
||||
bool success)
|
||||
{
|
||||
recent_[next_recent_] = RecentResult{msg_id, success};
|
||||
next_recent_ = (next_recent_ + 1) %
|
||||
(sizeof(recent_) / sizeof(recent_[0]));
|
||||
}
|
||||
|
||||
} // namespace ui_chat_runtime
|
||||
Reference in New Issue
Block a user