mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
faux offline messaging
This commit is contained in:
parent
a6b95e7b4f
commit
cee1bcc8d1
|
@ -147,7 +147,7 @@ QList<HistoryKeeper::HistMessage> HistoryKeeper::getChatHistory(HistoryKeeper::C
|
||||||
QSqlQuery dbAnswer;
|
QSqlQuery dbAnswer;
|
||||||
if (ct == ctSingle)
|
if (ct == ctSingle)
|
||||||
{
|
{
|
||||||
dbAnswer = db->exec(QString("SELECT timestamp, user_id, message, sent_ok FROM history INNER JOIN aliases ON history.sender = aliases.id ") +
|
dbAnswer = db->exec(QString("SELECT history.id, timestamp, user_id, message, sent_ok FROM history INNER JOIN aliases ON history.sender = aliases.id ") +
|
||||||
QString("AND timestamp BETWEEN %1 AND %2 AND chat_id = %3;")
|
QString("AND timestamp BETWEEN %1 AND %2 AND chat_id = %3;")
|
||||||
.arg(time64_from).arg(time64_to).arg(chat_id));
|
.arg(time64_from).arg(time64_to).arg(chat_id));
|
||||||
} else {
|
} else {
|
||||||
|
@ -156,13 +156,15 @@ QList<HistoryKeeper::HistMessage> HistoryKeeper::getChatHistory(HistoryKeeper::C
|
||||||
|
|
||||||
while (dbAnswer.next())
|
while (dbAnswer.next())
|
||||||
{
|
{
|
||||||
QString sender = dbAnswer.value(1).toString();
|
qint64 id = dbAnswer.value(0).toLongLong();
|
||||||
QString message = unWrapMessage(dbAnswer.value(2).toString());
|
qint64 timeInt = dbAnswer.value(1).toLongLong();
|
||||||
qint64 timeInt = dbAnswer.value(0).toLongLong();
|
QString sender = dbAnswer.value(2).toString();
|
||||||
QDateTime time = QDateTime::fromMSecsSinceEpoch(timeInt);
|
QString message = unWrapMessage(dbAnswer.value(3).toString());
|
||||||
bool isSent = dbAnswer.value(3).toBool();
|
bool isSent = dbAnswer.value(4).toBool();
|
||||||
|
|
||||||
res.push_back({sender,message,time,isSent});
|
QDateTime time = QDateTime::fromMSecsSinceEpoch(timeInt);
|
||||||
|
|
||||||
|
res.push_back({id, sender,message,time,isSent});
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
|
|
||||||
struct HistMessage
|
struct HistMessage
|
||||||
{
|
{
|
||||||
|
qint64 id;
|
||||||
QString sender;
|
QString sender;
|
||||||
QString message;
|
QString message;
|
||||||
QDateTime timestamp;
|
QDateTime timestamp;
|
||||||
|
|
|
@ -81,7 +81,7 @@ ChatForm::ChatForm(Friend* chatFriend)
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
|
|
||||||
if (Settings::getInstance().getEnableLogging())
|
if (Settings::getInstance().getEnableLogging())
|
||||||
loadHistory(QDateTime::currentDateTime().addDays(-7));
|
loadHistory(QDateTime::currentDateTime().addDays(-7), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatForm::~ChatForm()
|
ChatForm::~ChatForm()
|
||||||
|
@ -709,7 +709,7 @@ void ChatForm::onAvatarRemoved(int FriendId)
|
||||||
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
|
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::loadHistory(QDateTime since)
|
void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
||||||
{
|
{
|
||||||
QDateTime now = QDateTime::currentDateTime();
|
QDateTime now = QDateTime::currentDateTime();
|
||||||
|
|
||||||
|
@ -748,7 +748,19 @@ void ChatForm::loadHistory(QDateTime since)
|
||||||
// Show each messages
|
// Show each messages
|
||||||
MessageActionPtr ca = genMessageActionAction(ToxID::fromString(it.sender), it.message, false, msgDateTime);
|
MessageActionPtr ca = genMessageActionAction(ToxID::fromString(it.sender), it.message, false, msgDateTime);
|
||||||
if (it.isSent)
|
if (it.isSent)
|
||||||
|
{
|
||||||
ca->markAsSent();
|
ca->markAsSent();
|
||||||
|
} else {
|
||||||
|
if (processUndelivered)
|
||||||
|
{
|
||||||
|
int rec;
|
||||||
|
if (ca->isAction())
|
||||||
|
rec = Core::getInstance()->sendAction(f->getFriendID(), ca->getRawMessage());
|
||||||
|
else
|
||||||
|
rec = Core::getInstance()->sendMessage(f->getFriendID(), ca->getRawMessage());
|
||||||
|
registerReceipt(rec, it.id, ca);
|
||||||
|
}
|
||||||
|
}
|
||||||
historyMessages.append(ca);
|
historyMessages.append(ca);
|
||||||
}
|
}
|
||||||
std::swap(storedPrevId, previousId);
|
std::swap(storedPrevId, previousId);
|
||||||
|
@ -861,3 +873,20 @@ void ChatForm::clearReciepts()
|
||||||
receipts.clear();
|
receipts.clear();
|
||||||
undeliveredMsgs.clear();
|
undeliveredMsgs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatForm::deliverOfflineMsgs()
|
||||||
|
{
|
||||||
|
QMap<int, MessageActionPtr> msgs = undeliveredMsgs;
|
||||||
|
clearReciepts();
|
||||||
|
|
||||||
|
for (auto iter = msgs.begin(); iter != msgs.end(); iter++)
|
||||||
|
{
|
||||||
|
QString messageText = iter.value()->getRawMessage();
|
||||||
|
int rec;
|
||||||
|
if (iter.value()->isAction())
|
||||||
|
rec = Core::getInstance()->sendAction(f->getFriendID(), messageText);
|
||||||
|
else
|
||||||
|
rec = Core::getInstance()->sendMessage(f->getFriendID(), messageText);
|
||||||
|
registerReceipt(rec, iter.key(), iter.value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
ChatForm(Friend* chatFriend);
|
ChatForm(Friend* chatFriend);
|
||||||
~ChatForm();
|
~ChatForm();
|
||||||
void setStatusMessage(QString newMessage);
|
void setStatusMessage(QString newMessage);
|
||||||
void registerReceipt(int receipt, int messageID, MessageActionPtr msg);
|
|
||||||
void dischargeReceipt(int receipt);
|
void dischargeReceipt(int receipt);
|
||||||
void clearReciepts();
|
void clearReciepts();
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ signals:
|
||||||
void volMuteToggle(int callId);
|
void volMuteToggle(int callId);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void deliverOfflineMsgs();
|
||||||
void startFileSend(ToxFile file);
|
void startFileSend(ToxFile file);
|
||||||
void onFileRecvRequest(ToxFile file);
|
void onFileRecvRequest(ToxFile file);
|
||||||
void onAvInvite(int FriendId, int CallId, bool video);
|
void onAvInvite(int FriendId, int CallId, bool video);
|
||||||
|
@ -84,10 +85,11 @@ private slots:
|
||||||
void updateTime();
|
void updateTime();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void loadHistory(QDateTime since);
|
void loadHistory(QDateTime since, bool processUndelivered = false);
|
||||||
// drag & drop
|
// drag & drop
|
||||||
void dragEnterEvent(QDragEnterEvent* ev);
|
void dragEnterEvent(QDragEnterEvent* ev);
|
||||||
void dropEvent(QDropEvent* ev);
|
void dropEvent(QDropEvent* ev);
|
||||||
|
void registerReceipt(int receipt, int messageID, MessageActionPtr msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Friend* f;
|
Friend* f;
|
||||||
|
@ -105,7 +107,7 @@ private:
|
||||||
void stopCounter();
|
void stopCounter();
|
||||||
QString secondsToDHMS(quint32 duration);
|
QString secondsToDHMS(quint32 duration);
|
||||||
QHash<int, int> receipts;
|
QHash<int, int> receipts;
|
||||||
QHash<int, MessageActionPtr> undeliveredMsgs;
|
QMap<int, MessageActionPtr> undeliveredMsgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CHATFORM_H
|
#endif // CHATFORM_H
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
ActionAction::ActionAction(const QString &author, QString message, const QString &date, const bool& me) :
|
ActionAction::ActionAction(const QString &author, QString message, const QString &date, const bool& me) :
|
||||||
MessageAction(author, author+" "+message, date, me)
|
MessageAction(author, author+" "+message, date, me)
|
||||||
{
|
{
|
||||||
|
rawMessage = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ActionAction::getName()
|
QString ActionAction::getName()
|
||||||
|
@ -31,3 +32,8 @@ QString ActionAction::getMessage()
|
||||||
{
|
{
|
||||||
return MessageAction::getMessage("action");
|
return MessageAction::getMessage("action");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ActionAction::getRawMessage()
|
||||||
|
{
|
||||||
|
return rawMessage;
|
||||||
|
}
|
||||||
|
|
|
@ -24,13 +24,15 @@ class ActionAction : public MessageAction
|
||||||
public:
|
public:
|
||||||
ActionAction(const QString &author, QString message, const QString& date, const bool&);
|
ActionAction(const QString &author, QString message, const QString& date, const bool&);
|
||||||
virtual ~ActionAction(){;}
|
virtual ~ActionAction(){;}
|
||||||
|
virtual QString getRawMessage();
|
||||||
|
virtual bool isAction() {return true;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QString getMessage();
|
virtual QString getMessage();
|
||||||
virtual QString getName();
|
virtual QString getName();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString message;
|
QString message, rawMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MESSAGEACTION_H
|
#endif // MESSAGEACTION_H
|
||||||
|
|
|
@ -89,3 +89,8 @@ void MessageAction::markAsSent()
|
||||||
{
|
{
|
||||||
isProcessed = true;
|
isProcessed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString MessageAction::getRawMessage()
|
||||||
|
{
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ public:
|
||||||
virtual ~MessageAction(){;}
|
virtual ~MessageAction(){;}
|
||||||
virtual void featureUpdate();
|
virtual void featureUpdate();
|
||||||
void markAsSent();
|
void markAsSent();
|
||||||
|
virtual QString getRawMessage();
|
||||||
|
virtual bool isAction() {return false;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QString getMessage();
|
virtual QString getMessage();
|
||||||
|
|
|
@ -692,6 +692,11 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
|
||||||
f->getChatForm()->addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"").arg(f->getDisplayedName()).arg(fStatus),
|
f->getChatForm()->addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"").arg(f->getDisplayedName()).arg(fStatus),
|
||||||
"white", QDateTime::currentDateTime());
|
"white", QDateTime::currentDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isActualChange && status != Status::Offline)
|
||||||
|
{ // wait a little
|
||||||
|
QTimer::singleShot(250, f->getChatForm(), SLOT(deliverOfflineMsgs()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::onFriendStatusMessageChanged(int friendId, const QString& message)
|
void Widget::onFriendStatusMessageChanged(int friendId, const QString& message)
|
||||||
|
@ -1058,12 +1063,10 @@ void Widget::setStatusBusy()
|
||||||
void Widget::onMessageSendResult(int friendId, const QString& message, int messageId)
|
void Widget::onMessageSendResult(int friendId, const QString& message, int messageId)
|
||||||
{
|
{
|
||||||
Q_UNUSED(message)
|
Q_UNUSED(message)
|
||||||
|
Q_UNUSED(messageId)
|
||||||
Friend* f = FriendList::findFriend(friendId);
|
Friend* f = FriendList::findFriend(friendId);
|
||||||
if (!f)
|
if (!f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!messageId)
|
|
||||||
f->getChatForm()->addSystemInfoMessage(tr("Message failed to send"), "red", QDateTime::currentDateTime());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::onGroupSendResult(int groupId, const QString& message, int result)
|
void Widget::onGroupSendResult(int groupId, const QString& message, int result)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user