|
|
|
@ -82,12 +82,11 @@ HistoryKeeper::HistoryKeeper(const QString &path, bool encr) :
@@ -82,12 +82,11 @@ HistoryKeeper::HistoryKeeper(const QString &path, bool encr) :
|
|
|
|
|
profile_id -- profile ID (resolves from aliases table) |
|
|
|
|
chat_id -- current chat ID (resolves from chats table) |
|
|
|
|
sender -- sender's ID (resolves from aliases table) |
|
|
|
|
mtype -- type of message (message, action, etc) (UNUSED now) |
|
|
|
|
message |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
db.exec(QString("CREATE TABLE IF NOT EXISTS history (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER NOT NULL, ") + |
|
|
|
|
QString("profile_id INTEGER NOT NULL, chat_id INTEGER NOT NULL, sender INTERGER NOT NULL, mtype INTEGER NOT NULL, message TEXT NOT NULL);")); |
|
|
|
|
QString("profile_id INTEGER NOT NULL, chat_id INTEGER NOT NULL, sender INTERGER NOT NULL, message TEXT NOT NULL);")); |
|
|
|
|
db.exec(QString("CREATE TABLE IF NOT EXISTS aliases (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id TEXT UNIQUE NOT NULL);")); |
|
|
|
|
db.exec(QString("CREATE TABLE IF NOT EXISTS chats (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE NOT NULL, ctype INTEGER NOT NULL);")); |
|
|
|
|
|
|
|
|
@ -100,16 +99,15 @@ HistoryKeeper::~HistoryKeeper()
@@ -100,16 +99,15 @@ HistoryKeeper::~HistoryKeeper()
|
|
|
|
|
db.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HistoryKeeper::addChatEntry(const QString& chat, MessageType mt, const QString& message, |
|
|
|
|
const QString& sender, const QDateTime &dt) |
|
|
|
|
void HistoryKeeper::addChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt) |
|
|
|
|
{ |
|
|
|
|
int chat_id = getChatID(chat, ctSingle).first; |
|
|
|
|
int sender_id = getAliasID(sender); |
|
|
|
|
int profile_id = getCurrentProfileID(); |
|
|
|
|
|
|
|
|
|
db.exec(QString("INSERT INTO history (profile_id, timestamp, chat_id, sender, mtype, message)") + |
|
|
|
|
QString("VALUES (%1, %2, %3, %4, %5, '%6');") |
|
|
|
|
.arg(profile_id).arg(dt.toMSecsSinceEpoch()).arg(chat_id).arg(sender_id).arg(mt).arg(wrapMessage(message))); |
|
|
|
|
db.exec(QString("INSERT INTO history (profile_id, timestamp, chat_id, sender, message)") + |
|
|
|
|
QString("VALUES (%1, %2, %3, %4, '%5');") |
|
|
|
|
.arg(profile_id).arg(dt.toMSecsSinceEpoch()).arg(chat_id).arg(sender_id).arg(wrapMessage(message))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QList<HistoryKeeper::HistMessage> HistoryKeeper::getChatHistory(HistoryKeeper::ChatType ct, const QString &profile, |
|
|
|
@ -127,7 +125,7 @@ QList<HistoryKeeper::HistMessage> HistoryKeeper::getChatHistory(HistoryKeeper::C
@@ -127,7 +125,7 @@ QList<HistoryKeeper::HistMessage> HistoryKeeper::getChatHistory(HistoryKeeper::C
|
|
|
|
|
QSqlQuery dbAnswer; |
|
|
|
|
if (ct == ctSingle) |
|
|
|
|
{ |
|
|
|
|
dbAnswer = db.exec(QString("SELECT timestamp, user_id, message, mtype FROM history INNER JOIN aliases ON history.sender = aliases.id ") + |
|
|
|
|
dbAnswer = db.exec(QString("SELECT timestamp, user_id, message FROM history INNER JOIN aliases ON history.sender = aliases.id ") + |
|
|
|
|
QString("AND timestamp BETWEEN %1 AND %2 AND chat_id = %3 AND profile_id = %4;") |
|
|
|
|
.arg(time64_from).arg(time64_to).arg(chat_id).arg(profile_id)); |
|
|
|
|
} else { |
|
|
|
@ -140,9 +138,8 @@ QList<HistoryKeeper::HistMessage> HistoryKeeper::getChatHistory(HistoryKeeper::C
@@ -140,9 +138,8 @@ QList<HistoryKeeper::HistMessage> HistoryKeeper::getChatHistory(HistoryKeeper::C
|
|
|
|
|
QString message = unWrapMessage(dbAnswer.value(2).toString()); |
|
|
|
|
qint64 timeInt = dbAnswer.value(0).toLongLong(); |
|
|
|
|
QDateTime time = QDateTime::fromMSecsSinceEpoch(timeInt); |
|
|
|
|
MessageType mt = convertToMessageType(dbAnswer.value(3).toInt()); |
|
|
|
|
|
|
|
|
|
res.push_back({sender,message,time, mt}); |
|
|
|
|
res.push_back({sender,message,time}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
@ -267,14 +264,6 @@ int HistoryKeeper::getCurrentProfileID()
@@ -267,14 +264,6 @@ int HistoryKeeper::getCurrentProfileID()
|
|
|
|
|
return getAliasID(Core::getInstance()->getSelfId().publicKey); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
HistoryKeeper::MessageType HistoryKeeper::convertToMessageType(int mt) |
|
|
|
|
{ |
|
|
|
|
if (mt < 0 || mt > 1) |
|
|
|
|
return mtMessage; |
|
|
|
|
|
|
|
|
|
return static_cast<MessageType>(mt); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
HistoryKeeper::ChatType HistoryKeeper::convertToChatType(int ct) |
|
|
|
|
{ |
|
|
|
|
if (ct < 0 || ct > 1) |
|
|
|
|