Commit 0a6e43bd authored by Linus Jahn's avatar Linus Jahn

Fix message insertion bug

There was still an, now unused, variable/pointer in the MessageController class. It
wasn't set so it was a nullptr, when the MessageModel was trying to add it to the db.
parent b5140302
......@@ -226,7 +226,7 @@ void Kaidan::setChatPartner(QString chatPartner)
void Kaidan::sendMessage(QString jid, QString message)
{
messageController->sendMessage(&jid, &message);
messageController->sendMessage(&(this->jid), &jid, &message);
rosterController->handleNewMessageSent(&jid, &message);
}
......
......@@ -78,7 +78,8 @@ void MessageController::handleMessageReceived(Swift::Message::ref message_)
// author is only the 'bare' JID: e.g. 'albert@einstein.ch'
const QString author = QString::fromStdString(message_->getFrom().toBare().toString());
const QString author_resource = QString(message_->getFrom().getResource().c_str());
const QString author_resource = QString::fromStdString(message_->getFrom().getResource());
const QString recipient = QString::fromStdString(message_->getTo().toBare().toString());
const QString recipient_resource = QString::fromStdString(client->getJID().getResource());
QString timestamp = QDateTime::currentDateTime().toString(Qt::ISODate); // fallback timestamp
const QString message = QString::fromStdString(*bodyOpt);
......@@ -92,8 +93,8 @@ void MessageController::handleMessageReceived(Swift::Message::ref message_)
);
}
messageModel->addMessage(&author, &author_resource, ownJid,
&recipient_resource, &timestamp, &message, &msgId, false);
messageModel->addMessage(&author, &author_resource, &recipient,
&recipient_resource, &timestamp, &message, &msgId, false);
// send a new notification | TODO: Resolve nickname from JID
Notifications::sendMessageNotification(
......@@ -133,7 +134,7 @@ void MessageController::handleMessageReceived(Swift::Message::ref message_)
}
}
void MessageController::sendMessage(QString *recipient_, QString *message_)
void MessageController::sendMessage(QString *fromJid, QString *recipient_, QString *message_)
{
// generate a new message id
Swift::IDGenerator idGenerator;
......@@ -148,7 +149,7 @@ void MessageController::sendMessage(QString *recipient_, QString *message_)
const QString recipient_resource = QString("");
const QString qmsgId = QString::fromStdString(msgId);
messageModel->addMessage(ownJid, &author_resource, recipient_,
messageModel->addMessage(fromJid, &author_resource, recipient_,
&recipient_resource, &timestamp, message_, &qmsgId, true);
//
......
......@@ -43,7 +43,7 @@ public:
MessageModel* getMessageModel();
void setChatPartner(QString *recipient, QString* ownJid);
void sendMessage(QString *recipient_, QString *message_);
void sendMessage(QString *fromJid, QString *recipient_, QString *message_);
signals:
void messageModelChanged();
......@@ -54,7 +54,6 @@ private:
Swift::Client *client;
MessageModel *messageModel;
QString *ownJid;
};
#endif // MESSAGECONTROLLER_H
......@@ -83,9 +83,9 @@ void MessageModel::setMessageAsDelivered(const QString msgId)
submitAll();
}
void MessageModel::addMessage(const QString* author, const QString* author_resource,
const QString* recipient, const QString* recipient_resource,
const QString* timestamp, const QString* message, const QString* msgId,
void MessageModel::addMessage(const QString *author, const QString *author_resource,
const QString *recipient, const QString *recipient_resource,
const QString *timestamp, const QString *message, const QString *msgId,
bool sentByMe)
{
//
......@@ -102,8 +102,6 @@ void MessageModel::addMessage(const QString* author, const QString* author_resou
record.setValue("id", *msgId);
record.setValue("isSent", sentByMe ? false : true);
record.setValue("isDelivered", sentByMe ? false : true);
record.setValue("isRead", sentByMe ? false : true);
record.setValue("isReadByMe", sentByMe ? true : false);
if (!insertRecord(rowCount(), record)) {
qWarning() << "Failed to add message to DB:" << lastError().text();
......
......@@ -33,10 +33,10 @@ public:
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
void applyRecipientFilter(QString *recipient_, QString *author_);
void addMessage(const QString* author, const QString* author_resource,
const QString* recipient, const QString* recipient_resource,
const QString* timestamp, const QString* message,
const QString* msgId, bool sentByMe);
void addMessage(const QString *author, const QString *author_resource,
const QString *recipient, const QString *recipient_resource,
const QString *timestamp, const QString *message,
const QString *msgId, bool sentByMe);
void setMessageAsSent(const QString msgId);
void setMessageAsDelivered(const QString msgId);
......
......@@ -185,7 +185,7 @@ void RosterModel::setUnreadMessageCountOfJid(const QString* jid_, const int coun
void RosterModel::setLastMessageForJid(QString *jid, QString *message)
{
QSqlQuery query(*database);
query.prepare(QString("UPDATE Roster SET lastMessage = %1 WHERE jid = '%2'")
query.prepare(QString("UPDATE Roster SET lastMessage = '%1' WHERE jid = '%2'")
.arg(*message, *jid));
if (!query.exec()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment