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)
|
||||
{
|
||||
emit static_cast<Core*>(core)->receiptRecieved(friendId, receipt);
|
||||
emit static_cast<Core*>(core)->receiptRecieved(friendId, receipt);
|
||||
}
|
||||
|
||||
void Core::acceptFriendRequest(const QString& userId)
|
||||
|
@ -643,35 +643,31 @@ void Core::sendTyping(uint32_t friendId, bool 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);
|
||||
|
||||
for (auto &cMsg :cMessages)
|
||||
{
|
||||
TOX_ERR_CONFERENCE_SEND_MESSAGE error;
|
||||
|
||||
bool success = tox_conference_send_message(tox, groupId, TOX_MESSAGE_TYPE_NORMAL,
|
||||
bool success = tox_conference_send_message(tox, groupId, type,
|
||||
cMsg.data(), cMsg.size(), &error);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
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)
|
||||
{
|
||||
QList<CString> cMessages = splitMessage(message, MAX_GROUP_MESSAGE_LEN);
|
||||
|
||||
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);
|
||||
}
|
||||
sendGroupMessageWithType(groupId, message, TOX_MESSAGE_TYPE_ACTION);
|
||||
}
|
||||
|
||||
void Core::changeGroupTitle(int groupId, const QString& title)
|
||||
|
|
|
@ -112,11 +112,11 @@ public slots:
|
|||
void setStatusMessage(const QString& message);
|
||||
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 sendGroupAction(int groupId, const QString& message);
|
||||
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 sendAvatarFile(uint32_t friendId, const QByteArray& data);
|
||||
|
@ -224,6 +224,7 @@ private:
|
|||
static void onReadReceiptCallback(Tox* tox, uint32_t friendId,
|
||||
uint32_t receipt, void *core);
|
||||
|
||||
void sendGroupMessageWithType(int groupId, const QString& message, TOX_MESSAGE_TYPE type);
|
||||
bool checkConnection();
|
||||
|
||||
void checkEncryptedHistory();
|
||||
|
|
Loading…
Reference in New Issue
Block a user