X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcore%2Fpostgresqlstorage.cpp;h=90b0fdbbc4ef8fdbac8869e2073e19e458e902d2;hb=df38a9238d603ec8d2040619befa50980d994916;hp=2aa28552c0b8a5ef23f1560f9ec843a1d37e872b;hpb=6e3574a163f07c28d44276318f2d9f92e169f491;p=quassel.git diff --git a/src/core/postgresqlstorage.cpp b/src/core/postgresqlstorage.cpp index 2aa28552..90b0fdbb 100644 --- a/src/core/postgresqlstorage.cpp +++ b/src/core/postgresqlstorage.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2019 by the Quassel Project * + * Copyright (C) 2005-2020 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -1385,6 +1385,34 @@ bool PostgreSqlStorage::mergeBuffersPermanently(const UserId& user, const Buffer return true; } +QHash PostgreSqlStorage::bufferLastMsgIds(UserId user) +{ + QHash lastMsgHash; + + QSqlDatabase db = logDb(); + if (!beginReadOnlyTransaction(db)) { + qWarning() << "PostgreSqlStorage::bufferLastMsgIds(): cannot start read only transaction!"; + qWarning() << " -" << qPrintable(db.lastError().text()); + return lastMsgHash; + } + + QSqlQuery query(db); + query.prepare(queryString("select_buffer_last_messages")); + query.bindValue(":userid", user.toInt()); + safeExec(query); + if (!watchQuery(query)) { + db.rollback(); + return lastMsgHash; + } + + while (query.next()) { + lastMsgHash[query.value(0).toInt()] = query.value(1).toLongLong(); + } + + db.commit(); + return lastMsgHash; +} + void PostgreSqlStorage::setBufferLastSeenMsg(UserId user, const BufferId& bufferId, const MsgId& msgId) { QSqlQuery query(logDb());