mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(core): add send message error handling
remove unused sendMessageResult signal
This commit is contained in:
parent
5b83667aba
commit
5289c99962
|
@ -62,6 +62,62 @@ namespace {
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool parseFriendSendMessageError(Tox_Err_Friend_Send_Message error)
|
||||||
|
{
|
||||||
|
switch (error) {
|
||||||
|
case TOX_ERR_FRIEND_SEND_MESSAGE_OK:
|
||||||
|
return true;
|
||||||
|
case TOX_ERR_FRIEND_SEND_MESSAGE_NULL:
|
||||||
|
qCritical() << "Send friend message passed an unexpected null argument";
|
||||||
|
return false;
|
||||||
|
case TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_FOUND:
|
||||||
|
qCritical() << "Send friend message could not find friend";
|
||||||
|
return false;
|
||||||
|
case TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_CONNECTED:
|
||||||
|
qCritical() << "Send friend message: friend is offline";
|
||||||
|
return false;
|
||||||
|
case TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ:
|
||||||
|
qCritical() << "Failed to allocate more message queue";
|
||||||
|
return false;
|
||||||
|
case TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG:
|
||||||
|
qCritical() << "Attemped to send message that's too long";
|
||||||
|
return false;
|
||||||
|
case TOX_ERR_FRIEND_SEND_MESSAGE_EMPTY:
|
||||||
|
qCritical() << "Attempted to send an empty message";
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
qCritical() << "Unknown friend send message error:" << static_cast<int>(error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parseConferenceSendMessageError(Tox_Err_Conference_Send_Message error)
|
||||||
|
{
|
||||||
|
switch (error) {
|
||||||
|
case TOX_ERR_CONFERENCE_SEND_MESSAGE_OK:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case TOX_ERR_CONFERENCE_SEND_MESSAGE_CONFERENCE_NOT_FOUND:
|
||||||
|
qCritical() << "Conference not found";
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case TOX_ERR_CONFERENCE_SEND_MESSAGE_FAIL_SEND:
|
||||||
|
qCritical() << "Conference message failed to send";
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case TOX_ERR_CONFERENCE_SEND_MESSAGE_NO_CONNECTION:
|
||||||
|
qCritical() << "No connection";
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case TOX_ERR_CONFERENCE_SEND_MESSAGE_TOO_LONG:
|
||||||
|
qCritical() << "Message too long";
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
qCritical() << "Unknown Tox_Err_Conference_Send_Message error:" << static_cast<int>(error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Core::Core(QThread* coreThread)
|
Core::Core(QThread* coreThread)
|
||||||
|
@ -600,24 +656,33 @@ void Core::requestFriendship(const ToxId& friendId, const QString& message)
|
||||||
emit saveRequest();
|
emit saveRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Core::sendMessageWithType(uint32_t friendId, const QString& message, Tox_Message_Type type)
|
||||||
|
{
|
||||||
|
int size = message.toUtf8().size();
|
||||||
|
auto maxSize = tox_max_message_length();
|
||||||
|
if (size > maxSize) {
|
||||||
|
qCritical() << "Core::sendMessageWithType called with message of size:" << size << "when max is:" << maxSize <<". Ignoring.";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ToxString cMessage(message);
|
||||||
|
Tox_Err_Friend_Send_Message error;
|
||||||
|
int receipt = tox_friend_send_message(tox.get(), friendId, type,
|
||||||
|
cMessage.data(), cMessage.size(), &error);
|
||||||
|
parseFriendSendMessageError(error);
|
||||||
|
return receipt;
|
||||||
|
}
|
||||||
|
|
||||||
int Core::sendMessage(uint32_t friendId, const QString& message)
|
int Core::sendMessage(uint32_t friendId, const QString& message)
|
||||||
{
|
{
|
||||||
QMutexLocker ml(coreLoopLock.get());
|
QMutexLocker ml(coreLoopLock.get());
|
||||||
ToxString cMessage(message);
|
return sendMessageWithType(friendId, message, TOX_MESSAGE_TYPE_NORMAL);
|
||||||
int receipt = tox_friend_send_message(tox.get(), friendId, TOX_MESSAGE_TYPE_NORMAL,
|
|
||||||
cMessage.data(), cMessage.size(), nullptr);
|
|
||||||
emit messageSentResult(friendId, message, receipt);
|
|
||||||
return receipt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Core::sendAction(uint32_t friendId, const QString& action)
|
int Core::sendAction(uint32_t friendId, const QString& action)
|
||||||
{
|
{
|
||||||
QMutexLocker ml(coreLoopLock.get());
|
QMutexLocker ml(coreLoopLock.get());
|
||||||
ToxString cMessage(action);
|
return sendMessageWithType(friendId, action, TOX_MESSAGE_TYPE_ACTION);
|
||||||
int receipt = tox_friend_send_message(tox.get(), friendId, TOX_MESSAGE_TYPE_ACTION,
|
|
||||||
cMessage.data(), cMessage.size(), nullptr);
|
|
||||||
emit messageSentResult(friendId, action, receipt);
|
|
||||||
return receipt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::sendTyping(uint32_t friendId, bool typing)
|
void Core::sendTyping(uint32_t friendId, bool typing)
|
||||||
|
@ -629,34 +694,6 @@ void Core::sendTyping(uint32_t friendId, bool typing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parseConferenceSendMessageError(Tox_Err_Conference_Send_Message error)
|
|
||||||
{
|
|
||||||
switch (error) {
|
|
||||||
case TOX_ERR_CONFERENCE_SEND_MESSAGE_OK:
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case TOX_ERR_CONFERENCE_SEND_MESSAGE_CONFERENCE_NOT_FOUND:
|
|
||||||
qCritical() << "Conference not found";
|
|
||||||
return false;
|
|
||||||
|
|
||||||
case TOX_ERR_CONFERENCE_SEND_MESSAGE_FAIL_SEND:
|
|
||||||
qCritical() << "Conference message failed to send";
|
|
||||||
return false;
|
|
||||||
|
|
||||||
case TOX_ERR_CONFERENCE_SEND_MESSAGE_NO_CONNECTION:
|
|
||||||
qCritical() << "No connection";
|
|
||||||
return false;
|
|
||||||
|
|
||||||
case TOX_ERR_CONFERENCE_SEND_MESSAGE_TOO_LONG:
|
|
||||||
qCritical() << "Message too long";
|
|
||||||
return false;
|
|
||||||
|
|
||||||
default:
|
|
||||||
qCritical() << "Unknown Tox_Err_Conference_Send_Message error";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Core::sendGroupMessageWithType(int groupId, const QString& message, Tox_Message_Type type)
|
void Core::sendGroupMessageWithType(int groupId, const QString& message, Tox_Message_Type type)
|
||||||
{
|
{
|
||||||
QMutexLocker ml{coreLoopLock.get()};
|
QMutexLocker ml{coreLoopLock.get()};
|
||||||
|
|
|
@ -197,8 +197,6 @@ signals:
|
||||||
void groupPeerNameChanged(int groupnumber, int peernumber, const QString& newName);
|
void groupPeerNameChanged(int groupnumber, int peernumber, const QString& newName);
|
||||||
void groupTitleChanged(int groupnumber, const QString& author, const QString& title);
|
void groupTitleChanged(int groupnumber, const QString& author, const QString& title);
|
||||||
void groupPeerAudioPlaying(int groupnumber, int peernumber);
|
void groupPeerAudioPlaying(int groupnumber, int peernumber);
|
||||||
|
|
||||||
void messageSentResult(uint32_t friendId, const QString& message, int messageId);
|
|
||||||
void groupSentFailed(int groupId);
|
void groupSentFailed(int groupId);
|
||||||
void actionSentResult(uint32_t friendId, const QString& action, int success);
|
void actionSentResult(uint32_t friendId, const QString& action, int success);
|
||||||
|
|
||||||
|
@ -236,6 +234,7 @@ private:
|
||||||
static void onReadReceiptCallback(Tox* tox, uint32_t friendId, uint32_t receipt, void* core);
|
static void onReadReceiptCallback(Tox* tox, uint32_t friendId, uint32_t receipt, void* core);
|
||||||
|
|
||||||
void sendGroupMessageWithType(int groupId, const QString& message, Tox_Message_Type type);
|
void sendGroupMessageWithType(int groupId, const QString& message, Tox_Message_Type type);
|
||||||
|
int sendMessageWithType(uint32_t friendId, const QString& message, Tox_Message_Type type);
|
||||||
bool parsePeerQueryError(Tox_Err_Conference_Peer_Query error) const;
|
bool parsePeerQueryError(Tox_Err_Conference_Peer_Query error) const;
|
||||||
bool parseConferenceJoinError(Tox_Err_Conference_Join error) const;
|
bool parseConferenceJoinError(Tox_Err_Conference_Join error) const;
|
||||||
bool checkConnection();
|
bool checkConnection();
|
||||||
|
|
|
@ -211,7 +211,6 @@ void Nexus::showMainGUI()
|
||||||
connect(core, &Core::groupPeerAudioPlaying, widget, &Widget::onGroupPeerAudioPlaying);
|
connect(core, &Core::groupPeerAudioPlaying, widget, &Widget::onGroupPeerAudioPlaying);
|
||||||
connect(core, &Core::emptyGroupCreated, widget, &Widget::onEmptyGroupCreated);
|
connect(core, &Core::emptyGroupCreated, widget, &Widget::onEmptyGroupCreated);
|
||||||
connect(core, &Core::friendTypingChanged, widget, &Widget::onFriendTypingChanged);
|
connect(core, &Core::friendTypingChanged, widget, &Widget::onFriendTypingChanged);
|
||||||
connect(core, &Core::messageSentResult, widget, &Widget::onMessageSendResult);
|
|
||||||
connect(core, &Core::groupSentFailed, widget, &Widget::onGroupSendFailed);
|
connect(core, &Core::groupSentFailed, widget, &Widget::onGroupSendFailed);
|
||||||
connect(core, &Core::usernameSet, widget, &Widget::refreshPeerListsLocal);
|
connect(core, &Core::usernameSet, widget, &Widget::refreshPeerListsLocal);
|
||||||
|
|
||||||
|
|
|
@ -2075,16 +2075,6 @@ void Widget::setStatusBusy()
|
||||||
Nexus::getCore()->setStatus(Status::Busy);
|
Nexus::getCore()->setStatus(Status::Busy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::onMessageSendResult(uint32_t friendId, const QString& message, int messageId)
|
|
||||||
{
|
|
||||||
Q_UNUSED(message)
|
|
||||||
Q_UNUSED(messageId)
|
|
||||||
Friend* f = FriendList::findFriend(friendId);
|
|
||||||
if (!f) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Widget::onGroupSendFailed(int groupId)
|
void Widget::onGroupSendFailed(int groupId)
|
||||||
{
|
{
|
||||||
Group* g = GroupList::findGroup(groupId);
|
Group* g = GroupList::findGroup(groupId);
|
||||||
|
|
|
@ -167,7 +167,6 @@ public slots:
|
||||||
void onFriendMessageReceived(int friendId, const QString& message, bool isAction);
|
void onFriendMessageReceived(int friendId, const QString& message, bool isAction);
|
||||||
void onFriendRequestReceived(const ToxPk& friendPk, const QString& message);
|
void onFriendRequestReceived(const ToxPk& friendPk, const QString& message);
|
||||||
void updateFriendActivity(const Friend* frnd);
|
void updateFriendActivity(const Friend* frnd);
|
||||||
void onMessageSendResult(uint32_t friendId, const QString& message, int messageId);
|
|
||||||
void onReceiptRecieved(int friendId, int receipt);
|
void onReceiptRecieved(int friendId, int receipt);
|
||||||
void onEmptyGroupCreated(int groupId, const QString& title);
|
void onEmptyGroupCreated(int groupId, const QString& title);
|
||||||
void onGroupInviteReceived(const GroupInvite& inviteInfo);
|
void onGroupInviteReceived(const GroupInvite& inviteInfo);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user