mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
no reason to keep action flag in the logfile
This commit is contained in:
parent
c07a0cd7f8
commit
e3d5853ca3
|
@ -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()
|
|||
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
|
|||
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
|
|||
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()
|
|||
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)
|
||||
|
|
|
@ -26,21 +26,19 @@ class HistoryKeeper
|
|||
{
|
||||
public:
|
||||
enum ChatType {ctSingle = 0, ctGroup};
|
||||
enum MessageType {mtMessage = 0, mtAction};
|
||||
|
||||
struct HistMessage
|
||||
{
|
||||
QString sender;
|
||||
QString message;
|
||||
QDateTime timestamp;
|
||||
MessageType mt;
|
||||
};
|
||||
|
||||
static HistoryKeeper* getInstance();
|
||||
static void resetInstance();
|
||||
virtual ~HistoryKeeper();
|
||||
|
||||
void addChatEntry(const QString& chat, MessageType mt, const QString& message, const QString& sender, const QDateTime &dt);
|
||||
void addChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt);
|
||||
void addGroupChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt);
|
||||
QList<HistMessage> getChatHistory(ChatType ct, const QString &profile, const QString &chat,
|
||||
const QDateTime &time_from, const QDateTime &time_to);
|
||||
|
@ -61,7 +59,6 @@ private:
|
|||
QString unWrapMessage(const QString &str);
|
||||
bool dumpDBtoFile(const QString &fname);
|
||||
|
||||
MessageType convertToMessageType(int);
|
||||
ChatType convertToChatType(int);
|
||||
|
||||
QSqlDatabase db;
|
||||
|
|
|
@ -91,19 +91,17 @@ void ChatForm::onSendTriggered()
|
|||
return;
|
||||
QString name = Widget::getInstance()->getUsername();
|
||||
QDateTime timestamp = QDateTime::currentDateTime();
|
||||
HistoryKeeper::getInstance()->addChatEntry(f->userId, msg, Core::getInstance()->getSelfId().publicKey, timestamp);
|
||||
|
||||
if (msg.startsWith("/me "))
|
||||
{
|
||||
msg = msg.right(msg.length() - 4);
|
||||
addMessage(name, msg, true, timestamp);
|
||||
HistoryKeeper::getInstance()->addChatEntry(f->userId, HistoryKeeper::mtAction, msg,
|
||||
Core::getInstance()->getSelfId().publicKey, timestamp);
|
||||
emit sendAction(f->friendId, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
addMessage(name, msg, false, timestamp);
|
||||
HistoryKeeper::getInstance()->addChatEntry(f->userId, HistoryKeeper::mtMessage, msg,
|
||||
Core::getInstance()->getSelfId().publicKey, timestamp);
|
||||
emit sendMessage(f->friendId, msg);
|
||||
}
|
||||
msgEdit->clear();
|
||||
|
@ -568,12 +566,11 @@ void ChatForm::onLoadHistory()
|
|||
|
||||
for (const auto &it : msgs)
|
||||
{
|
||||
bool isAction = (it.mt == HistoryKeeper::mtAction);
|
||||
QString name = f->getName();
|
||||
if (it.sender == Core::getInstance()->getSelfId().publicKey)
|
||||
name = Core::getInstance()->getUsername();
|
||||
|
||||
ChatAction *ca = genMessageActionAction(name, it.message, isAction, it.timestamp.toLocalTime());
|
||||
ChatAction *ca = genMessageActionAction(name, it.message, false, it.timestamp.toLocalTime());
|
||||
historyMessages.append(ca);
|
||||
}
|
||||
previousName = storedPrevName;
|
||||
|
|
|
@ -501,8 +501,11 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool
|
|||
|
||||
QDateTime timestamp = QDateTime::currentDateTime();
|
||||
f->chatForm->addMessage(f->getName(), message, isAction, timestamp);
|
||||
HistoryKeeper::MessageType mt = isAction ? HistoryKeeper::mtAction : HistoryKeeper::mtMessage;
|
||||
HistoryKeeper::getInstance()->addChatEntry(f->userId, mt, message, f->userId, timestamp);
|
||||
|
||||
if (isAction)
|
||||
HistoryKeeper::getInstance()->addChatEntry(f->userId, "/me " + message, f->userId, timestamp);
|
||||
else
|
||||
HistoryKeeper::getInstance()->addChatEntry(f->userId, message, f->userId, timestamp);
|
||||
|
||||
if (activeChatroomWidget != nullptr)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user