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:
parent
9bc6ae57fa
commit
f8bdaac121
14
src/core.cpp
14
src/core.cpp
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user