Commit 91342788 authored by Linus Jahn's avatar Linus Jahn

more changes

parent be55cfca
......@@ -87,8 +87,9 @@ class ClientWorker : public QObject
public:
struct Caches {
Caches(Kaidan *kaidan, MessageDb *msgDb, QObject *parent = nullptr)
: msgModel(new MessageModel(kaidan, parent)),
Caches(Kaidan *kaidan, RosterDb *rosterDb, MessageDb *msgDb,
QObject *parent = nullptr)
: msgModel(new MessageModel(kaidan, msgDb, parent)),
rosterModel(new RosterModel(rosterDb, parent)),
avatarStorage(new AvatarFileStorage(parent)),
presCache(new PresenceCache(parent)),
......
......@@ -45,6 +45,7 @@
#include "PresenceCache.h"
#include "Utils.h"
#include "MessageDb.h"
#include "RosterDb.h"
Kaidan::Kaidan(QGuiApplication *app, bool enableLogging, QObject *parent)
: QObject(parent), utils(new Utils(this)), database(new Database()),
......@@ -55,11 +56,13 @@ Kaidan::Kaidan(QGuiApplication *app, bool enableLogging, QObject *parent)
connect(dbThrd, &DbThread::started, database, &Database::openDatabase);
msgDb = new MessageDb();
msgDb->moveToThread(dbThrd);
rosterDb = new RosterDb();
rosterDb->moveToThread(dbThrd);
dbThrd->start();
// Caching components
caches = new ClientWorker::Caches(this, msgDb, this);
caches = new ClientWorker::Caches(this, rosterDb, msgDb, this);
// Connect the avatar changed signal of the avatarStorage with the NOTIFY signal
// of the Q_PROPERTY for the avatar storage (so all avatars are updated in QML)
connect(caches->avatarStorage, &AvatarFileStorage::avatarIdsChanged,
......
......@@ -364,6 +364,7 @@ private:
Database *database;
DbThread *dbThrd;
MessageDb *msgDb;
RosterDb *rosterDb;
ClientWorker::Caches *caches;
ClientThread *cltThrd;
ClientWorker *client;
......
......@@ -48,43 +48,44 @@ MessageDb::MessageDb(QObject *parent)
void MessageDb::fetchMessages(const QString &user1, const QString &user2, int index)
{
qDebug() << user1 << user2 << index;
QSqlQuery query(QSqlDatabase::database(KAIDAN_SQL_CONNECTION));
query.prepare("SELECT * FROM Messages "
"WHERE (author = :1 AND recipient = :2) OR "
"(author = :2 AND recipient = :1) "
"ORDER BY timestamp DESC "
"LIMIT :3, :4");
/*query.prepare("SELECT * FROM Messages "
"WHERE (author = :1 AND recipient = :2) OR "
"(author = :2 AND recipient = :1) "
"ORDER BY timestamp DESC ");
// "LIMIT :3, :4");
query.bindValue(":1", user1);
query.bindValue(":2", user2);
query.bindValue(":3", index);
query.bindValue(":4", 20);
if (!query.exec()) {
qDebug() << query.executedQuery();
qFatal("Failed to query database: %s", qPrintable(query.lastError().text()));
}
qDebug() << query.executedQuery() << query.size();
// query.bindValue(":3", index);
// query.bindValue(":4", 20);
// if (!query.exec()) {
// qDebug() << query.executedQuery();
// qFatal("Failed to query database: %s", qPrintable(query.lastError().text()));
// }
qDebug() << QSqlDatabase::database(KAIDAN_SQL_CONNECTION).tables();
query.exec("SELECT * FROM Messages");
qDebug() << user1 << user2 << index;
// get indexes of attributes
QSqlRecord record = query.record();
int idxFrom = record.indexOf("author");
int idxTo = record.indexOf("recipient");
int idxStamp = record.indexOf("timestamp");
int idxId = record.indexOf("id");
int idxBody = record.indexOf("message");
int idxIsSent = record.indexOf("isSent");
int idxIsDelivered = record.indexOf("isDelivered");
int idxMediaType = record.indexOf("type");
int idxOutOfBandUrl = record.indexOf("mediaUrl");
int idxMediaContentType = record.indexOf("mediaContentType");
int idxMediaLocation = record.indexOf("mediaLocation");
int idxIsEdited = record.indexOf("isEdited");
int idxSpoilerHint = record.indexOf("spoilerHint");
int idxIsSpoiler = record.indexOf("isSpoiler");
QSqlRecord rec = query.record();
int idxFrom = rec.indexOf("author");
int idxTo = rec.indexOf("recipient");
int idxStamp = rec.indexOf("timestamp");
int idxId = rec.indexOf("id");
int idxBody = rec.indexOf("message");
int idxIsSent = rec.indexOf("isSent");
int idxIsDelivered = rec.indexOf("isDelivered");
int idxMediaType = rec.indexOf("type");
int idxOutOfBandUrl = rec.indexOf("mediaUrl");
int idxMediaContentType = rec.indexOf("mediaContentType");
int idxMediaLocation = rec.indexOf("mediaLocation");
int idxIsEdited = rec.indexOf("isEdited");
int idxSpoilerHint = rec.indexOf("spoilerHint");
int idxIsSpoiler = rec.indexOf("isSpoiler");
QList<Message> messages;
while (query.next()) {
qDebug() << "message";
Message msg;
msg.setFrom(query.value(idxFrom).toString());
msg.setTo(query.value(idxTo).toString());
......@@ -101,7 +102,11 @@ void MessageDb::fetchMessages(const QString &user1, const QString &user2, int in
msg.setSpoilerHint(query.value(idxSpoilerHint).toString());
msg.setIsSpoiler(query.value(idxIsSpoiler).toBool());
messages << msg;
}*/
while (query.next()) {
qDebug() << query.record().value("message").toString();
}
emit messagesFetched(messages);
// emit messagesFetched(messages);
}
......@@ -177,12 +177,12 @@ void MessageHandler::handleMessage(const QXmppMessage &msg)
// TODO: Move back following call to RosterManager::handleMessage when spoiler
// messages are implemented in QXmpp
emit kaidan->getRosterModel()->setLastMessageRequested(contactJid,
message.isSpoiler() ? message.spoilerHint().isEmpty()
? tr("Spoiler")
: message.spoilerHint()
: msg.body()
);
// emit kaidan->getRosterModel()->setLastMessageRequested(contactJid,
// message.isSpoiler() ? message.spoilerHint().isEmpty()
// ? tr("Spoiler")
// : message.spoilerHint()
// : msg.body()
// );
}
void MessageHandler::sendMessage(QString toJid, QString body, bool isSpoiler, QString spoilerHint)
......
......@@ -49,18 +49,18 @@ RosterManager::RosterManager(Kaidan *kaidan, QXmppClient *client, RosterModel *m
connect(&manager, &QXmppRosterManager::itemAdded, [=] (QString jid) {
QXmppRosterIq::Item item = manager.getRosterEntry(jid);
emit model->insertContactRequested(jid, item.name());
// emit model->insertContactRequested(jid, item.name());
vCardManager->fetchVCard(jid);
});
connect(&manager, &QXmppRosterManager::itemChanged, [=] (QString jid) {
QXmppRosterIq::Item item = manager.getRosterEntry(jid);
emit model->setContactNameRequested(jid, item.name());
// emit model->setContactNameRequested(jid, item.name());
});
connect(&manager, &QXmppRosterManager::itemRemoved, [=] (QString jid) {
emit model->removeContactRequested(jid);
// emit model->removeContactRequested(jid);
});
connect(&manager, &QXmppRosterManager::subscriptionReceived, [=] (QString jid) {
......@@ -103,7 +103,7 @@ void RosterManager::populateRoster()
}
// replace current contacts with new ones from server
emit model->replaceContactsRequested(contactList);
// emit model->replaceContactsRequested(contactList);
}
void RosterManager::addContact(const QString jid, const QString name, const QString msg)
......@@ -139,14 +139,14 @@ void RosterManager::handleSendMessage(const QString &jid, const QString &message
{
if (client->state() == QXmppClient::ConnectedState) {
// update last message of the contact
emit model->setLastMessageRequested(jid,
isSpoiler ? spoilerHint.isEmpty() ? tr("Spoiler") : spoilerHint
: message
);
// emit model->setLastMessageRequested(jid,
// isSpoiler ? spoilerHint.isEmpty() ? tr("Spoiler") : spoilerHint
// : message
// );
// update last exchanged datetime (sorting order in contact list)
QString dateTime = QDateTime::currentDateTime().toUTC().toString(Qt::ISODate);
emit model->setLastExchangedRequested(jid, dateTime);
// emit model->setLastExchangedRequested(jid, dateTime);
}
}
......@@ -163,11 +163,11 @@ void RosterManager::handleMessage(const QXmppMessage &msg)
// update last exchanged datetime (sorting order in contact list)
QString dateTime = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
emit model->setLastExchangedRequested(contactJid, dateTime);
// emit model->setLastExchangedRequested(contactJid, dateTime);
// when we sent a message we can ignore all unread message notifications
if (sentByMe)
emit model->setUnreadMessageCountRequested(contactJid, 0);
// if (sentByMe)
// emit model->setUnreadMessageCountRequested(contactJid, 0);
// update unread message counter, if chat is not active
// else if (chatPartner != contactJid)
// emit model->newUnreadMessageRequested(contactJid);
......
......@@ -65,7 +65,7 @@ private slots:
private:
RosterDb *rosterDb;
QList<RosterItem> m_items;
bool m_hasFetched;
bool m_hasFetched = false;
};
#endif // ROSTERMODEL_H
......@@ -172,6 +172,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
qRegisterMetaType<TransferJob*>("TransferJob*");
qRegisterMetaType<Utils*>("Utils*");
qRegisterMetaType<QList<Message>>("QList<Message>");
qRegisterMetaType<QList<RosterItem>>("QList<RosterItem>");
// Qt-Translator
QTranslator qtTranslator;
......
......@@ -136,18 +136,19 @@ Kirigami.ScrollablePage {
delegate: ChatMessage {
msgId: model.id
sentByMe: model.sentByMe
messageBody: model.body
sentByMe: model.recipient !== kaidan.jid
messageBody: model.message
dateTime: new Date(model.timestamp)
isRead: model.isDelivered
recipientAvatarUrl: kaidan.avatarStorage.getAvatarUrl(author)
name: chatName
mediaType: model.mediaType
mediaType: model.type
mediaGetUrl: model.mediaUrl
mediaLocation: model.mediaLocation
isLastMessage: kaidan.messageModel.canCorrectMessage(model.id)
isLastMessage: model.id === kaidan.messageModel.lastMessageId(recipientJid)
edited: model.edited
isSpoiler: model.isSpoiler
isShowingSpoiler: false
spoilerHint: model.spoilerHint
onMessageEditRequested: {
......@@ -291,7 +292,6 @@ Kirigami.ScrollablePage {
Kirigami.Icon {
source: "preferences-desktop-emoticons"
enabled: sendButton.enabled
color: "transparent"
isMask: false
smooth: true
anchors.centerIn: parent
......@@ -314,7 +314,6 @@ Kirigami.ScrollablePage {
return "edit-symbolic"
}
enabled: sendButton.enabled
color: "transparent"
isMask: true
smooth: true
anchors.centerIn: parent
......
......@@ -54,9 +54,11 @@ Kirigami.ScrollablePage {
mainAction: Kirigami.Action {
text: qsTr("Add new contact")
iconName: "contact-new"
enabled: !addContactSheet.sheetOpen
onTriggered: {
addContactSheet.open();
if (addContactSheet.sheetOpen)
addContactSheet.close()
else
addContactSheet.open()
}
}
......@@ -81,7 +83,7 @@ Kirigami.ScrollablePage {
}
}
onClicked: {
kaidan.messageModel.chatPartner = "jbb@kaidan.im"//model.jid
kaidan.messageModel.chatPartner = model.jid
pageStack.push(chatPage, {
"chatName": (model.name ? model.name : model.jid),
"recipientJid": model.jid
......
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