void GroupChatForm::onSendTriggered() { QString msg = msgEdit->toPlainText(); if (msg.isEmpty()) return; msgEdit->setLastMessage(msg); msgEdit->clear(); if (group->getPeersCount() != 1) { if (msg.startsWith("/me ", Qt::CaseInsensitive)) { msg = msg.right(msg.length() - 4); emit sendAction(group->getGroupId(), msg); } else { emit sendMessage(group->getGroupId(), msg); } } else { if (msg.startsWith("/me ", Qt::CaseInsensitive)) addSelfMessage(msg.right(msg.length() - 4), true, QDateTime::currentDateTime(), true); else addSelfMessage(msg, false, QDateTime::currentDateTime(), true); } }
void ChatForm::SendMessageStr(QString msg) { if (msg.isEmpty()) return; bool isAction = msg.startsWith(ACTION_PREFIX, Qt::CaseInsensitive); if (isAction) msg.remove(0, ACTION_PREFIX.length()); QList<CString> splittedMsg = Core::splitMessage(msg, TOX_MAX_MESSAGE_LENGTH); QDateTime timestamp = QDateTime::currentDateTime(); for (CString& c_msg : splittedMsg) { QString qt_msg = CString::toString(c_msg.data(), c_msg.size()); QString qt_msg_hist = qt_msg; if (isAction) qt_msg_hist = ACTION_PREFIX + qt_msg; bool status = !Settings::getInstance().getFauxOfflineMessaging(); ChatMessage::Ptr ma = addSelfMessage(qt_msg, isAction, timestamp, false); int rec; if (isAction) rec = Core::getInstance()->sendAction(f->getFriendID(), qt_msg); else rec = Core::getInstance()->sendMessage(f->getFriendID(), qt_msg); Profile* profile = Nexus::getProfile(); if (profile->isHistoryEnabled()) { auto* offMsgEngine = getOfflineMsgEngine(); profile->getHistory()->addNewMessage(f->getToxId().publicKey, qt_msg_hist, Core::getInstance()->getSelfId().publicKey, timestamp, status, Core::getInstance()->getUsername(), [offMsgEngine,rec,ma](int64_t id) { offMsgEngine->registerReceipt(rec, id, ma); }); } else { // TODO: Make faux-offline messaging work partially with the history disabled ma->markAsSent(QDateTime::currentDateTime()); } msgEdit->setLastMessage(msg); //set last message only when sending it Widget::getInstance()->updateFriendActivity(f); } }
void ChatForm::onSendTriggered() { QString msg = msgEdit->toPlainText(); if (msg.isEmpty()) return; QDateTime timestamp = QDateTime::currentDateTime(); HistoryKeeper::getInstance()->addChatEntry(f->userId, msg, Core::getInstance()->getSelfId().publicKey, timestamp); if (msg.startsWith("/me ")) { msg = msg.right(msg.length() - 4); addSelfMessage(msg, true, timestamp); emit sendAction(f->friendId, msg); } else { addSelfMessage(msg, false, timestamp); emit sendMessage(f->friendId, msg); } msgEdit->clear(); }
void ChatForm::SendMessageStr(QString msg) { if (msg.isEmpty()) return; bool isAction = msg.startsWith("/me ", Qt::CaseInsensitive); if (isAction) msg = msg = msg.right(msg.length() - 4); QList<CString> splittedMsg = Core::splitMessage(msg, TOX_MAX_MESSAGE_LENGTH); QDateTime timestamp = QDateTime::currentDateTime(); for (CString& c_msg : splittedMsg) { QString qt_msg = CString::toString(c_msg.data(), c_msg.size()); QString qt_msg_hist = qt_msg; if (isAction) qt_msg_hist = "/me " + qt_msg; bool status = !Settings::getInstance().getFauxOfflineMessaging(); int id = HistoryKeeper::getInstance()->addChatEntry(f->getToxId().publicKey, qt_msg_hist, Core::getInstance()->getSelfId().publicKey, timestamp, status, Core::getInstance()->getUsername()); ChatMessage::Ptr ma = addSelfMessage(qt_msg, isAction, timestamp, false); int rec; if (isAction) rec = Core::getInstance()->sendAction(f->getFriendID(), qt_msg); else rec = Core::getInstance()->sendMessage(f->getFriendID(), qt_msg); getOfflineMsgEngine()->registerReceipt(rec, id, ma); msgEdit->setLastMessage(msg); //set last message only when sending it Widget::getInstance()->updateFriendActivity(f); } }
void ChatForm::onSendTriggered() { QString msg = msgEdit->toPlainText(); if (msg.isEmpty()) return; bool isAction = msg.startsWith("/me "); if (isAction) msg = msg = msg.right(msg.length() - 4); QList<CString> splittedMsg = Core::splitMessage(msg, TOX_MAX_MESSAGE_LENGTH); QDateTime timestamp = QDateTime::currentDateTime(); for (CString& c_msg : splittedMsg) { QString qt_msg = CString::toString(c_msg.data(), c_msg.size()); QString qt_msg_hist = qt_msg; if (isAction) qt_msg_hist = "/me " + qt_msg; bool status = !Settings::getInstance().getFauxOfflineMessaging(); int id = HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, qt_msg_hist, Core::getInstance()->getSelfId().publicKey, timestamp, status); MessageActionPtr ma = addSelfMessage(qt_msg, isAction, timestamp, false); int rec; if (isAction) rec = Core::getInstance()->sendAction(f->getFriendID(), qt_msg); else rec = Core::getInstance()->sendMessage(f->getFriendID(), qt_msg); registerReceipt(rec, id, ma); } msgEdit->clear(); }