1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

group messages

This commit is contained in:
apprb 2014-11-10 19:23:02 +09:00
parent 44fb8a360e
commit a6b95e7b4f
No known key found for this signature in database
GPG Key ID: B001911B5B22FB9B
4 changed files with 23 additions and 17 deletions

View File

@ -832,8 +832,8 @@ QString ChatForm::secondsToDHMS(quint32 duration)
void ChatForm::registerReceipt(int receipt, int messageID, MessageActionPtr msg) void ChatForm::registerReceipt(int receipt, int messageID, MessageActionPtr msg)
{ {
receipts[receipt] = {messageID, msg}; receipts[receipt] = messageID;
undeliveredIDs.insert(messageID); undeliveredMsgs[messageID] = msg;
qDebug() << "linking: rec" << receipt << "with" << messageID; qDebug() << "linking: rec" << receipt << "with" << messageID;
} }
@ -842,13 +842,15 @@ void ChatForm::dischargeReceipt(int receipt)
auto it = receipts.find(receipt); auto it = receipts.find(receipt);
if (it != receipts.end()) if (it != receipts.end())
{ {
int mID = it.value().first; int mID = it.value();
if (undeliveredIDs.remove(mID)) auto msgIt = undeliveredMsgs.find(mID);
if (msgIt != undeliveredMsgs.end())
{ {
HistoryKeeper::getInstance()->markAsSent(mID); HistoryKeeper::getInstance()->markAsSent(mID);
msgIt.value()->markAsSent();
msgIt.value()->featureUpdate();
undeliveredMsgs.erase(msgIt);
} }
it.value().second->markAsSent();
it.value().second->featureUpdate();
receipts.erase(it); receipts.erase(it);
qDebug() << "receipt" << receipt << "delivered"; qDebug() << "receipt" << receipt << "delivered";
} }
@ -857,5 +859,5 @@ void ChatForm::dischargeReceipt(int receipt)
void ChatForm::clearReciepts() void ChatForm::clearReciepts()
{ {
receipts.clear(); receipts.clear();
undeliveredIDs.clear(); undeliveredMsgs.clear();
} }

View File

@ -104,8 +104,8 @@ private:
void startCounter(); void startCounter();
void stopCounter(); void stopCounter();
QString secondsToDHMS(quint32 duration); QString secondsToDHMS(quint32 duration);
QHash<int, QPair<int, MessageActionPtr>> receipts; QHash<int, int> receipts;
QSet<int> undeliveredIDs; QHash<int, MessageActionPtr> undeliveredMsgs;
}; };
#endif // CHATFORM_H #endif // CHATFORM_H

View File

@ -201,7 +201,8 @@ void GenericChatForm::onSaveLogClicked()
*/ */
void GenericChatForm::addMessage(const QString& author, const QString &message, bool isAction, const QDateTime &datetime) void GenericChatForm::addMessage(const QString& author, const QString &message, bool isAction, const QDateTime &datetime)
{ {
ChatActionPtr ca = genMessageActionAction(author, message, isAction, datetime); MessageActionPtr ca = genMessageActionAction(author, message, isAction, datetime);
ca->markAsSent();
chatWidget->insertMessage(ca); chatWidget->insertMessage(ca);
} }
@ -230,7 +231,9 @@ MessageActionPtr GenericChatForm::addSelfMessage(const QString &message, bool is
void GenericChatForm::addAlertMessage(const QString& author, QString message, QDateTime datetime) void GenericChatForm::addAlertMessage(const QString& author, QString message, QDateTime datetime)
{ {
QString date = datetime.toString(Settings::getInstance().getTimestampFormat()); QString date = datetime.toString(Settings::getInstance().getTimestampFormat());
chatWidget->insertMessage(ChatActionPtr(new AlertAction(author, message, date))); AlertAction *alact = new AlertAction(author, message, date);
alact->markAsSent();
chatWidget->insertMessage(ChatActionPtr(alact));
previousId.publicKey = author; previousId.publicKey = author;
} }
@ -307,7 +310,8 @@ void GenericChatForm::clearChatArea(bool notinform)
/** /**
* @deprecated The only reason it's still alive is because the groupchat API is a bit limited * @deprecated The only reason it's still alive is because the groupchat API is a bit limited
*/ */
ChatActionPtr GenericChatForm::genMessageActionAction(const QString &author, QString message, bool isAction, const QDateTime &datetime) MessageActionPtr GenericChatForm::genMessageActionAction(const QString &author, QString message, bool isAction,
const QDateTime &datetime)
{ {
if (earliestMessage == nullptr) if (earliestMessage == nullptr)
{ {
@ -326,14 +330,14 @@ ChatActionPtr GenericChatForm::genMessageActionAction(const QString &author, QSt
if (isAction) if (isAction)
{ {
previousId = ToxID(); // next msg has a name regardless previousId = ToxID(); // next msg has a name regardless
return ChatActionPtr(new ActionAction (getElidedName(author), message, date, isMe)); return MessageActionPtr(new ActionAction (getElidedName(author), message, date, isMe));
} }
ChatActionPtr res; MessageActionPtr res;
if (previousId.publicKey == author) if (previousId.publicKey == author)
res = ChatActionPtr(new MessageAction(QString(), message, date, isMe)); res = MessageActionPtr(new MessageAction(QString(), message, date, isMe));
else else
res = ChatActionPtr(new MessageAction(getElidedName(author), message, date, isMe)); res = MessageActionPtr(new MessageAction(getElidedName(author), message, date, isMe));
previousId.publicKey = author; previousId.publicKey = author;
return res; return res;

View File

@ -73,7 +73,7 @@ protected slots:
protected: protected:
QString getElidedName(const QString& name); QString getElidedName(const QString& name);
ChatActionPtr genMessageActionAction(const QString& author, QString message, bool isAction, const QDateTime &datetime); ///< Deprecated MessageActionPtr genMessageActionAction(const QString& author, QString message, bool isAction, const QDateTime &datetime); ///< Deprecated
MessageActionPtr genMessageActionAction(const ToxID& author, QString message, bool isAction, const QDateTime &datetime); MessageActionPtr genMessageActionAction(const ToxID& author, QString message, bool isAction, const QDateTime &datetime);
MessageActionPtr genSelfActionAction(QString message, bool isAction, const QDateTime &datetime); MessageActionPtr genSelfActionAction(QString message, bool isAction, const QDateTime &datetime);
ChatActionPtr genSystemInfoAction(const QString &message, const QString &type, const QDateTime &datetime); ChatActionPtr genSystemInfoAction(const QString &message, const QString &type, const QDateTime &datetime);