Browse Source

feat: add action "Go to current date"

reviewable/pr5672/r5
TriKriSta 7 years ago
parent
commit
2a9648d12c
  1. 9
      src/model/chathistory.cpp
  2. 1
      src/model/chathistory.h
  3. 2
      src/model/ichatlog.h
  4. 5
      src/model/sessionchatlog.cpp
  5. 1
      src/model/sessionchatlog.h
  6. 18
      src/widget/form/genericchatform.cpp
  7. 2
      src/widget/form/genericchatform.h

9
src/model/chathistory.cpp

@ -220,6 +220,15 @@ std::vector<IChatLog::DateChatLogIdxPair> ChatHistory::getDateIdxs(const QDate& @@ -220,6 +220,15 @@ std::vector<IChatLog::DateChatLogIdxPair> ChatHistory::getDateIdxs(const QDate&
}
}
std::size_t ChatHistory::size() const
{
if (canUseHistory()) {
return history->getNumMessagesForFriend(f.getPublicKey());
}
return sessionChatLog.size();
}
void ChatHistory::onFileUpdated(const ToxPk& sender, const ToxFile& file)
{
if (canUseHistory()) {

1
src/model/chathistory.h

@ -42,6 +42,7 @@ public: @@ -42,6 +42,7 @@ public:
ChatLogIdx getFirstIdx() const override;
ChatLogIdx getNextIdx() const override;
std::vector<DateChatLogIdxPair> getDateIdxs(const QDate& startDate, size_t maxDates) const override;
std::size_t size() const override;
public slots:
void onFileUpdated(const ToxPk& sender, const ToxFile& file);

2
src/model/ichatlog.h

@ -138,6 +138,8 @@ public: @@ -138,6 +138,8 @@ public:
virtual std::vector<DateChatLogIdxPair> getDateIdxs(const QDate& startDate,
size_t maxDates) const = 0;
virtual std::size_t size() const = 0;
signals:
void itemUpdated(ChatLogIdx idx);
};

5
src/model/sessionchatlog.cpp

@ -289,6 +289,11 @@ std::vector<IChatLog::DateChatLogIdxPair> SessionChatLog::getDateIdxs(const QDat @@ -289,6 +289,11 @@ std::vector<IChatLog::DateChatLogIdxPair> SessionChatLog::getDateIdxs(const QDat
return ret;
}
std::size_t SessionChatLog::size() const
{
return items.size();
}
void SessionChatLog::insertMessageAtIdx(ChatLogIdx idx, ToxPk sender, QString senderName,
ChatLogMessage message)
{

1
src/model/sessionchatlog.h

@ -45,6 +45,7 @@ public: @@ -45,6 +45,7 @@ public:
ChatLogIdx getFirstIdx() const override;
ChatLogIdx getNextIdx() const override;
std::vector<DateChatLogIdxPair> getDateIdxs(const QDate& startDate, size_t maxDates) const override;
std::size_t size() const override;
void insertMessageAtIdx(ChatLogIdx idx, ToxPk sender, QString senderName, ChatLogMessage message);
void insertFileAtIdx(ChatLogIdx idx, ToxPk sender, QString senderName, ChatLogFile file);

18
src/widget/form/genericchatform.cpp

@ -328,6 +328,13 @@ GenericChatForm::GenericChatForm(const Contact* contact, IChatLog& chatLog, @@ -328,6 +328,13 @@ GenericChatForm::GenericChatForm(const Contact* contact, IChatLog& chatLog,
quoteAction = menu.addAction(QIcon(), QString(), this, SLOT(quoteSelectedText()),
QKeySequence(Qt::ALT + Qt::Key_Q));
addAction(quoteAction);
menu.addSeparator();
goCurrentDateAction = menu.addAction(QIcon(), QString(), this, SLOT(goToCurrentDate()),
QKeySequence(Qt::CTRL + Qt::Key_G));
addAction(goCurrentDateAction);
menu.addSeparator();
searchAction = menu.addAction(QIcon(), QString(), this, SLOT(searchFormShow()),
@ -1004,6 +1011,16 @@ void GenericChatForm::renderMessages(ChatLogIdx begin, ChatLogIdx end, @@ -1004,6 +1011,16 @@ void GenericChatForm::renderMessages(ChatLogIdx begin, ChatLogIdx end,
}
}
void GenericChatForm::goToCurrentDate()
{
chatWidget->clear();
messages.clear();
auto end = ChatLogIdx(chatLog.size() - 1);
auto begin = end.get() > 100 ? ChatLogIdx(end.get() - 100) : ChatLogIdx(0);
renderMessages(begin, end);
}
void GenericChatForm::loadHistoryLower()
{
auto end = messages.begin()->first;
@ -1050,6 +1067,7 @@ void GenericChatForm::retranslateUi() @@ -1050,6 +1067,7 @@ void GenericChatForm::retranslateUi()
quoteAction->setText(tr("Quote selected text"));
copyLinkAction->setText(tr("Copy link address"));
searchAction->setText(tr("Search in text"));
goCurrentDateAction->setText(tr("Go to current date"));
loadHistoryAction->setText(tr("Load chat history..."));
exportChatAction->setText(tr("Export to file"));
}

2
src/widget/form/genericchatform.h

@ -126,6 +126,7 @@ protected slots: @@ -126,6 +126,7 @@ protected slots:
void renderMessage(ChatLogIdx idx);
void renderMessages(ChatLogIdx begin, ChatLogIdx end,
std::function<void(void)> onCompletion = std::function<void(void)>());
void goToCurrentDate();
void loadHistoryLower();
void loadHistoryUpper();
@ -165,6 +166,7 @@ protected: @@ -165,6 +166,7 @@ protected:
QAction* searchAction;
QAction* loadHistoryAction;
QAction* exportChatAction;
QAction* goCurrentDateAction;
ToxPk previousId;

Loading…
Cancel
Save