File indexing completed on 2024-12-08 04:30:52

0001 /**
0002  * SPDX-FileCopyrightText: 2018 Simon Redman <simon@ergotech.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #pragma once
0008 
0009 #include "conversationsdbusinterface.h"
0010 
0011 #include <QObject>
0012 #include <QThread>
0013 
0014 /**
0015  * In case we need to wait for more messages to be downloaded from Android,
0016  * Do the actual work of a requestConversation call in a separate thread
0017  *
0018  * This class is the worker for that thread
0019  */
0020 class RequestConversationWorker : public QObject
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     RequestConversationWorker(const qint64 &conversationID, int start, int end, ConversationsDbusInterface *interface);
0026 
0027 public Q_SLOTS:
0028     /**
0029      * Main body of this worker
0030      *
0031      * Reply to a request for messages and, if needed, wait for the remote to reply with more
0032      *
0033      * Emits conversationMessageRead for every message handled
0034      */
0035     void handleRequestConversation();
0036     void work();
0037 
0038 Q_SIGNALS:
0039     void conversationMessageRead(const QDBusVariant &msg);
0040     void finished();
0041 
0042 private:
0043     qint64 conversationID;
0044     int start; // Start of range to request messages
0045     size_t howMany; // Number of messages being requested
0046     ConversationsDbusInterface *parent;
0047 
0048     QThread *m_thread;
0049 
0050     /**
0051      * Reply with all messages we currently have available in the requested range
0052      *
0053      * If the range specified by start and howMany is not in the range of messages in the conversation,
0054      * reply with only as many messages as we have available in that range
0055      *
0056      * @param conversation Conversation to send messages from
0057      * @param start Start of requested range, 0-indexed, inclusive
0058      * @param howMany Maximum number of messages to return
0059      * $return Number of messages processed
0060      */
0061     size_t replyForConversation(const QList<ConversationMessage> &conversation, int start, size_t howMany);
0062 };