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

history fixes

This commit is contained in:
krepa098 2015-01-04 19:29:06 +01:00
parent 12a1fa1549
commit 6711fd6ee4
3 changed files with 34 additions and 31 deletions

View File

@ -688,20 +688,22 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
if (since > now) if (since > now)
return; return;
if (earliestMessage) if (!earliestMessage.isNull())
{ {
if (*earliestMessage < since) if (earliestMessage < since)
return; return;
if (*earliestMessage < now) if (earliestMessage < now)
{ {
now = *earliestMessage; now = earliestMessage;
now = now.addMSecs(-1); now = now.addMSecs(-1);
} }
} }
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().publicKey, since, now); auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().publicKey, since, now);
ToxID storedPrevId; ToxID storedPrevId = previousId;
ToxID prevId;
std::swap(storedPrevId, previousId); std::swap(storedPrevId, previousId);
QList<ChatMessage::Ptr> historyMessages; QList<ChatMessage::Ptr> historyMessages;
@ -714,20 +716,26 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
if (msgDate > lastDate) if (msgDate > lastDate)
{ {
lastDate = msgDate; lastDate = msgDate;
insertChatMessage(ChatMessage::createChatInfoMessage(msgDate.toString(), ChatMessage::INFO, QDateTime::currentDateTime())); historyMessages.prepend(ChatMessage::createChatInfoMessage(msgDate.toString(), ChatMessage::INFO, QDateTime::currentDateTime()));
} }
// Show each messages // Show each messages
ToxID msgSender = ToxID::fromString(it.sender); ToxID authorId = ToxID::fromString(it.sender);
QString authorStr = authorId.isMine() ? Core::getInstance()->getUsername() : resolveToxID(authorId);
bool isAction = it.message.startsWith("/me "); bool isAction = it.message.startsWith("/me ");
ChatMessage::Ptr msg = addMessage(msgSender, ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr,
isAction ? it.message.right(it.message.length() - 4) : it.message, isAction ? it.message.right(it.message.length() - 4) : it.message,
isAction, QDateTime::currentDateTime(), isAction, false,
false); authorId.isMine(),
QDateTime::currentDateTime());
if (it.isSent || !msgSender.isMine()) if(prevId == authorId)
msg->hideSender();
prevId = authorId;
if (it.isSent || !authorId.isMine())
{ {
msg->markAsSent(msgDateTime); msg->markAsSent(msgDateTime);
} }
@ -743,19 +751,19 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
registerReceipt(rec, it.id, msg); registerReceipt(rec, it.id, msg);
} }
} }
historyMessages.append(msg); historyMessages.prepend(msg);
} }
std::swap(storedPrevId, previousId);
// int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value(); previousId = storedPrevId;
int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value();
// if (earliestMessage != nullptr) earliestMessage = since;
// *earliestMessage = since;
// chatWidget->insertMessagesTop(historyMessages); for(ChatMessage::Ptr m : historyMessages)
chatWidget->insertChatlineOnTop(m);
// savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos; savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos;
// chatWidget->verticalScrollBar()->setValue(savedSliderPos); chatWidget->verticalScrollBar()->setValue(savedSliderPos);
} }
void ChatForm::onLoadHistory() void ChatForm::onLoadHistory()

View File

@ -32,9 +32,8 @@
#include "src/friend.h" #include "src/friend.h"
#include "src/chatlog/chatlog.h" #include "src/chatlog/chatlog.h"
GenericChatForm::GenericChatForm(QWidget *parent) : GenericChatForm::GenericChatForm(QWidget *parent)
QWidget(parent), : QWidget(parent)
earliestMessage(nullptr)
, audioInputFlag(false) , audioInputFlag(false)
, audioOutputFlag(false) , audioOutputFlag(false)
{ {
@ -300,11 +299,7 @@ void GenericChatForm::clearChatArea(bool notinform)
if (!notinform) if (!notinform)
addSystemInfoMessage(tr("Cleared"), ChatMessage::INFO, QDateTime::currentDateTime()); addSystemInfoMessage(tr("Cleared"), ChatMessage::INFO, QDateTime::currentDateTime());
if (earliestMessage) earliestMessage = QDateTime(); //null
{
delete earliestMessage;
earliestMessage = nullptr;
}
emit chatAreaCleared(); emit chatAreaCleared();
} }
@ -329,5 +324,5 @@ QString GenericChatForm::resolveToxID(const ToxID &id)
void GenericChatForm::insertChatMessage(ChatMessage::Ptr msg) void GenericChatForm::insertChatMessage(ChatMessage::Ptr msg)
{ {
chatWidget->insertChatline(std::dynamic_pointer_cast<ChatLine>(msg)); chatWidget->insertChatlineAtBottom(std::dynamic_pointer_cast<ChatLine>(msg));
} }

View File

@ -89,7 +89,7 @@ protected:
ChatTextEdit *msgEdit; ChatTextEdit *msgEdit;
QPushButton *sendButton; QPushButton *sendButton;
ChatLog *chatWidget; ChatLog *chatWidget;
QDateTime *earliestMessage; QDateTime earliestMessage;
bool audioInputFlag; bool audioInputFlag;
bool audioOutputFlag; bool audioOutputFlag;
}; };