|
|
@ -19,6 +19,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "sessionchatlog.h" |
|
|
|
#include "sessionchatlog.h" |
|
|
|
#include "src/friendlist.h" |
|
|
|
#include "src/friendlist.h" |
|
|
|
|
|
|
|
#include "src/grouplist.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <QDebug> |
|
|
|
#include <QDebug> |
|
|
|
#include <QtGlobal> |
|
|
|
#include <QtGlobal> |
|
|
@ -105,6 +106,23 @@ firstItemAfterDate(QDate date, const std::map<ChatLogIdx, ChatLogItem>& items) |
|
|
|
return a.timestamp.date() < b.timestamp.date(); |
|
|
|
return a.timestamp.date() < b.timestamp.date(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString resolveToxPk(const ToxPk& pk) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Friend* f = FriendList::findFriend(pk); |
|
|
|
|
|
|
|
if (f) { |
|
|
|
|
|
|
|
return f->getDisplayedName(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Group* it : GroupList::getAllGroups()) { |
|
|
|
|
|
|
|
QString res = it->resolveToxId(pk); |
|
|
|
|
|
|
|
if (!res.isEmpty()) { |
|
|
|
|
|
|
|
return res; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return pk.toString(); |
|
|
|
|
|
|
|
} |
|
|
|
} // namespace
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
SessionChatLog::SessionChatLog(const ICoreIdHandler& coreIdHandler) |
|
|
|
SessionChatLog::SessionChatLog(const ICoreIdHandler& coreIdHandler) |
|
|
@ -121,6 +139,14 @@ SessionChatLog::SessionChatLog(ChatLogIdx initialIdx, const ICoreIdHandler& core |
|
|
|
|
|
|
|
|
|
|
|
SessionChatLog::~SessionChatLog() = default; |
|
|
|
SessionChatLog::~SessionChatLog() = default; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString SessionChatLog::resolveSenderNameFromSender(const ToxPk& sender) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
bool isSelf = sender == coreIdHandler.getSelfPublicKey(); |
|
|
|
|
|
|
|
QString myNickName = coreIdHandler.getUsername().isEmpty() ? sender.toString() : coreIdHandler.getUsername(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return isSelf ? myNickName : resolveToxPk(sender); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const ChatLogItem& SessionChatLog::at(ChatLogIdx idx) const |
|
|
|
const ChatLogItem& SessionChatLog::at(ChatLogIdx idx) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto item = items.find(idx); |
|
|
|
auto item = items.find(idx); |
|
|
@ -293,29 +319,21 @@ std::vector<IChatLog::DateChatLogIdxPair> SessionChatLog::getDateIdxs(const QDat |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SessionChatLog::insertCompleteMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, const QString& senderName, |
|
|
|
void SessionChatLog::insertCompleteMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, QString senderName, |
|
|
|
const ChatLogMessage& message) |
|
|
|
const ChatLogMessage& message) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto item = ChatLogItem(sender, message); |
|
|
|
auto item = ChatLogItem(sender, senderName, message); |
|
|
|
|
|
|
|
|
|
|
|
if (!senderName.isEmpty()) { |
|
|
|
|
|
|
|
item.setDisplayName(senderName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert(message.state == MessageState::complete); |
|
|
|
assert(message.state == MessageState::complete); |
|
|
|
|
|
|
|
|
|
|
|
items.emplace(idx, std::move(item)); |
|
|
|
items.emplace(idx, std::move(item)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SessionChatLog::insertIncompleteMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, const QString& senderName, |
|
|
|
void SessionChatLog::insertIncompleteMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, QString senderName, |
|
|
|
const ChatLogMessage& message, |
|
|
|
const ChatLogMessage& message, |
|
|
|
DispatchedMessageId dispatchId) |
|
|
|
DispatchedMessageId dispatchId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto item = ChatLogItem(sender, message); |
|
|
|
auto item = ChatLogItem(sender, senderName, message); |
|
|
|
|
|
|
|
|
|
|
|
if (!senderName.isEmpty()) { |
|
|
|
|
|
|
|
item.setDisplayName(senderName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert(message.state == MessageState::pending); |
|
|
|
assert(message.state == MessageState::pending); |
|
|
|
|
|
|
|
|
|
|
@ -323,27 +341,19 @@ void SessionChatLog::insertIncompleteMessageAtIdx(ChatLogIdx idx, const ToxPk& s |
|
|
|
outgoingMessages.insert(dispatchId, idx); |
|
|
|
outgoingMessages.insert(dispatchId, idx); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SessionChatLog::insertBrokenMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, const QString& senderName, |
|
|
|
void SessionChatLog::insertBrokenMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, QString senderName, |
|
|
|
const ChatLogMessage& message) |
|
|
|
const ChatLogMessage& message) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto item = ChatLogItem(sender, message); |
|
|
|
auto item = ChatLogItem(sender, senderName, message); |
|
|
|
|
|
|
|
|
|
|
|
if (!senderName.isEmpty()) { |
|
|
|
|
|
|
|
item.setDisplayName(senderName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert(message.state == MessageState::broken); |
|
|
|
assert(message.state == MessageState::broken); |
|
|
|
|
|
|
|
|
|
|
|
items.emplace(idx, std::move(item)); |
|
|
|
items.emplace(idx, std::move(item)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SessionChatLog::insertFileAtIdx(ChatLogIdx idx, const ToxPk& sender, const QString& senderName, const ChatLogFile& file) |
|
|
|
void SessionChatLog::insertFileAtIdx(ChatLogIdx idx, const ToxPk& sender, QString senderName, const ChatLogFile& file) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto item = ChatLogItem(sender, file); |
|
|
|
auto item = ChatLogItem(sender, senderName, file); |
|
|
|
|
|
|
|
|
|
|
|
if (!senderName.isEmpty()) { |
|
|
|
|
|
|
|
item.setDisplayName(senderName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
items.emplace(idx, std::move(item)); |
|
|
|
items.emplace(idx, std::move(item)); |
|
|
|
} |
|
|
|
} |
|
|
@ -359,7 +369,7 @@ void SessionChatLog::onMessageReceived(const ToxPk& sender, const Message& messa |
|
|
|
ChatLogMessage chatLogMessage; |
|
|
|
ChatLogMessage chatLogMessage; |
|
|
|
chatLogMessage.state = MessageState::complete; |
|
|
|
chatLogMessage.state = MessageState::complete; |
|
|
|
chatLogMessage.message = message; |
|
|
|
chatLogMessage.message = message; |
|
|
|
items.emplace(messageIdx, ChatLogItem(sender, chatLogMessage)); |
|
|
|
items.emplace(messageIdx, ChatLogItem(sender, resolveSenderNameFromSender(sender), chatLogMessage)); |
|
|
|
|
|
|
|
|
|
|
|
emit this->itemUpdated(messageIdx); |
|
|
|
emit this->itemUpdated(messageIdx); |
|
|
|
} |
|
|
|
} |
|
|
@ -375,7 +385,9 @@ void SessionChatLog::onMessageSent(DispatchedMessageId id, const Message& messag |
|
|
|
ChatLogMessage chatLogMessage; |
|
|
|
ChatLogMessage chatLogMessage; |
|
|
|
chatLogMessage.state = MessageState::pending; |
|
|
|
chatLogMessage.state = MessageState::pending; |
|
|
|
chatLogMessage.message = message; |
|
|
|
chatLogMessage.message = message; |
|
|
|
items.emplace(messageIdx, ChatLogItem(coreIdHandler.getSelfPublicKey(), chatLogMessage)); |
|
|
|
const ToxPk selfPk = coreIdHandler.getSelfPublicKey(); |
|
|
|
|
|
|
|
const QString selfName = resolveSenderNameFromSender(selfPk); |
|
|
|
|
|
|
|
items.emplace(messageIdx, ChatLogItem(selfPk, selfName, chatLogMessage)); |
|
|
|
|
|
|
|
|
|
|
|
outgoingMessages.insert(id, messageIdx); |
|
|
|
outgoingMessages.insert(id, messageIdx); |
|
|
|
|
|
|
|
|
|
|
@ -428,7 +440,7 @@ void SessionChatLog::onFileUpdated(const ToxPk& sender, const ToxFile& file) |
|
|
|
currentFileTransfers.push_back(currentTransfer); |
|
|
|
currentFileTransfers.push_back(currentTransfer); |
|
|
|
|
|
|
|
|
|
|
|
const auto chatLogFile = ChatLogFile{QDateTime::currentDateTime(), file}; |
|
|
|
const auto chatLogFile = ChatLogFile{QDateTime::currentDateTime(), file}; |
|
|
|
items.emplace(currentTransfer.idx, ChatLogItem(sender, chatLogFile)); |
|
|
|
items.emplace(currentTransfer.idx, ChatLogItem(sender, resolveSenderNameFromSender(sender), chatLogFile)); |
|
|
|
messageIdx = currentTransfer.idx; |
|
|
|
messageIdx = currentTransfer.idx; |
|
|
|
} else if (fileIt != currentFileTransfers.end()) { |
|
|
|
} else if (fileIt != currentFileTransfers.end()) { |
|
|
|
messageIdx = fileIt->idx; |
|
|
|
messageIdx = fileIt->idx; |
|
|
|