X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcore%2Fpostgresqlstorage.cpp;h=d9b518f37d76de8427a2f23493657135f712d9cf;hb=92f4dca367c3a6f0536a1e0f3fbb44bb6ed4da62;hp=db8387f31aded41ef571f29cb7c5a0dcbe6c4fa3;hpb=dba66762993507168b1a3de25cfd2d7bff0ff969;p=quassel.git diff --git a/src/core/postgresqlstorage.cpp b/src/core/postgresqlstorage.cpp index db8387f3..d9b518f3 100644 --- a/src/core/postgresqlstorage.cpp +++ b/src/core/postgresqlstorage.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -1385,6 +1385,61 @@ QHash PostgreSqlStorage::bufferMarkerLineMsgIds(UserId user) return markerLineHash; } + +void PostgreSqlStorage::setBufferActivity(UserId user, BufferId bufferId, Message::Types bufferActivity) +{ + QSqlQuery query(logDb()); + query.prepare(queryString("update_buffer_bufferactivity")); + + query.bindValue(":userid", user.toInt()); + query.bindValue(":bufferid", bufferId.toInt()); + query.bindValue(":bufferactivity", (int) bufferActivity); + safeExec(query); + watchQuery(query); +} + +QHash PostgreSqlStorage::bufferActivities(UserId user) +{ + QHash bufferActivityHash; + + QSqlDatabase db = logDb(); + if (!beginReadOnlyTransaction(db)) { + qWarning() << "PostgreSqlStorage::bufferActivities(): cannot start read only transaction!"; + qWarning() << " -" << qPrintable(db.lastError().text()); + return bufferActivityHash; + } + + QSqlQuery query(db); + query.prepare(queryString("select_buffer_bufferactivities")); + query.bindValue(":userid", user.toInt()); + safeExec(query); + if (!watchQuery(query)) { + db.rollback(); + return bufferActivityHash; + } + + while (query.next()) { + bufferActivityHash[query.value(0).toInt()] = Message::Types(query.value(1).toInt()); + } + + db.commit(); + return bufferActivityHash; +} + +Message::Types PostgreSqlStorage::bufferActivity(BufferId bufferId, MsgId lastSeenMsgId) +{ + QSqlQuery query(logDb()); + query.prepare(queryString("select_buffer_bufferactivity")); + query.bindValue(":bufferid", bufferId.toInt()); + query.bindValue(":lastseenmsgid", lastSeenMsgId.toInt()); + safeExec(query); + watchQuery(query); + Message::Types result = Message::Types(0); + if (query.first()) + result = Message::Types(query.value(0).toInt()); + return result; +} + bool PostgreSqlStorage::logMessage(Message &msg) { QSqlDatabase db = logDb(); @@ -1630,7 +1685,7 @@ QList PostgreSqlStorage::requestAllMsgs(UserId user, MsgId first, MsgId QDateTime timestamp; for (int i = 0; i < limit && query.next(); i++) { - timestamp = query.value(1).toDateTime(); + timestamp = query.value(2).toDateTime(); timestamp.setTimeSpec(Qt::UTC); Message msg(timestamp, bufferInfoHash[query.value(1).toInt()], @@ -1978,8 +2033,9 @@ bool PostgreSqlMigrationWriter::writeMo(const BufferMO &buffer) bindValue(7, buffer.lastmsgid); bindValue(8, buffer.lastseenmsgid); bindValue(9, buffer.markerlinemsgid); - bindValue(10, buffer.key); - bindValue(11, buffer.joined); + bindValue(10, buffer.bufferactivity); + bindValue(11, buffer.key); + bindValue(12, buffer.joined); return exec(); }