Changeset View
Changeset View
Standalone View
Standalone View
plugins/sms/conversationsdbusinterface.h
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
44 | { | 44 | { | ||
45 | Q_OBJECT | 45 | Q_OBJECT | ||
46 | Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.conversations") | 46 | Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.conversations") | ||
47 | 47 | | |||
48 | public: | 48 | public: | ||
49 | explicit ConversationsDbusInterface(KdeConnectPlugin* plugin); | 49 | explicit ConversationsDbusInterface(KdeConnectPlugin* plugin); | ||
50 | ~ConversationsDbusInterface() override; | 50 | ~ConversationsDbusInterface() override; | ||
51 | 51 | | |||
52 | void addMessage(const ConversationMessage &message); | 52 | void addMessages(const QList<ConversationMessage> &messages); | ||
53 | void removeMessage(const QString& internalId); | 53 | void removeMessage(const QString& internalId); | ||
54 | 54 | | |||
55 | /** | ||||
56 | * Return a shallow copy of the requested conversation | ||||
57 | */ | ||||
58 | QList<ConversationMessage> getConversation(const qint32& conversationID) const; | ||||
59 | | ||||
60 | /** | ||||
61 | * Get all of the messages in the requested conversation from the remote device | ||||
62 | * TODO: Make interface capable of requesting smaller window of messages | ||||
63 | */ | ||||
64 | void updateConversation(const qint32& conversationID); | ||||
65 | | ||||
55 | public Q_SLOTS: | 66 | public Q_SLOTS: | ||
56 | /** | 67 | /** | ||
57 | * Return a list of the first message in every conversation | 68 | * Return a list of the first message in every conversation | ||
58 | * | 69 | * | ||
59 | * Note that the return value is a list of QVariants, which in turn have a value of | 70 | * Note that the return value is a list of QVariants, which in turn have a value of | ||
60 | * QVariantMap created from each message | 71 | * QVariantMap created from each message | ||
61 | */ | 72 | */ | ||
62 | QVariantList activeConversations(); | 73 | QVariantList activeConversations(); | ||
63 | 74 | | |||
64 | void requestConversation(const QString &conversationID, int start, int end); | 75 | /** | ||
76 | * Request the specified range of the specified conversation | ||||
77 | * | ||||
78 | * Emits conversationUpdated for every message in the requested range | ||||
79 | * | ||||
80 | * If the conversation does not have enough messages to fill the request, | ||||
81 | * this method may return fewer messages | ||||
82 | */ | ||||
83 | void requestConversation(const qint32 &conversationID, int start, int end); | ||||
65 | 84 | | |||
66 | /** | 85 | /** | ||
67 | * Send a new message to this conversation | 86 | * Send a new message to this conversation | ||
68 | */ | 87 | */ | ||
69 | void replyToConversation(const QString& conversationID, const QString& message); | 88 | void replyToConversation(const qint32& conversationID, const QString& message); | ||
70 | 89 | | |||
71 | /** | 90 | /** | ||
72 | * Send the request to the Telephony plugin to update the list of conversation threads | 91 | * Send the request to the Telephony plugin to update the list of conversation threads | ||
73 | */ | 92 | */ | ||
74 | void requestAllConversationThreads(); | 93 | void requestAllConversationThreads(); | ||
75 | 94 | | |||
76 | Q_SIGNALS: | 95 | Q_SIGNALS: | ||
96 | /** | ||||
97 | * Emitted whenever a conversation with no cached messages is added, either because the cache | ||||
98 | * is being populated or because a new conversation has been created | ||||
99 | */ | ||||
77 | Q_SCRIPTABLE void conversationCreated(const QVariantMap& msg); | 100 | Q_SCRIPTABLE void conversationCreated(const QVariantMap& msg); | ||
78 | Q_SCRIPTABLE void conversationRemoved(const QString& threadID); | 101 | | ||
102 | /** | ||||
103 | * Emitted whenever a conversation is being deleted | ||||
104 | */ | ||||
105 | Q_SCRIPTABLE void conversationRemoved(const qint32& conversationID); | ||||
106 | | ||||
107 | /** | ||||
108 | * Emitted whenever a message is added to a conversation and it is the newest message in the | ||||
109 | * conversation | ||||
110 | */ | ||||
79 | Q_SCRIPTABLE void conversationUpdated(const QVariantMap& msg); | 111 | Q_SCRIPTABLE void conversationUpdated(const QVariantMap& msg); | ||
80 | Q_SCRIPTABLE void conversationMessageReceived(const QVariantMap& msg, int pos); | | |||
81 | 112 | | |||
82 | private /*methods*/: | 113 | private /*methods*/: | ||
83 | QString newId(); //Generates successive identifiers to use as public ids | 114 | QString newId(); //Generates successive identifitiers to use as public ids | ||
84 | 115 | | |||
85 | private /*attributes*/: | 116 | private /*attributes*/: | ||
86 | const Device* m_device; | 117 | const Device* m_device; | ||
87 | KdeConnectPlugin* m_plugin; | 118 | KdeConnectPlugin* m_plugin; | ||
88 | 119 | | |||
89 | /** | 120 | /** | ||
90 | * Mapping of threadID to the messages which make up that thread | 121 | * Mapping of threadID to the messages which make up that thread | ||
91 | * | 122 | * | ||
92 | * The messages are stored as a QMap of the timestamp to the actual message object so that | 123 | * The messages are stored as a QMap of the timestamp to the actual message object so that | ||
93 | * we can use .values() to get a sorted list of messages from least- to most-recent | 124 | * we can use .values() to get a sorted list of messages from least- to most-recent | ||
94 | */ | 125 | */ | ||
95 | QHash<QString, QMap<qint64, ConversationMessage>> m_conversations; | 126 | QHash<qint32, QMap<qint64, ConversationMessage>> m_conversations; | ||
96 | 127 | | |||
97 | /** | 128 | /** | ||
98 | * Mapping of threadID to the set of uIDs known in the corresponding conversation | 129 | * Mapping of threadID to the set of uIDs known in the corresponding conversation | ||
99 | */ | 130 | */ | ||
100 | QHash<QString, QSet<qint32>> m_known_messages; | 131 | QHash<qint32, QSet<qint32>> m_known_messages; | ||
101 | 132 | | |||
102 | int m_lastId; | 133 | int m_lastId; | ||
103 | 134 | | |||
104 | SmsDbusInterface m_smsInterface; | 135 | SmsDbusInterface m_smsInterface; | ||
136 | | ||||
137 | QSet<qint32> conversationsWaitingForMessages; | ||||
138 | QMutex waitingForMessagesLock; | ||||
139 | QWaitCondition waitingForMessages; | ||||
105 | }; | 140 | }; | ||
106 | 141 | | |||
107 | #endif // CONVERSATIONSDBUSINTERFACE_H | 142 | #endif // CONVERSATIONSDBUSINTERFACE_H |