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

Circles: Use history for activity, fix search

This commit is contained in:
TheSpiritXIII 2015-06-18 11:27:50 -04:00 committed by tux3
parent d9d6f20bf7
commit 79424de10a
6 changed files with 64 additions and 13 deletions

View File

@ -392,6 +392,26 @@ void HistoryKeeper::markAsSent(int m_id)
db->exec(QString("UPDATE sent_status SET status = 1 WHERE id = %1;").arg(m_id)); db->exec(QString("UPDATE sent_status SET status = 1 WHERE id = %1;").arg(m_id));
} }
QDate HistoryKeeper::getLatestDate(const QString &chat)
{
int chat_id = getChatID(chat, ctSingle).first;
QSqlQuery dbAnswer;
dbAnswer = db->exec(QString("SELECT MAX(timestamp) FROM history LEFT JOIN sent_status ON history.id = sent_status.id ") +
QString("INNER JOIN aliases ON history.sender = aliases.id AND chat_id = %3;")
.arg(chat_id));
if (dbAnswer.first())
{
qint64 timeInt = dbAnswer.value(0).toLongLong();
if (timeInt != 0)
return QDateTime::fromMSecsSinceEpoch(timeInt).date();
}
return QDate();
}
void HistoryKeeper::setSyncType(Db::syncType sType) void HistoryKeeper::setSyncType(Db::syncType sType)
{ {
QString syncCmd; QString syncCmd;

View File

@ -62,6 +62,7 @@ public:
qint64 addGroupChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt); qint64 addGroupChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt);
QList<HistMessage> getChatHistory(ChatType ct, const QString &chat, const QDateTime &time_from, const QDateTime &time_to); QList<HistMessage> getChatHistory(ChatType ct, const QString &chat, const QDateTime &time_from, const QDateTime &time_to);
void markAsSent(int m_id); void markAsSent(int m_id);
QDate getLatestDate(const QString& chat);
QList<HistMessage> exportMessages(); QList<HistMessage> exportMessages();
void importMessages(const QList<HistoryKeeper::HistMessage> &lst); void importMessages(const QList<HistoryKeeper::HistMessage> &lst);

View File

@ -296,7 +296,8 @@ void Settings::loadPersonnal(Profile* profile)
fp.alias = ps.value("alias").toString(); fp.alias = ps.value("alias").toString();
fp.autoAcceptDir = ps.value("autoAcceptDir").toString(); fp.autoAcceptDir = ps.value("autoAcceptDir").toString();
fp.circleID = ps.value("circle", -1).toInt(); fp.circleID = ps.value("circle", -1).toInt();
fp.activity = ps.value("activity").toDate(); fp.activity = ps.value("activity", QDate()).toDate();
friendLst[ToxId(fp.addr).publicKey] = fp; friendLst[ToxId(fp.addr).publicKey] = fp;
} }
ps.endArray(); ps.endArray();

View File

@ -285,7 +285,7 @@ void CategoryWidget::onCompactChanged(bool _compact)
mainLayout->setSpacing(0); mainLayout->setSpacing(0);
mainLayout->setContentsMargins(20, 0, 20, 0); mainLayout->setContentsMargins(20, 0, 20, 0);
container->setFixedHeight(55); container->setFixedHeight(35);
container->setLayout(mainLayout); container->setLayout(mainLayout);
topLayout->addWidget(&statusPic); topLayout->addWidget(&statusPic);

View File

