1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

messages splitting fix

This commit is contained in:
apprb 2014-12-28 23:26:35 +06:00
parent 9bc6ae57fa
commit f8bdaac121
No known key found for this signature in database
GPG Key ID: B001911B5B22FB9B
3 changed files with 10 additions and 8 deletions

View File

@ -49,6 +49,8 @@ QList<ToxFile> Core::fileRecvQueue;
QHash<int, ToxGroupCall> Core::groupCalls;
QThread* Core::coreThread{nullptr};
#define MAX_GROUP_MESSAGE_LEN 1024
Core::Core(Camera* cam, QThread *CoreThread, QString loadPath) :
tox(nullptr), camera(cam), loadPath(loadPath), ready{false}
{
@ -779,7 +781,7 @@ void Core::sendTyping(int friendId, bool typing)
void Core::sendGroupMessage(int groupId, const QString& message)
{
QList<CString> cMessages = splitMessage(message);
QList<CString> cMessages = splitMessage(message, MAX_GROUP_MESSAGE_LEN);
for (auto &cMsg :cMessages)
{
@ -792,7 +794,7 @@ void Core::sendGroupMessage(int groupId, const QString& message)
void Core::sendGroupAction(int groupId, const QString& message)
{
QList<CString> cMessages = splitMessage(message);
QList<CString> cMessages = splitMessage(message, MAX_GROUP_MESSAGE_LEN);
for (auto &cMsg :cMessages)
{
@ -1741,17 +1743,17 @@ QString Core::getFriendUsername(int friendnumber) const
return CString::toString(name, tox_get_name_size(tox, friendnumber));
}
QList<CString> Core::splitMessage(const QString &message)
QList<CString> Core::splitMessage(const QString &message, int maxLen)
{
QList<CString> splittedMsgs;
QByteArray ba_message(message.toUtf8());
while (ba_message.size() > TOX_MAX_MESSAGE_LENGTH)
while (ba_message.size() > maxLen)
{
int splitPos = ba_message.lastIndexOf(' ', TOX_MAX_MESSAGE_LENGTH - 1);
int splitPos = ba_message.lastIndexOf(' ', maxLen - 1);
if (splitPos <= 0)
{
splitPos = TOX_MAX_MESSAGE_LENGTH;
splitPos = maxLen;
if (ba_message[splitPos] & 0x80)
{
do {

View File

@ -50,7 +50,7 @@ public:
static const QString TOX_EXT;
static const QString CONFIG_FILE_NAME;
static QString sanitize(QString name);
static QList<CString> splitMessage(const QString &message);
static QList<CString> splitMessage(const QString &message, int maxLen);
QString getPeerName(const ToxID& id) const;

View File

@ -103,7 +103,7 @@ void ChatForm::onSendTriggered()
if (isAction)
msg = msg = msg.right(msg.length() - 4);
QList<CString> splittedMsg = Core::splitMessage(msg);
QList<CString> splittedMsg = Core::splitMessage(msg, TOX_MAX_MESSAGE_LENGTH);
QDateTime timestamp = QDateTime::currentDateTime();
for (CString& c_msg : splittedMsg)