[SMS App] Make requestMoreMessages asynchronous, blocking, and caching
Summary:
The most serious change from this patch is to move the asynchronous replying to a request from the app for more messages to a newly-spawned, self-destructing thread. Within that thread, we block until the remote device replies with the requested messages.
All gotten messages are cached in the ConversationDbusInterface, so all future requests are fast and don't hit the remote device.
Test Plan: After applying this diff, the messaging app should show 10 messages every time it is opened
Reviewers: #kde_connect, nicolasfella, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: albertvaka, apol, nicolasfella, kdeconnect
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D16475
2018-12-13 05:42:45 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2018 Simon Redman <simon@ergotech.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License or (at your option) version 3 or any later version
|
|
|
|
* accepted by the membership of KDE e.V. (or its successor approved
|
|
|
|
* by the membership of KDE e.V.), which shall act as a proxy
|
|
|
|
* defined in Section 14 of version 3 of the license.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef REQUESTCONVERSATIONWORKER_H
|
|
|
|
#define REQUESTCONVERSATIONWORKER_H
|
|
|
|
|
|
|
|
#include "conversationsdbusinterface.h"
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QThread>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In case we need to wait for more messages to be downloaded from Android,
|
|
|
|
* Do the actual work of a requestConversation call in a separate thread
|
|
|
|
*
|
|
|
|
* This class is the worker for that thread
|
|
|
|
*/
|
|
|
|
class RequestConversationWorker : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
RequestConversationWorker(const qint64& conversationID, int start, int end, ConversationsDbusInterface* interface);
|
|
|
|
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
2019-01-23 01:27:10 +00:00
|
|
|
/**
|
|
|
|
* Main body of this worker
|
|
|
|
*
|
|
|
|
* Reply to a request for messages and, if needed, wait for the remote to reply with more
|
|
|
|
*
|
|
|
|
* Emits conversationMessageRead for every message handled
|
|
|
|
*/
|
[SMS App] Make requestMoreMessages asynchronous, blocking, and caching
Summary:
The most serious change from this patch is to move the asynchronous replying to a request from the app for more messages to a newly-spawned, self-destructing thread. Within that thread, we block until the remote device replies with the requested messages.
All gotten messages are cached in the ConversationDbusInterface, so all future requests are fast and don't hit the remote device.
Test Plan: After applying this diff, the messaging app should show 10 messages every time it is opened
Reviewers: #kde_connect, nicolasfella, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: albertvaka, apol, nicolasfella, kdeconnect
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D16475
2018-12-13 05:42:45 +00:00
|
|
|
void handleRequestConversation();
|
|
|
|
void work();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2019-02-28 13:13:35 +00:00
|
|
|
void conversationMessageRead(const QVariantMap& msg);
|
[SMS App] Make requestMoreMessages asynchronous, blocking, and caching
Summary:
The most serious change from this patch is to move the asynchronous replying to a request from the app for more messages to a newly-spawned, self-destructing thread. Within that thread, we block until the remote device replies with the requested messages.
All gotten messages are cached in the ConversationDbusInterface, so all future requests are fast and don't hit the remote device.
Test Plan: After applying this diff, the messaging app should show 10 messages every time it is opened
Reviewers: #kde_connect, nicolasfella, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: albertvaka, apol, nicolasfella, kdeconnect
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D16475
2018-12-13 05:42:45 +00:00
|
|
|
void finished();
|
|
|
|
|
|
|
|
private:
|
|
|
|
qint64 conversationID;
|
2019-01-23 01:27:10 +00:00
|
|
|
int start; // Start of range to request messages
|
|
|
|
size_t howMany; // Number of messages being requested
|
[SMS App] Make requestMoreMessages asynchronous, blocking, and caching
Summary:
The most serious change from this patch is to move the asynchronous replying to a request from the app for more messages to a newly-spawned, self-destructing thread. Within that thread, we block until the remote device replies with the requested messages.
All gotten messages are cached in the ConversationDbusInterface, so all future requests are fast and don't hit the remote device.
Test Plan: After applying this diff, the messaging app should show 10 messages every time it is opened
Reviewers: #kde_connect, nicolasfella, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: albertvaka, apol, nicolasfella, kdeconnect
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D16475
2018-12-13 05:42:45 +00:00
|
|
|
ConversationsDbusInterface* parent;
|
|
|
|
|
|
|
|
QThread* m_thread;
|
2019-01-23 01:27:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reply with all messages we currently have available in the requested range
|
|
|
|
*
|
|
|
|
* If the range specified by start and howMany is not in the range of messages in the conversation,
|
|
|
|
* reply with only as many messages as we have available in that range
|
|
|
|
*
|
|
|
|
* @param conversation Conversation to send messages from
|
|
|
|
* @param start Start of requested range, 0-indexed, inclusive
|
|
|
|
* @param howMany Maximum number of messages to return
|
|
|
|
* $return Number of messages processed
|
|
|
|
*/
|
|
|
|
size_t replyForConversation(const QList<ConversationMessage>& conversation, int start, size_t howMany);
|
[SMS App] Make requestMoreMessages asynchronous, blocking, and caching
Summary:
The most serious change from this patch is to move the asynchronous replying to a request from the app for more messages to a newly-spawned, self-destructing thread. Within that thread, we block until the remote device replies with the requested messages.
All gotten messages are cached in the ConversationDbusInterface, so all future requests are fast and don't hit the remote device.
Test Plan: After applying this diff, the messaging app should show 10 messages every time it is opened
Reviewers: #kde_connect, nicolasfella, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: albertvaka, apol, nicolasfella, kdeconnect
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D16475
2018-12-13 05:42:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // REQUESTCONVERSATIONWORKER_H
|