mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(core): Remove code duplication for different types of messages
This commit is contained in:
parent
d371e78871
commit
98fa64f841
|
@ -552,7 +552,7 @@ void Core::onGroupTitleChange(Tox*, uint32_t groupId, uint32_t peerId,
|
||||||
|
|
||||||
void Core::onReadReceiptCallback(Tox*, uint32_t friendId, uint32_t receipt, void *core)
|
void Core::onReadReceiptCallback(Tox*, uint32_t friendId, uint32_t receipt, void *core)
|
||||||
{
|
{
|
||||||
emit static_cast<Core*>(core)->receiptRecieved(friendId, receipt);
|
emit static_cast<Core*>(core)->receiptRecieved(friendId, receipt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::acceptFriendRequest(const QString& userId)
|
void Core::acceptFriendRequest(const QString& userId)
|
||||||
|
@ -643,35 +643,31 @@ void Core::sendTyping(uint32_t friendId, bool typing)
|
||||||
emit failedToSetTyping(typing);
|
emit failedToSetTyping(typing);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::sendGroupMessage(int groupId, const QString& message)
|
void Core::sendGroupMessageWithType(int groupId, const QString &message, TOX_MESSAGE_TYPE type)
|
||||||
{
|
{
|
||||||
QList<CString> cMessages = splitMessage(message, MAX_GROUP_MESSAGE_LEN);
|
QList<CString> cMessages = splitMessage(message, MAX_GROUP_MESSAGE_LEN);
|
||||||
|
|
||||||
for (auto &cMsg :cMessages)
|
for (auto &cMsg :cMessages)
|
||||||
{
|
{
|
||||||
TOX_ERR_CONFERENCE_SEND_MESSAGE error;
|
TOX_ERR_CONFERENCE_SEND_MESSAGE error;
|
||||||
|
bool success = tox_conference_send_message(tox, groupId, type,
|
||||||
bool success = tox_conference_send_message(tox, groupId, TOX_MESSAGE_TYPE_NORMAL,
|
|
||||||
cMsg.data(), cMsg.size(), &error);
|
cMsg.data(), cMsg.size(), &error);
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
|
{
|
||||||
emit groupSentResult(groupId, message, -1);
|
emit groupSentResult(groupId, message, -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Core::sendGroupMessage(int groupId, const QString& message)
|
||||||
|
{
|
||||||
|
sendGroupMessageWithType(groupId, message, TOX_MESSAGE_TYPE_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
void Core::sendGroupAction(int groupId, const QString& message)
|
void Core::sendGroupAction(int groupId, const QString& message)
|
||||||
{
|
{
|
||||||
QList<CString> cMessages = splitMessage(message, MAX_GROUP_MESSAGE_LEN);
|
sendGroupMessageWithType(groupId, message, TOX_MESSAGE_TYPE_ACTION);
|
||||||
|
|
||||||
for (auto &cMsg :cMessages)
|
|
||||||
{
|
|
||||||
TOX_ERR_CONFERENCE_SEND_MESSAGE error;
|
|
||||||
bool success = tox_conference_send_message(tox, groupId, TOX_MESSAGE_TYPE_ACTION,
|
|
||||||
cMsg.data(), cMsg.size(), &error);
|
|
||||||
|
|
||||||
if (!success)
|
|
||||||
emit groupSentResult(groupId, message, -1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::changeGroupTitle(int groupId, const QString& title)
|
void Core::changeGroupTitle(int groupId, const QString& title)
|
||||||
|
|
|
@ -112,11 +112,11 @@ public slots:
|
||||||
void setStatusMessage(const QString& message);
|
void setStatusMessage(const QString& message);
|
||||||
void setAvatar(const QByteArray& data);
|
void setAvatar(const QByteArray& data);
|
||||||
|
|
||||||
int sendMessage(uint32_t friendId, const QString& message);
|
int sendMessage(uint32_t friendId, const QString& message);
|
||||||
void sendGroupMessage(int groupId, const QString& message);
|
void sendGroupMessage(int groupId, const QString& message);
|
||||||
void sendGroupAction(int groupId, const QString& message);
|
void sendGroupAction(int groupId, const QString& message);
|
||||||
void changeGroupTitle(int groupId, const QString& title);
|
void changeGroupTitle(int groupId, const QString& title);
|
||||||
int sendAction(uint32_t friendId, const QString& action);
|
int sendAction(uint32_t friendId, const QString& action);
|
||||||
void sendTyping(uint32_t friendId, bool typing);
|
void sendTyping(uint32_t friendId, bool typing);
|
||||||
|
|
||||||
void sendAvatarFile(uint32_t friendId, const QByteArray& data);
|
void sendAvatarFile(uint32_t friendId, const QByteArray& data);
|
||||||
|
@ -224,6 +224,7 @@ private:
|
||||||
static void onReadReceiptCallback(Tox* tox, uint32_t friendId,
|
static void onReadReceiptCallback(Tox* tox, uint32_t friendId,
|
||||||
uint32_t receipt, void *core);
|
uint32_t receipt, void *core);
|
||||||
|
|
||||||
|
void sendGroupMessageWithType(int groupId, const QString& message, TOX_MESSAGE_TYPE type);
|
||||||
bool checkConnection();
|
bool checkConnection();
|
||||||
|
|
||||||
void checkEncryptedHistory();
|
void checkEncryptedHistory();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user