mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(activity): change last activity time from QDate to QDateTime
* Allows for strict sorting based on last activity in the future
This commit is contained in:
parent
ca397aebbf
commit
d55332ee0a
|
@ -38,8 +38,8 @@ public:
|
|||
virtual int getFriendCircleID(const ToxPk& pk) const = 0;
|
||||
virtual void setFriendCircleID(const ToxPk& pk, int circleID) = 0;
|
||||
|
||||
virtual QDate getFriendActivity(const ToxPk& pk) const = 0;
|
||||
virtual void setFriendActivity(const ToxPk& pk, const QDate& date) = 0;
|
||||
virtual QDateTime getFriendActivity(const ToxPk& pk) const = 0;
|
||||
virtual void setFriendActivity(const ToxPk& pk, const QDateTime& date) = 0;
|
||||
|
||||
virtual void saveFriendSettings(const ToxPk& pk) = 0;
|
||||
virtual void removeFriendSettings(const ToxPk& pk) = 0;
|
||||
|
|
|
@ -319,7 +319,7 @@ void Settings::loadPersonal(QString profileName, const ToxEncrypt* passKey)
|
|||
fp.circleID = ps.value("circle", -1).toInt();
|
||||
|
||||
if (getEnableLogging())
|
||||
fp.activity = ps.value("activity", QDate()).toDate();
|
||||
fp.activity = ps.value("activity", QDateTime()).toDateTime();
|
||||
friendLst.insert(ToxId(fp.addr).getPublicKey().getByteArray(), fp);
|
||||
}
|
||||
ps.endArray();
|
||||
|
@ -2031,17 +2031,17 @@ void Settings::setFriendCircleID(const ToxPk& id, int circleID)
|
|||
frnd.circleID = circleID;
|
||||
}
|
||||
|
||||
QDate Settings::getFriendActivity(const ToxPk& id) const
|
||||
QDateTime Settings::getFriendActivity(const ToxPk& id) const
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
auto it = friendLst.find(id.getByteArray());
|
||||
if (it != friendLst.end())
|
||||
return it->activity;
|
||||
|
||||
return QDate();
|
||||
return QDateTime();
|
||||
}
|
||||
|
||||
void Settings::setFriendActivity(const ToxPk& id, const QDate& activity)
|
||||
void Settings::setFriendActivity(const ToxPk& id, const QDateTime& activity)
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
auto& frnd = getOrInsertFriendPropRef(id);
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include "src/persistence/ifriendsettings.h"
|
||||
#include "src/video/ivideosettings.h"
|
||||
|
||||
#include <QDate>
|
||||
#include <QDateTime>
|
||||
#include <QFlags>
|
||||
#include <QFont>
|
||||
#include <QHash>
|
||||
|
@ -497,8 +497,8 @@ public:
|
|||
int getFriendCircleID(const ToxPk& id) const override;
|
||||
void setFriendCircleID(const ToxPk& id, int circleID) override;
|
||||
|
||||
QDate getFriendActivity(const ToxPk& id) const override;
|
||||
void setFriendActivity(const ToxPk& id, const QDate& date) override;
|
||||
QDateTime getFriendActivity(const ToxPk& id) const override;
|
||||
void setFriendActivity(const ToxPk& id, const QDateTime& date) override;
|
||||
|
||||
void saveFriendSettings(const ToxPk& id) override;
|
||||
void removeFriendSettings(const ToxPk& id) override;
|
||||
|
@ -699,7 +699,7 @@ private:
|
|||
QString autoAcceptDir = "";
|
||||
QString note = "";
|
||||
int circleID = -1;
|
||||
QDate activity = QDate();
|
||||
QDateTime activity = QDateTime();
|
||||
AutoAcceptCallFlags autoAcceptCall;
|
||||
bool autoGroupInvite = false;
|
||||
};
|
||||
|
|
|
@ -536,7 +536,7 @@ void ChatForm::searchInBegin(const QString& phrase, const ParameterSearch& param
|
|||
const bool isFirst = (parameter.period == PeriodSearch::WithTheFirst);
|
||||
const bool isAfter = (parameter.period == PeriodSearch::AfterDate);
|
||||
if (isFirst || isAfter) {
|
||||
if (isFirst || (isAfter && parameter.date < getFirstDate())) {
|
||||
if (isFirst || (isAfter && parameter.date < getFirstTime().date())) {
|
||||
const QString pk = f->getPublicKey().toString();
|
||||
if ((isFirst || parameter.date >= history->getStartDateChatHistory(pk).date())
|
||||
&& loadHistory(phrase, parameter)) {
|
||||
|
@ -547,7 +547,7 @@ void ChatForm::searchInBegin(const QString& phrase, const ParameterSearch& param
|
|||
|
||||
onSearchDown(phrase, parameter);
|
||||
} else {
|
||||
if (parameter.period == PeriodSearch::BeforeDate && parameter.date < getFirstDate()) {
|
||||
if (parameter.period == PeriodSearch::BeforeDate && parameter.date < getFirstTime().date()) {
|
||||
const QString pk = f->getPublicKey().toString();
|
||||
if (parameter.date >= history->getStartDateChatHistory(pk).date()
|
||||
&& loadHistory(phrase, parameter)) {
|
||||
|
@ -1167,7 +1167,7 @@ bool ChatForm::loadHistory(const QString& phrase, const ParameterSearch& paramet
|
|||
const QDateTime newBaseDate =
|
||||
history->getDateWhereFindPhrase(pk, earliestMessage, phrase, parameter);
|
||||
|
||||
if (newBaseDate.isValid() && getFirstDate().isValid() && newBaseDate.date() < getFirstDate()) {
|
||||
if (newBaseDate.isValid() && getFirstTime().isValid() && newBaseDate.date() < getFirstTime().date()) {
|
||||
searchAfterLoadHistory = true;
|
||||
loadHistoryByDateRange(newBaseDate);
|
||||
|
||||
|
|
|
@ -285,14 +285,14 @@ void GenericChatForm::hideFileMenu()
|
|||
fileFlyout->animateHide();
|
||||
}
|
||||
|
||||
QDate GenericChatForm::getLatestDate() const
|
||||
QDateTime GenericChatForm::getLatestTime() const
|
||||
{
|
||||
return getDate(chatWidget->getLatestLine());
|
||||
return getTime(chatWidget->getLatestLine());
|
||||
}
|
||||
|
||||
QDate GenericChatForm::getFirstDate() const
|
||||
QDateTime GenericChatForm::getFirstTime() const
|
||||
{
|
||||
return getDate(chatWidget->getFirstLine());
|
||||
return getTime(chatWidget->getFirstLine());
|
||||
}
|
||||
|
||||
void GenericChatForm::reloadTheme()
|
||||
|
@ -401,7 +401,8 @@ ChatMessage::Ptr GenericChatForm::createMessage(const ToxPk& author, const QStri
|
|||
bool isSelf = author == core->getSelfId().getPublicKey();
|
||||
QString myNickName = core->getUsername().isEmpty() ? author.toString() : core->getUsername();
|
||||
QString authorStr = isSelf ? myNickName : resolveToxPk(author);
|
||||
if (getLatestDate() != QDate::currentDate()) {
|
||||
const auto now = QDateTime::currentDateTime();
|
||||
if (getLatestTime().date() != now.date()) {
|
||||
addSystemDateMessage();
|
||||
}
|
||||
|
||||
|
@ -411,13 +412,12 @@ ChatMessage::Ptr GenericChatForm::createMessage(const ToxPk& author, const QStri
|
|||
previousId = ToxPk{};
|
||||
} else {
|
||||
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, isSelf, QDateTime(), colorizeName);
|
||||
const QDateTime newMsgDateTime = QDateTime::currentDateTime();
|
||||
if (needsToHideName(author, newMsgDateTime)) {
|
||||
if (needsToHideName(author, now)) {
|
||||
msg->hideSender();
|
||||
}
|
||||
|
||||
previousId = author;
|
||||
prevMsgDateTime = newMsgDateTime;
|
||||
prevMsgDateTime = now;
|
||||
}
|
||||
|
||||
if (isSent) {
|
||||
|
@ -552,7 +552,7 @@ void GenericChatForm::onChatMessageFontChanged(const QFont& font)
|
|||
void GenericChatForm::addSystemInfoMessage(const QString& message, ChatMessage::SystemMessageType type,
|
||||
const QDateTime& datetime)
|
||||
{
|
||||
if (getLatestDate() != QDate::currentDate()) {
|
||||
if (getLatestTime().date() != QDate::currentDate()) {
|
||||
addSystemDateMessage();
|
||||
}
|
||||
|
||||
|
@ -569,19 +569,19 @@ void GenericChatForm::addSystemDateMessage()
|
|||
insertChatMessage(ChatMessage::createChatInfoMessage(dateText, ChatMessage::INFO, QDateTime()));
|
||||
}
|
||||
|
||||
QDate GenericChatForm::getDate(const ChatLine::Ptr &chatLine) const
|
||||
QDateTime GenericChatForm::getTime(const ChatLine::Ptr &chatLine) const
|
||||
{
|
||||
if (chatLine) {
|
||||
Timestamp* const timestamp = qobject_cast<Timestamp*>(chatLine->getContent(2));
|
||||
|
||||
if (timestamp) {
|
||||
return timestamp->getTime().date();
|
||||
return timestamp->getTime();
|
||||
} else {
|
||||
return QDate::currentDate();
|
||||
return QDateTime::currentDateTime();
|
||||
}
|
||||
}
|
||||
|
||||
return QDate();
|
||||
return QDateTime();
|
||||
}
|
||||
|
||||
void GenericChatForm::disableSearchText()
|
||||
|
@ -625,7 +625,7 @@ bool GenericChatForm::searchInText(const QString& phrase, const ParameterSearch&
|
|||
startLine = 0;
|
||||
} else if (parameter.period == PeriodSearch::AfterDate) {
|
||||
const auto lambda = [=](const ChatLine::Ptr& item) {
|
||||
const auto d = getDate(item);
|
||||
const auto d = getTime(item).date();
|
||||
return d.isValid() && parameter.date <= d;
|
||||
};
|
||||
|
||||
|
@ -637,7 +637,7 @@ bool GenericChatForm::searchInText(const QString& phrase, const ParameterSearch&
|
|||
} else if (parameter.period == PeriodSearch::BeforeDate) {
|
||||
#if QT_VERSION > QT_VERSION_CHECK(5, 6, 0)
|
||||
const auto lambda = [=](const ChatLine::Ptr& item) {
|
||||
const auto d = getDate(item);
|
||||
const auto d = getTime(item).date();
|
||||
return d.isValid() && parameter.date >= d;
|
||||
};
|
||||
|
||||
|
@ -648,7 +648,7 @@ bool GenericChatForm::searchInText(const QString& phrase, const ParameterSearch&
|
|||
}
|
||||
#else
|
||||
for (int i = lines.size() - 1; i >= 0; --i) {
|
||||
auto d = getDate(lines[i]);
|
||||
auto d = getTime(lines[i]).date();
|
||||
if (d.isValid() && parameter.date >= d) {
|
||||
startLine = i;
|
||||
break;
|
||||
|
@ -1001,9 +1001,9 @@ void GenericChatForm::onSearchTriggered()
|
|||
|
||||
void GenericChatForm::updateShowDateInfo(const ChatLine::Ptr& line)
|
||||
{
|
||||
const auto date = getDate(line);
|
||||
const auto date = getTime(line);
|
||||
|
||||
if (date.isValid() && date != QDate::currentDate()) {
|
||||
if (date.isValid() && date != QDateTime::currentDateTime()) {
|
||||
const auto dateText = QStringLiteral("<b>%1<\b>").arg(date.toString(Settings::getInstance().getDateFormat()));
|
||||
dateInfo->setText(dateText);
|
||||
dateInfo->setVisible(true);
|
||||
|
|
|
@ -82,8 +82,8 @@ public:
|
|||
const QDateTime& datetime);
|
||||
void addAlertMessage(const ToxPk& author, const QString& message, const QDateTime& datetime, bool colorizeName = false);
|
||||
static QString resolveToxPk(const ToxPk& pk);
|
||||
QDate getLatestDate() const;
|
||||
QDate getFirstDate() const;
|
||||
QDateTime getLatestTime() const;
|
||||
QDateTime getFirstTime() const;
|
||||
|
||||
signals:
|
||||
void sendMessage(uint32_t, QString);
|
||||
|
@ -125,7 +125,7 @@ protected slots:
|
|||
private:
|
||||
void retranslateUi();
|
||||
void addSystemDateMessage();
|
||||
QDate getDate(const ChatLine::Ptr& chatLine) const;
|
||||
QDateTime getTime(const ChatLine::Ptr& chatLine) const;
|
||||
|
||||
protected:
|
||||
ChatMessage::Ptr createMessage(const ToxPk& author, const QString& message,
|
||||
|
|
|
@ -52,9 +52,9 @@ enum class Time
|
|||
|
||||
static const int LAST_TIME = static_cast<int>(Time::Never);
|
||||
|
||||
Time getTime(const QDate& date)
|
||||
Time getTimeBucket(const QDateTime& date)
|
||||
{
|
||||
if (date == QDate()) {
|
||||
if (date == QDateTime()) {
|
||||
return Time::Never;
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ Time getTime(const QDate& date)
|
|||
// clang-format on
|
||||
|
||||
for (Time time : dates.keys()) {
|
||||
if (dates[time] <= date) {
|
||||
if (dates[time] <= date.date()) {
|
||||
return time;
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ Time getTime(const QDate& date)
|
|||
return Time::LongAgo;
|
||||
}
|
||||
|
||||
QDate getDateFriend(const Friend* contact)
|
||||
QDateTime getActiveTimeFriend(const Friend* contact)
|
||||
{
|
||||
return Settings::getInstance().getFriendActivity(contact->getPublicKey());
|
||||
}
|
||||
|
@ -263,10 +263,10 @@ void FriendListWidget::moveFriends(QLayout* layout)
|
|||
circleWidget->moveFriendWidgets(this);
|
||||
} else if (friendWidget) {
|
||||
const Friend* contact = friendWidget->getFriend();
|
||||
QDate activityDate = getDateFriend(contact);
|
||||
int time = static_cast<int>(getTime(activityDate));
|
||||
const auto activityTime = getActiveTimeFriend(contact);
|
||||
int timeIndex = static_cast<int>(getTimeBucket(activityTime));
|
||||
|
||||
QWidget* w = activityLayout->itemAt(time)->widget();
|
||||
QWidget* w = activityLayout->itemAt(timeIndex)->widget();
|
||||
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(w);
|
||||
categoryWidget->addFriendWidget(friendWidget, contact->getStatus());
|
||||
}
|
||||
|
@ -309,9 +309,9 @@ void FriendListWidget::removeFriendWidget(FriendWidget* w)
|
|||
{
|
||||
const Friend* contact = w->getFriend();
|
||||
if (mode == Activity) {
|
||||
QDate activityDate = getDateFriend(contact);
|
||||
int time = static_cast<int>(getTime(activityDate));
|
||||
QWidget* widget = activityLayout->itemAt(time)->widget();
|
||||
const auto activityTime = getActiveTimeFriend(contact);
|
||||
int timeIndex = static_cast<int>(getTimeBucket(activityTime));
|
||||
QWidget* widget = activityLayout->itemAt(timeIndex)->widget();
|
||||
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(widget);
|
||||
categoryWidget->removeFriendWidget(w, contact->getStatus());
|
||||
categoryWidget->setVisible(categoryWidget->hasChatrooms());
|
||||
|
@ -401,9 +401,9 @@ void FriendListWidget::onFriendWidgetRenamed(FriendWidget* friendWidget)
|
|||
const Friend* contact = friendWidget->getFriend();
|
||||
auto status = contact->getStatus();
|
||||
if (mode == Activity) {
|
||||
QDate activityDate = getDateFriend(contact);
|
||||
int time = static_cast<int>(getTime(activityDate));
|
||||
QWidget* widget = activityLayout->itemAt(time)->widget();
|
||||
const auto activityTime = getActiveTimeFriend(contact);
|
||||
int timeIndex = static_cast<int>(getTimeBucket(activityTime));
|
||||
QWidget* widget = activityLayout->itemAt(timeIndex)->widget();
|
||||
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(widget);
|
||||
categoryWidget->removeFriendWidget(friendWidget, status);
|
||||
categoryWidget->addFriendWidget(friendWidget, status);
|
||||
|
@ -452,8 +452,8 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
|||
return;
|
||||
}
|
||||
|
||||
QDate activityDate = getDateFriend(friendWidget->getFriend());
|
||||
index = static_cast<int>(getTime(activityDate));
|
||||
const auto activityTime = getActiveTimeFriend(friendWidget->getFriend());
|
||||
index = static_cast<int>(getTimeBucket(activityTime));
|
||||
QWidget* widget = activityLayout->itemAt(index)->widget();
|
||||
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(widget);
|
||||
|
||||
|
@ -627,22 +627,22 @@ void FriendListWidget::moveWidget(FriendWidget* widget, Status::Status s, bool a
|
|||
circleWidget->addFriendWidget(widget, s);
|
||||
} else {
|
||||
const Friend* contact = widget->getFriend();
|
||||
QDate activityDate = getDateFriend(contact);
|
||||
int time = static_cast<int>(getTime(activityDate));
|
||||
QWidget* w = activityLayout->itemAt(time)->widget();
|
||||
const auto activityTime = getActiveTimeFriend(contact);
|
||||
int timeIndex = static_cast<int>(getTimeBucket(activityTime));
|
||||
QWidget* w = activityLayout->itemAt(timeIndex)->widget();
|
||||
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(w);
|
||||
categoryWidget->addFriendWidget(widget, contact->getStatus());
|
||||
categoryWidget->show();
|
||||
}
|
||||
}
|
||||
|
||||
void FriendListWidget::updateActivityDate(const QDate& date)
|
||||
void FriendListWidget::updateActivityTime(const QDateTime& time)
|
||||
{
|
||||
if (mode != Activity)
|
||||
return;
|
||||
|
||||
int time = static_cast<int>(getTime(date));
|
||||
QWidget* widget = activityLayout->itemAt(time)->widget();
|
||||
int timeIndex = static_cast<int>(getTimeBucket(time));
|
||||
QWidget* widget = activityLayout->itemAt(timeIndex)->widget();
|
||||
CategoryWidget* categoryWidget = static_cast<CategoryWidget*>(widget);
|
||||
categoryWidget->updateStatus();
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ public:
|
|||
|
||||
void cycleContacts(GenericChatroomWidget* activeChatroomWidget, bool forward);
|
||||
|
||||
void updateActivityDate(const QDate& date);
|
||||
void updateActivityTime(const QDateTime& date);
|
||||
void reDraw();
|
||||
|
||||
signals:
|
||||
|
|
|
@ -1001,10 +1001,10 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
|
|||
friendWidgets[friendPk] = widget;
|
||||
chatForms[friendPk] = friendForm;
|
||||
|
||||
QDate activityDate = settings.getFriendActivity(friendPk);
|
||||
QDate chatDate = friendForm->getLatestDate();
|
||||
if (chatDate > activityDate && chatDate.isValid()) {
|
||||
settings.setFriendActivity(friendPk, chatDate);
|
||||
const auto activityTime = settings.getFriendActivity(friendPk);
|
||||
const auto chatTime = friendForm->getLatestTime();
|
||||
if (chatTime > activityTime && chatTime.isValid()) {
|
||||
settings.setFriendActivity(friendPk, chatTime);
|
||||
}
|
||||
|
||||
contactListWidget->addFriendWidget(widget, Status::Status::Offline, settings.getFriendCircleID(friendPk));
|
||||
|
@ -1493,15 +1493,12 @@ void Widget::onFriendRequestReceived(const ToxPk& friendPk, const QString& messa
|
|||
void Widget::updateFriendActivity(const Friend* frnd)
|
||||
{
|
||||
const ToxPk& pk = frnd->getPublicKey();
|
||||
QDate date = settings.getFriendActivity(pk);
|
||||
if (date != QDate::currentDate()) {
|
||||
// Update old activity before after new one. Store old date first.
|
||||
QDate oldDate = settings.getFriendActivity(pk);
|
||||
settings.setFriendActivity(pk, QDate::currentDate());
|
||||
FriendWidget* widget = friendWidgets[frnd->getPublicKey()];
|
||||
contactListWidget->moveWidget(widget, frnd->getStatus());
|
||||
contactListWidget->updateActivityDate(oldDate);
|
||||
}
|
||||
const auto oldTime = settings.getFriendActivity(pk);
|
||||
const auto newTime = QDateTime::currentDateTime();
|
||||
settings.setFriendActivity(pk, newTime);
|
||||
FriendWidget* widget = friendWidgets[frnd->getPublicKey()];
|
||||
contactListWidget->moveWidget(widget, frnd->getStatus());
|
||||
contactListWidget->updateActivityTime(oldTime); // update old category widget
|
||||
}
|
||||
|
||||
void Widget::removeFriend(Friend* f, bool fake)
|
||||
|
|
Loading…
Reference in New Issue
Block a user