@ -26,6 +26,7 @@
#include "groupwidget.h" #include "groupwidget.h"
#include "circlewidget.h" #include "circlewidget.h"
#include "widget.h" #include "widget.h"
#include "src/persistence/historykeeper.h"
#include <QGridLayout> #include <QGridLayout>
#include <QMimeData> #include <QMimeData>
#include <QDragEnterEvent> #include <QDragEnterEvent>
@ -108,6 +109,16 @@ Time getTime(const QDate date)
return LongAgo; return LongAgo;
} }
QDate getDateFriend(Friend* contact)
{
QDate date = Settings::getInstance().getFriendActivity(contact->getToxId());
if (date.isNull() && Settings::getInstance().getEnableLogging())
date = HistoryKeeper::getInstance()->getLatestDate(contact->getToxId().publicKey);
return date;
}
FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop) FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
: QWidget(parent) : QWidget(parent)
// Prevent Valgrind from complaining. We're changing this to Name here. // Prevent Valgrind from complaining. We're changing this to Name here.
@ -164,6 +175,7 @@ void FriendListWidget::setMode(Mode mode)
return; return;
this->mode = mode; this->mode = mode;
if (mode == Name) if (mode == Name)
{ {
circleLayout = new GenericChatItemLayout; circleLayout = new GenericChatItemLayout;
@ -171,7 +183,10 @@ void FriendListWidget::setMode(Mode mode)
circleLayout->getLayout()->setMargin(0); circleLayout->getLayout()->setMargin(0);
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i) for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
{
addCircleWidget(i); addCircleWidget(i);
CircleWidget::getFromID(i)->setVisible(false);
}
QList<Friend*> friendList = FriendList::getAllFriends(); QList<Friend*> friendList = FriendList::getAllFriends();
for (Friend* contact : friendList) for (Friend* contact : friendList)
@ -180,7 +195,6 @@ void FriendListWidget::setMode(Mode mode)
addFriendWidget(contact->getFriendWidget(), contact->getStatus(), circleId); addFriendWidget(contact->getFriendWidget(), contact->getStatus(), circleId);
} }
listLayout->removeItem(activityLayout);
listLayout->addLayout(listLayout->getLayoutOnline()); listLayout->addLayout(listLayout->getLayoutOnline());
listLayout->addLayout(listLayout->getLayoutOffline()); listLayout->addLayout(listLayout->getLayoutOffline());
listLayout->addLayout(circleLayout->getLayout()); listLayout->addLayout(circleLayout->getLayout());
@ -261,7 +275,7 @@ void FriendListWidget::setMode(Mode mode)
QList<Friend*> friendList = FriendList::getAllFriends(); QList<Friend*> friendList = FriendList::getAllFriends();
for (Friend* contact : friendList) for (Friend* contact : friendList)
{ {
QDate activityDate = Settings::getInstance().getFriendActivity(contact->getToxId()); QDate activityDate = getDateFriend(contact);
Time time = getTime(activityDate); Time time = getTime(activityDate);
CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(time)->widget()); CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(time)->widget());
categoryWidget->addFriendWidget(contact->getFriendWidget(), contact->getStatus()); categoryWidget->addFriendWidget(contact->getFriendWidget(), contact->getStatus());
@ -270,7 +284,7 @@ void FriendListWidget::setMode(Mode mode)
for (int i = 0; i < activityLayout->count(); ++i) for (int i = 0; i < activityLayout->count(); ++i)
{ {
CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(i)->widget()); CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(i)->widget());
categoryWidget->setVisible(categoryWidget->hasChatrooms()); categoryWidget->setVisible(categoryWidget->hasChatrooms());
} }
listLayout->removeItem(listLayout->getLayoutOnline()); listLayout->removeItem(listLayout->getLayoutOnline());
@ -303,10 +317,6 @@ void FriendListWidget::addGroupWidget(GroupWidget* widget)
{ {
groupLayout.addSortedWidget(widget); groupLayout.addSortedWidget(widget);
connect(widget, &GroupWidget::renameRequested, this, &FriendListWidget::renameGroupWidget); connect(widget, &GroupWidget::renameRequested, this, &FriendListWidget::renameGroupWidget);
// Only rename group if groups are visible.
if (Widget::getInstance()->groupsVisible())
widget->editName();
} }
void FriendListWidget::addFriendWidget(FriendWidget* w, Status s, int circleIndex) void FriendListWidget::addFriendWidget(FriendWidget* w, Status s, int circleIndex)
@ -323,7 +333,7 @@ void FriendListWidget::removeFriendWidget(FriendWidget* w)
Friend* contact = FriendList::findFriend(w->friendId); Friend* contact = FriendList::findFriend(w->friendId);
if (mode == Activity) if (mode == Activity)
{ {
QDate activityDate = Settings::getInstance().getFriendActivity(contact->getToxId()); QDate activityDate = getDateFriend(contact);
Time time = getTime(activityDate); Time time = getTime(activityDate);
CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(time)->widget()); CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(time)->widget());
categoryWidget->removeFriendWidget(w, contact->getStatus()); categoryWidget->removeFriendWidget(w, contact->getStatus());
@ -373,6 +383,7 @@ void FriendListWidget::searchChatrooms(const QString &searchString, bool hideOnl
{ {
groupLayout.search(searchString, hideGroups); groupLayout.search(searchString, hideGroups);
listLayout->searchChatrooms(searchString, hideOnline, hideOffline); listLayout->searchChatrooms(searchString, hideOnline, hideOffline);
if (circleLayout != nullptr) if (circleLayout != nullptr)
{ {
for (int i = 0; i != circleLayout->getLayout()->count(); ++i) for (int i = 0; i != circleLayout->getLayout()->count(); ++i)
@ -381,6 +392,15 @@ void FriendListWidget::searchChatrooms(const QString &searchString, bool hideOnl
circleWidget->search(searchString, true, hideOnline, hideOffline); circleWidget->search(searchString, true, hideOnline, hideOffline);
} }
} }
else if (activityLayout != nullptr)
{
for (int i = 0; i != activityLayout->count(); ++i)
{
CategoryWidget* categoryWidget = static_cast<CategoryWidget*>(activityLayout->itemAt(i)->widget());
categoryWidget->search(searchString, true, hideOnline, hideOffline);
categoryWidget->setVisible(categoryWidget->hasChatrooms());
}
}
} }
void FriendListWidget::renameGroupWidget(GroupWidget* groupWidget, const QString &newName) void FriendListWidget::renameGroupWidget(GroupWidget* groupWidget, const QString &newName)
@ -427,7 +447,7 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
if (friendWidget == nullptr) if (friendWidget == nullptr)
return; return;
QDate activityDate = Settings::getInstance().getFriendActivity(FriendList::findFriend(friendWidget->friendId)->getToxId()); QDate activityDate = getDateFriend(FriendList::findFriend(friendWidget->friendId));
index = getTime(activityDate); index = getTime(activityDate);
CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(index)->widget()); CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(index)->widget());
@ -615,7 +635,7 @@ void FriendListWidget::moveWidget(FriendWidget* w, Status s, bool add)
else else
{ {
Friend* contact = FriendList::findFriend(w->friendId); Friend* contact = FriendList::findFriend(w->friendId);
QDate activityDate = Settings::getInstance().getFriendActivity(contact->getToxId()); QDate activityDate = getDateFriend(contact);
Time time = getTime(activityDate); Time time = getTime(activityDate);
CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(time)->widget()); CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(time)->widget());
categoryWidget->addFriendWidget(contact->getFriendWidget(), contact->getStatus()); categoryWidget->addFriendWidget(contact->getFriendWidget(), contact->getStatus());
@ -642,6 +662,8 @@ CircleWidget* FriendListWidget::createCircleWidget(int id)
if (mode == Activity) if (mode == Activity)
return nullptr; return nullptr;
assert(circleLayout != nullptr);
CircleWidget* circleWidget = new CircleWidget(this, id); CircleWidget* circleWidget = new CircleWidget(this, id);
circleLayout->addSortedWidget(circleWidget); circleLayout->addSortedWidget(circleWidget);
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged); connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);

