Commit 65010bd6 authored by Rafał Malinowski's avatar Rafał Malinowski

message: use SortesMessages where possible

Signed-off-by: Rafał Malinowski's avatarRafał Malinowski <rafal.przemyslaw.malinowski@gmail.com>
parent 58e5603f
......@@ -27,6 +27,7 @@
#include "gui/widgets/chat-widget/chat-widget-repository.h"
#include "gui/windows/kadu-window.h"
#include "message/message-manager.h"
#include "message/sorted-messages.h"
#include "message/unread-message-repository.h"
#include "protocols/protocol.h"
#include "services/notification-service.h"
......@@ -140,7 +141,7 @@ void ChatWidgetMessageHandler::appendAllUnreadMessages(ChatWidget *chatWidget)
}
}
QVector<Message> ChatWidgetMessageHandler::loadAllUnreadMessages(const Chat &chat) const
SortedMessages ChatWidgetMessageHandler::loadAllUnreadMessages(const Chat &chat) const
{
// TODO: BuddyChatManager cannot be injected here, because it crashes, find out why
auto buddyChat = BuddyChatManager::instance()->buddyChat(chat);
......@@ -210,7 +211,7 @@ void ChatWidgetMessageHandler::handleUnreadMessageChange(const Message &message)
auto chat = message.messageChat();
auto chatWidget = m_chatWidgetRepository.data()->widgetForChat(chat);
if (chatWidget)
chatWidget->setUnreadMessagesCount(m_unreadMessageRepository.data()->unreadMessagesForChat(chat).count());
chatWidget->setUnreadMessagesCount(m_unreadMessageRepository.data()->unreadMessagesForChat(chat).size());
}
#include "moc_chat-widget-message-handler.cpp"
......@@ -32,6 +32,7 @@ class ChatWidgetRepository;
class Message;
class MessageManager;
class NotificationService;
class SortedMessages;
class UnreadMessageRepository;
/**
......@@ -80,7 +81,7 @@ private:
ChatWidgetMessageHandlerConfiguration m_configuration;
void appendAllUnreadMessages(ChatWidget *chatWidget);
QVector<Message> loadAllUnreadMessages(const Chat &chat) const;
SortedMessages loadAllUnreadMessages(const Chat &chat) const;
bool shouldOpenChatWidget(const Chat &chat) const;
private slots:
......
......@@ -81,6 +81,7 @@
#include "icons/icons-manager.h"
#include "icons/kadu-icon.h"
#include "message/message-manager.h"
#include "message/sorted-messages.h"
#include "misc/misc.h"
#include "model/model-chain.h"
#include "parser/parser.h"
......@@ -474,12 +475,12 @@ QIcon ChatWidget::icon()
return KaduIcon("internet-group-chat").icon();
}
void ChatWidget::appendMessages(const QVector<Message> &messages)
void ChatWidget::appendMessages(const SortedMessages &messages)
{
if (messages.isEmpty())
if (messages.empty())
return;
auto unread = std::any_of(std::begin(messages), std::end(messages), [](const Message &message){
auto unread = std::any_of(begin(messages), end(messages), [](const Message &message){
return message.type() == MessageTypeReceived || message.type() == MessageTypeSystem;
});
......
......@@ -49,6 +49,7 @@ class CustomInput;
class FilteredTreeView;
class FormattedStringFactory;
class Protocol;
class SortedMessages;
class TalkableProxyModel;
class KADUAPI ChatWidget : public QWidget, public ConfigurationAwareObject
......@@ -156,7 +157,7 @@ public:
int unreadMessagesCount() const;
public slots:
void appendMessages(const QVector<Message> &messages);
void appendMessages(const SortedMessages &messages);
void appendMessage(const Message &message);
void sendMessage();
......
......@@ -236,11 +236,11 @@ Message WebkitMessagesView::firstNonSystemMessage(const SortedMessages &messages
: Message::null;
}
void WebkitMessagesView::prependMessages(const QVector<Message> &messages)
void WebkitMessagesView::prependMessages(const SortedMessages &messages)
{
if (messages.empty())
return;
/*
auto const &rendererMessages = Renderer->messages();
// case #1: all prepended messages are already rendered
......@@ -253,7 +253,7 @@ void WebkitMessagesView::prependMessages(const QVector<Message> &messages)
// case #2: some prepended messages are already rendered
auto const &firstRenderedMessage = firstNonSystemMessage(rendererMessages);
auto newMessages = QVector<Message>{};
auto newMessages = SortedMessages{};
for (auto const &message : messages)
{
if (sameMessage(firstRenderedMessage, message))
......@@ -265,10 +265,10 @@ void WebkitMessagesView::prependMessages(const QVector<Message> &messages)
// clearMessages will destroy existing ones
for (auto const &message : rendererMessages)
newMessages.append(message);
*/
ScopedUpdatesDisabler updatesDisabler{*this};
Renderer->clearMessages();
Renderer->add(SortedMessages{newMessages.toStdVector()});
Renderer->add(messages);
emit messagesUpdated();
}
......@@ -280,10 +280,10 @@ void WebkitMessagesView::appendMessage(const Message &message)
emit messagesUpdated();
}
void WebkitMessagesView::appendMessages(const QVector<Message> &messages)
void WebkitMessagesView::appendMessages(const SortedMessages &messages)
{
ScopedUpdatesDisabler updatesDisabler{*this};
Renderer->add(SortedMessages{messages.toStdVector()});
Renderer->add(messages);
emit messagesUpdated();
}
......
......@@ -89,10 +89,10 @@ public:
HtmlMessagesRenderer * renderer() { return Renderer.get(); }
void prependMessages(const QVector<Message> &messages);
void prependMessages(const SortedMessages &messages);
void appendMessage(const Message &message);
void appendMessages(const QVector<Message> &messages);
void appendMessages(const SortedMessages &messages);
int countMessages();
......
......@@ -20,8 +20,9 @@
#pragma once
#include "message/message.h"
#include "exports.h"
class SortedMessages
class KADUAPI SortedMessages
{
public:
......@@ -44,5 +45,5 @@ private:
};
std::vector<Message>::const_iterator begin(const SortedMessages &sortedMessages);
std::vector<Message>::const_iterator end(const SortedMessages &sortedMessages);
KADUAPI std::vector<Message>::const_iterator begin(const SortedMessages &sortedMessages);
KADUAPI std::vector<Message>::const_iterator end(const SortedMessages &sortedMessages);
......@@ -23,6 +23,7 @@
#include "chat/chat.h"
#include "chat/chat-details-buddy.h"
#include "message/message.h"
#include "message/sorted-messages.h"
UnreadMessageRepository::UnreadMessageRepository(QObject *parent) :
QObject{parent}
......@@ -127,9 +128,8 @@ const QList<Message> & UnreadMessageRepository::allUnreadMessages() const
return m_unreadMessages;
}
QVector<Message> UnreadMessageRepository::unreadMessagesForChat(const Chat &chat) const
SortedMessages UnreadMessageRepository::unreadMessagesForChat(const Chat &chat) const
{
auto result = QVector<Message>{};
auto chats = QSet<Chat>{};
auto details = chat.details();
......@@ -141,11 +141,12 @@ QVector<Message> UnreadMessageRepository::unreadMessagesForChat(const Chat &chat
else
chats.insert(chat);
for (const auto &message : m_unreadMessages)
if (chats.contains(message.messageChat()))
result.append(message);
auto messages = std::vector<Message>{};
std::copy_if(std::begin(m_unreadMessages), std::end(m_unreadMessages), std::back_inserter(messages),
[&chats](const Message &message){ return chats.contains(message.messageChat()); }
);
return result;
return SortedMessages{messages};
}
bool UnreadMessageRepository::hasUnreadMessages() const
......@@ -158,7 +159,7 @@ int UnreadMessageRepository::unreadMessagesCount() const
return m_unreadMessages.count();
}
void UnreadMessageRepository::markMessagesAsRead(const QVector<Message> &messages)
void UnreadMessageRepository::markMessagesAsRead(const SortedMessages &messages)
{
for (const auto &message : messages)
if (m_unreadMessages.removeAll(message) > 0)
......
......@@ -29,6 +29,7 @@ class Buddy;
class Chat;
class Contact;
class Message;
class SortedMessages;
/**
* @addtogroup Message
......@@ -72,7 +73,7 @@ public:
*
* Returns list of all unread messages for given chat.
*/
QVector<Message> unreadMessagesForChat(const Chat &chat) const;
SortedMessages unreadMessagesForChat(const Chat &chat) const;
/**
* @short Returns true if there is any unread message in manager.
......@@ -101,7 +102,7 @@ public:
* are updated to MessageStatusRead and its pending statues are set to false.
* Signal unreadMessageRemoved is emited for each changed message.
*/
void markMessagesAsRead(const QVector<Message> &messages);
void markMessagesAsRead(const SortedMessages &messages);
/**
* @short Returns one of unread messages.
......
......@@ -349,7 +349,7 @@ void GaduChatService::removeTimeoutUndeliveredMessages()
else
++it;
foreach (const Message &message, removedMessages)
for (auto const &message : removedMessages)
{
message.setStatus(MessageStatusWontDeliver);
emit sentMessageStatusChanged(message);
......
......@@ -43,6 +43,7 @@
#include "gui/widgets/chat-widget/chat-widget-manager.h"
#include "gui/widgets/tool-tip-class-manager.h"
#include "message/message-manager.h"
#include "message/sorted-messages.h"
#include "message/unread-message-repository.h"
#include "misc/misc.h"
#include "notify/notification-manager.h"
......@@ -329,7 +330,7 @@ void HintManager::processButtonPress(const QString &buttonName, Hint *hint)
if (hint->chat() && config_file.readBoolEntry("Hints", "DeletePendingMsgWhenHintDeleted"))
{
auto unreadMessages = Core::instance()->unreadMessageRepository()->unreadMessagesForChat(hint->chat());
foreach (const Message &message, unreadMessages)
for (auto const &message : unreadMessages)
Core::instance()->unreadMessageRepository()->removeUnreadMessage(message);
}
......
......@@ -29,6 +29,7 @@
#include "gui/widgets/chat-edit-box.h"
#include "gui/widgets/chat-widget/chat-widget.h"
#include "gui/widgets/webkit-messages-view/webkit-messages-view.h"
#include "message/sorted-messages.h"
#include "gui/windows/history-window.h"
#include "history-messages-prepender.h"
......
......@@ -44,6 +44,7 @@
#include "gui/widgets/webkit-messages-view/webkit-messages-view.h"
#include "gui/windows/message-dialog.h"
#include "icons/kadu-icon.h"
#include "message/sorted-messages.h"
#include "model/merged-proxy-model-factory.h"
#include "model/model-chain.h"
#include "talkable/filter/hide-temporary-talkable-filter.h"
......@@ -240,7 +241,7 @@ void HistoryMessagesTab::futureTalkablesCanceled()
TalkablesFutureWatcher = 0;
}
void HistoryMessagesTab::setFutureTalkables(const QFuture<QVector<Talkable> > &futureTalkables)
void HistoryMessagesTab::setFutureTalkables(const QFuture<QVector<Talkable>> &futureTalkables)
{
if (TalkablesFutureWatcher)
{
......@@ -268,7 +269,7 @@ void HistoryMessagesTab::currentDateChanged()
if (!Storage || !date.isValid())
{
TimelineView->setMessages(QVector<Message>());
TimelineView->setMessages(SortedMessages());
return;
}
......
......@@ -124,7 +124,7 @@ protected:
* This methods sets list of future talkable items to display in tree view. Whole tab will
* be blocked by WaitOverlay until talkables are available.
*/
void setFutureTalkables(const QFuture<QVector<Talkable> > &futureTalkables);
void setFutureTalkables(const QFuture<QVector<Talkable>> &futureTalkables);
/**
* @author Rafał 'Vogel' Malinowski
......
......@@ -68,7 +68,7 @@ void HistoryTalkableComboBox::setTalkables(const QVector<Talkable> &talkables)
BuddiesModel->setBuddyList(chatsBuddies.buddies().toList());
}
void HistoryTalkableComboBox::setFutureTalkables(const QFuture<QVector<Talkable> > &talkables)
void HistoryTalkableComboBox::setFutureTalkables(const QFuture<QVector<Talkable>> &talkables)
{
if (TalkablesFutureWatcher)
delete TalkablesFutureWatcher;
......
......@@ -94,7 +94,7 @@ public:
* Widget will be populated when future value will become available. Thenhis list will be split
* into chats and buddies before displaying. Buddies will be extracted from single-buddy chats.
*/
void setFutureTalkables(const QFuture<QVector<Talkable> > &talkables);
void setFutureTalkables(const QFuture<QVector<Talkable>> &talkables);
};
......
......@@ -36,6 +36,7 @@
#include "gui/widgets/search-bar.h"
#include "gui/widgets/webkit-messages-view/webkit-messages-view.h"
#include "icons/kadu-icon.h"
#include "message/sorted-messages.h"
#include "misc/misc.h"
#include "model/roles.h"
#include "activate.h"
......@@ -315,7 +316,7 @@ void SearchTab::currentDateChanged()
TimelineView->setFutureMessages((*SearchedStorage)->messages(query));
}
else
TimelineView->setMessages(QVector<Message>());
TimelineView->setMessages(SortedMessages());
}
void SearchTab::messagesDisplayed()
......
......@@ -31,6 +31,7 @@
#include "gui/widgets/webkit-messages-view/webkit-messages-view.h"
#include "gui/widgets/search-bar.h"
#include "gui/widgets/wait-overlay.h"
#include "message/sorted-messages.h"
#include "model/roles.h"
#include "model/history-query-results-model.h"
......@@ -154,7 +155,7 @@ void TimelineChatMessagesView::futureResultsCanceled()
ResultsFutureWatcher = 0;
}
void TimelineChatMessagesView::setFutureResults(const QFuture<QVector<HistoryQueryResult> > &futureResults)
void TimelineChatMessagesView::setFutureResults(const QFuture<QVector<HistoryQueryResult>> &futureResults)
{
if (ResultsFutureWatcher)
{
......@@ -171,7 +172,7 @@ void TimelineChatMessagesView::setFutureResults(const QFuture<QVector<HistoryQue
showTimelineWaitOverlay();
}
void TimelineChatMessagesView::setMessages(const QVector<Message> &messages)
void TimelineChatMessagesView::setMessages(const SortedMessages &messages)
{
ScopedUpdatesDisabler updatesDisabler{*MessagesView};
......@@ -208,7 +209,7 @@ void TimelineChatMessagesView::futureMessagesCanceled()
MessagesFutureWatcher = 0;
}
void TimelineChatMessagesView::setFutureMessages(const QFuture<QVector<Message> > &futureMessages)
void TimelineChatMessagesView::setFutureMessages(const QFuture<SortedMessages> &futureMessages)
{
if (MessagesFutureWatcher)
{
......@@ -216,7 +217,7 @@ void TimelineChatMessagesView::setFutureMessages(const QFuture<QVector<Message>
MessagesFutureWatcher->deleteLater();
}
MessagesFutureWatcher = new QFutureWatcher<QVector<Message> >(this);
MessagesFutureWatcher = new QFutureWatcher<SortedMessages>(this);
connect(MessagesFutureWatcher, SIGNAL(finished()), this, SLOT(futureMessagesAvailable()));
connect(MessagesFutureWatcher, SIGNAL(canceled()), this, SLOT(futureMessagesCanceled()));
......
......@@ -37,6 +37,7 @@ class HistoryQueryResultsModel;
class HistoryQueryResultsProxyModel;
class Message;
class SearchBar;
class SortedMessages;
class WaitOverlay;
class WebViewHighlighter;
......@@ -69,7 +70,7 @@ class TimelineChatMessagesView : public QWidget
SearchBar *MessagesSearchBar;
QFutureWatcher<QVector<HistoryQueryResult> > *ResultsFutureWatcher;
QFutureWatcher<QVector<Message> > *MessagesFutureWatcher;
QFutureWatcher<SortedMessages> *MessagesFutureWatcher;
void createGui();
......@@ -151,7 +152,7 @@ public:
* If received list will be empty, displayForDate() will be called with invalid date to ensure
* that view is cleared.
*/
void setFutureResults(const QFuture<QVector<HistoryQueryResult> > &futureResults);
void setFutureResults(const QFuture<QVector<HistoryQueryResult>> &futureResults);
/**
* @author Rafał 'Vogel' Malinowski
......@@ -160,7 +161,7 @@ public:
*
* This methods sets list of messages to display in message view widget.
*/
void setMessages(const QVector<Message> &messages);
void setMessages(const SortedMessages &messages);
/**
* @author Rafał 'Vogel' Malinowski
......@@ -170,7 +171,7 @@ public:
* This methods sets list of future messages to display in message view widget. This widget will
* be blocked by WaitOverlay until messages are available.
*/
void setFutureMessages(const QFuture<QVector<Message> > &futureMessages);
void setFutureMessages(const QFuture<SortedMessages> &futureMessages);
/**
* @author Rafał 'Vogel' Malinowski
......
......@@ -21,10 +21,11 @@
#include "history-messages-prepender.h"
#include "gui/widgets/webkit-messages-view/webkit-messages-view.h"
#include "message/sorted-messages.h"
#include <QtCore/QFutureWatcher>
HistoryMessagesPrepender::HistoryMessagesPrepender(QFuture<QVector<Message> > messages, WebkitMessagesView *chatMessagesView, QObject *parent) :
HistoryMessagesPrepender::HistoryMessagesPrepender(QFuture<SortedMessages> messages, WebkitMessagesView *chatMessagesView, QObject *parent) :
QObject{parent},
m_messages{std::move(messages)},
m_messagesView(chatMessagesView)
......@@ -33,7 +34,7 @@ HistoryMessagesPrepender::HistoryMessagesPrepender(QFuture<QVector<Message> > me
connect(m_messagesView, SIGNAL(destroyed()), this, SLOT(deleteLater()));
auto futureWatcher = new QFutureWatcher<QVector<Message>>(this);
auto futureWatcher = new QFutureWatcher<SortedMessages>(this);
connect(futureWatcher, SIGNAL(finished()), this, SLOT(messagesAvailable()));
futureWatcher->setFuture(m_messages);
......
......@@ -26,6 +26,7 @@
#include "message/message.h"
class SortedMessages;
class WebkitMessagesView;
/**
......@@ -56,11 +57,11 @@ public:
* messages from QFuture are available. If chatMessagesView is destroyed before that, nothing will happen.
* After this class finishes its work (successfully or not) it deletes itself.
*/
HistoryMessagesPrepender(QFuture<QVector<Message>> messages, WebkitMessagesView *chatMessagesView, QObject *parent = nullptr);
HistoryMessagesPrepender(QFuture<SortedMessages> messages, WebkitMessagesView *chatMessagesView, QObject *parent = nullptr);
virtual ~HistoryMessagesPrepender();
private:
QFuture<QVector<Message>> m_messages;
QFuture<SortedMessages> m_messages;
QPointer<WebkitMessagesView> m_messagesView;
private slots:
......
......@@ -61,6 +61,7 @@
#include "gui/windows/message-dialog.h"
#include "message/message-manager.h"
#include "message/message.h"
#include "message/sorted-messages.h"
#include "protocols/services/chat-service.h"
#include "debug.h"
......
......@@ -32,6 +32,7 @@
#include "../history_exports.h"
class HistoryQuery;
class SortedMessages;
/**
* @addtogroup History
......@@ -74,7 +75,7 @@ public:
* This methods returns list of available talkables in asynchronous way. Refer to QFuture
* documentation for more information.
*/
virtual QFuture<QVector<Talkable> > talkables() = 0;
virtual QFuture<QVector<Talkable>> talkables() = 0;
/**
* @author Rafał 'Vogel' Malinowski
......@@ -85,7 +86,7 @@ public:
* This methods returns list of available dates for given talkabel in asynchronous way. Refer to QFuture
* documentation for more information. Limit query parametr is ignored for this method.
*/
virtual QFuture<QVector<HistoryQueryResult> > dates(const HistoryQuery &historyQuery) = 0;
virtual QFuture<QVector<HistoryQueryResult>> dates(const HistoryQuery &historyQuery) = 0;
/**
* @author Rafał 'Vogel' Malinowski
......@@ -99,7 +100,7 @@ public:
* Query string parameter is ignored for this method. Limit query parameter can be ignored in
* implementations of this method.
*/
virtual QFuture<QVector<Message> > messages(const HistoryQuery &historyQuery) = 0;
virtual QFuture<SortedMessages> messages(const HistoryQuery &historyQuery) = 0;
/**
* @author Rafał 'Vogel' Malinowski
......
......@@ -38,6 +38,7 @@ class HistoryQuery;
class HistoryQueryResult;
class HistoryMessagesStorage;
class Message;
class SortedMessages;
class Status;
class Talkable;
class TimedStatus;
......@@ -54,17 +55,17 @@ public:
explicit HistoryStorage(QObject *parent) : QObject(parent) {}
virtual ~HistoryStorage() {}
virtual QFuture<QVector<Talkable> > chats() = 0;
virtual QFuture<QVector<Talkable> > statusBuddies() = 0;
virtual QFuture<QVector<Talkable> > smsRecipients() = 0;
virtual QFuture<QVector<Talkable>> chats() = 0;
virtual QFuture<QVector<Talkable>> statusBuddies() = 0;
virtual QFuture<QVector<Talkable>> smsRecipients() = 0;
virtual QFuture<QVector<HistoryQueryResult> > chatDates(const HistoryQuery &historyQuery) = 0;
virtual QFuture<QVector<HistoryQueryResult> > statusDates(const HistoryQuery &historyQuery) = 0;
virtual QFuture<QVector<HistoryQueryResult> > smsRecipientDates(const HistoryQuery &historyQuery) = 0;
virtual QFuture<QVector<HistoryQueryResult>> chatDates(const HistoryQuery &historyQuery) = 0;
virtual QFuture<QVector<HistoryQueryResult>> statusDates(const HistoryQuery &historyQuery) = 0;
virtual QFuture<QVector<HistoryQueryResult>> smsRecipientDates(const HistoryQuery &historyQuery) = 0;
virtual QFuture<QVector<Message> > messages(const HistoryQuery &historyQuery) = 0;
virtual QFuture<QVector<Message> > statuses(const HistoryQuery &historyQuery) = 0;
virtual QFuture<QVector<Message> > smses(const HistoryQuery &historyQuery) = 0;
virtual QFuture<SortedMessages> messages(const HistoryQuery &historyQuery) = 0;
virtual QFuture<SortedMessages> statuses(const HistoryQuery &historyQuery) = 0;
virtual QFuture<SortedMessages> smses(const HistoryQuery &historyQuery) = 0;
virtual void appendMessage(const Message &message) = 0;
virtual void appendStatus(const Contact &contact, const Status &status, const QDateTime &time = QDateTime::currentDateTime()) = 0;
......
......@@ -50,6 +50,7 @@
#include "gui/windows/message-dialog.h"
#include "gui/windows/progress-window.h"
#include "message/message.h"
#include "message/sorted-messages.h"
#include "misc/misc.h"
#include "status/status-type-data.h"
#include "status/status-type-manager.h"
......@@ -501,7 +502,7 @@ QVector<Talkable> HistorySqlStorage::syncChats()
return talkables;
}
QFuture<QVector<Talkable> > HistorySqlStorage::chats()
QFuture<QVector<Talkable>> HistorySqlStorage::chats()
{
return QtConcurrent::run(this, &HistorySqlStorage::syncChats);
}
......@@ -534,7 +535,7 @@ QVector<Talkable> HistorySqlStorage::syncStatusBuddies()
return result;
}
QFuture<QVector<Talkable> > HistorySqlStorage::statusBuddies()
QFuture<QVector<Talkable>> HistorySqlStorage::statusBuddies()
{
return QtConcurrent::run(this, &HistorySqlStorage::syncStatusBuddies);
}
......@@ -562,7 +563,7 @@ QVector<Talkable> HistorySqlStorage::syncSmsRecipients()
return result;
}
QFuture<QVector<Talkable> > HistorySqlStorage::smsRecipients()
QFuture<QVector<Talkable>> HistorySqlStorage::smsRecipients()
{
return QtConcurrent::run(this, &HistorySqlStorage::syncSmsRecipients);
}
......@@ -760,7 +761,7 @@ QVector<HistoryQueryResult> HistorySqlStorage::syncStatusDates(const HistoryQuer
return dates;
}
QFuture<QVector<HistoryQueryResult> > HistorySqlStorage::statusDates(const HistoryQuery &historyQuery)
QFuture<QVector<HistoryQueryResult>> HistorySqlStorage::statusDates(const HistoryQuery &historyQuery)
{
return QtConcurrent::run(this, &HistorySqlStorage::syncStatusDates, historyQuery);
}
......@@ -830,15 +831,15 @@ QVector<HistoryQueryResult> HistorySqlStorage::syncSmsRecipientDates(const Histo
return dates;
}
QFuture<QVector<HistoryQueryResult> > HistorySqlStorage::smsRecipientDates(const HistoryQuery &historyQuery)
QFuture<QVector<HistoryQueryResult>> HistorySqlStorage::smsRecipientDates(const HistoryQuery &historyQuery)
{
return QtConcurrent::run(this, &HistorySqlStorage::syncSmsRecipientDates, historyQuery);
}
QVector<Message> HistorySqlStorage::syncMessages(const HistoryQuery &historyQuery)
SortedMessages HistorySqlStorage::syncMessages(const HistoryQuery &historyQuery)
{
if (!waitForDatabase())
return QVector<Message>();
return SortedMessages();
QMutexLocker locker(&DatabaseMutex);
......@@ -884,36 +885,23 @@ QVector<Message> HistorySqlStorage::syncMessages(const HistoryQuery &historyQuer
if (historyQuery.limit() > 0)
query.bindValue(":limit", historyQuery.limit());
QVector<Message> messages;
SortedMessages messages;
executeQuery(query);
messages = messagesFromQuery(query);
if (historyQuery.limit() > 0)
{
// see comment above
QVector<Message> inverted;
inverted.reserve(messages.size());
for (int i = messages.size() - 1; i >= 0; --i)
inverted.append(messages.at(i));
return inverted;
}
return messages;
return messagesFromQuery(query);
}
QFuture<QVector<Message> > HistorySqlStorage::messages(const HistoryQuery &historyQuery)
QFuture<SortedMessages> HistorySqlStorage::messages(const HistoryQuery &historyQuery)
{
return QtConcurrent::run(this, &HistorySqlStorage::syncMessages, historyQuery);
}
QVector<Message> HistorySqlStorage::syncStatuses(const HistoryQuery &historyQuery)
SortedMessages HistorySqlStorage::syncStatuses(const HistoryQuery &historyQuery)
{
const Talkable &talkable = historyQuery.talkable();
if (!waitForDatabase())
return QVector<Message>();
return SortedMessages();
QMutexLocker locker(&DatabaseMutex);
......@@ -927,7 +915,7 @@ QVector<Message> HistorySqlStorage::syncStatuses(const HistoryQuery &historyQuer
queryString += " ORDER BY set_time ASC";
QVector<Message> statuses;
SortedMessages statuses;
query.prepare(queryString);
if (historyQuery.fromDate().isValid())
......@@ -941,17 +929,17 @@ QVector<Message> HistorySqlStorage::syncStatuses(const HistoryQuery &historyQuer
return statuses;
}
QFuture<QVector<Message> > HistorySqlStorage::statuses(const HistoryQuery &historyQuery)
QFuture<SortedMessages> HistorySqlStorage::statuses(const HistoryQuery &historyQuery)
{
return QtConcurrent::run(this, &HistorySqlStorage::syncStatuses, historyQuery);
}
QVector<Message> HistorySqlStorage::syncSmses(const HistoryQuery &historyQuery)
SortedMessages HistorySqlStorage::syncSmses(const HistoryQuery &historyQuery)
{
const Talkable &talkable = historyQuery.talkable();
if (!waitForDatabase())
return QVector<Message>();
return SortedMessages();
QMutexLocker locker(&DatabaseMutex);
......@@ -979,12 +967,12 @@ QVector<Message> HistorySqlStorage::syncSmses(const HistoryQuery &historyQuery)
executeQuery(query);
QVector<Message> result = smsFromQuery(query);
SortedMessages result = smsFromQuery(query);
return result;
}
QFuture<QVector<Message> > HistorySqlStorage::smses(const HistoryQuery &historyQuery)
QFuture<SortedMessages> HistorySqlStorage::smses(const HistoryQuery &historyQuery)
{
return QtConcurrent::run(this, &HistorySqlStorage::syncSmses, historyQuery);
}
......@@ -1024,12 +1012,12 @@ QString HistorySqlStorage::stripAllScriptTags(const QString &string)
return afterReplace;