View File

@ -656,6 +656,8 @@ void Widget::addFriend(int friendId, const QString &userId)
connect(core, &Core::friendAvatarRemoved, newfriend->getChatForm(), &ChatForm::onAvatarRemoved); connect(core, &Core::friendAvatarRemoved, newfriend->getChatForm(), &ChatForm::onAvatarRemoved);
connect(core, &Core::friendAvatarRemoved, newfriend->getFriendWidget(), &FriendWidget::onAvatarRemoved); connect(core, &Core::friendAvatarRemoved, newfriend->getFriendWidget(), &FriendWidget::onAvatarRemoved);
qDebug() << HistoryKeeper::getInstance()->getLatestDate(newfriend->getToxId().publicKey);
// Try to get the avatar from the cache // Try to get the avatar from the cache
QPixmap avatar = Settings::getInstance().getSavedAvatar(userId); QPixmap avatar = Settings::getInstance().getSavedAvatar(userId);
if (!avatar.isNull()) if (!avatar.isNull())
@ -1130,7 +1132,11 @@ Group *Widget::createGroup(int groupId)
void Widget::onEmptyGroupCreated(int groupId) void Widget::onEmptyGroupCreated(int groupId)
{ {
createGroup(groupId); Group* group = createGroup(groupId);
// Only rename group if groups are visible.
if (Widget::getInstance()->groupsVisible())
group->getGroupWidget()->editName();
} }
bool Widget::isFriendWidgetCurActiveWidget(const Friend* f) const bool Widget::isFriendWidgetCurActiveWidget(const Friend* f) const
@ -1499,6 +1505,7 @@ void Widget::changeDisplayMode()
contactListWidget->setMode(FriendListWidget::Name); contactListWidget->setMode(FriendListWidget::Name);
updateFilterText(); updateFilterText();
searchContacts();
} }
void Widget::updateFilterText() void Widget::updateFilterText()