Changeset View
Changeset View
Standalone View
Standalone View
plugins/sms/conversationsdbusinterface.cpp
- This file was moved from plugins/telephony/conversationsdbusinterface.cpp.
Show All 21 Lines | |||||
22 | #include "interfaces/dbusinterfaces.h" | 22 | #include "interfaces/dbusinterfaces.h" | ||
23 | #include "interfaces/conversationmessage.h" | 23 | #include "interfaces/conversationmessage.h" | ||
24 | 24 | | |||
25 | #include <QDBusConnection> | 25 | #include <QDBusConnection> | ||
26 | 26 | | |||
27 | #include <core/device.h> | 27 | #include <core/device.h> | ||
28 | #include <core/kdeconnectplugin.h> | 28 | #include <core/kdeconnectplugin.h> | ||
29 | 29 | | |||
30 | #include "telephonyplugin.h" | 30 | Q_LOGGING_CATEGORY(KDECONNECT_CONVERSATIONS, "kdeconnect.conversations") | ||
31 | 31 | | |||
32 | ConversationsDbusInterface::ConversationsDbusInterface(KdeConnectPlugin* plugin) | 32 | ConversationsDbusInterface::ConversationsDbusInterface(KdeConnectPlugin* plugin) | ||
33 | : QDBusAbstractAdaptor(const_cast<Device*>(plugin->device())) | 33 | : QDBusAbstractAdaptor(const_cast<Device*>(plugin->device())) | ||
34 | , m_device(plugin->device()) | 34 | , m_device(plugin->device()) | ||
35 | , m_plugin(plugin) | 35 | , m_plugin(plugin) | ||
36 | , m_lastId(0) | 36 | , m_lastId(0) | ||
37 | , m_telephonyInterface(m_device->id()) | 37 | , m_smsInterface(m_device->id()) | ||
38 | { | 38 | { | ||
39 | ConversationMessage::registerDbusType(); | 39 | ConversationMessage::registerDbusType(); | ||
40 | } | 40 | } | ||
41 | 41 | | |||
42 | ConversationsDbusInterface::~ConversationsDbusInterface() | 42 | ConversationsDbusInterface::~ConversationsDbusInterface() | ||
43 | { | 43 | { | ||
44 | } | 44 | } | ||
45 | 45 | | |||
46 | QStringList ConversationsDbusInterface::activeConversations() | 46 | QStringList ConversationsDbusInterface::activeConversations() | ||
47 | { | 47 | { | ||
48 | return m_conversations.keys(); | 48 | return m_conversations.keys(); | ||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | void ConversationsDbusInterface::requestConversation(const QString& conversationID, int start, int end) | 51 | void ConversationsDbusInterface::requestConversation(const QString& conversationID, int start, int end) | ||
52 | { | 52 | { | ||
53 | const auto messagesList = m_conversations[conversationID].values(); | 53 | const auto messagesList = m_conversations[conversationID].values(); | ||
54 | 54 | | |||
55 | if (messagesList.isEmpty()) | 55 | if (messagesList.isEmpty()) | ||
56 | { | 56 | { | ||
57 | // Since there are no messages in the conversation, it's likely that it is a junk ID, but go ahead anyway | 57 | // Since there are no messages in the conversation, it's likely that it is a junk ID, but go ahead anyway | ||
58 | qCWarning(KDECONNECT_PLUGIN_TELEPHONY) << "Got a conversationID for a conversation with no messages!" << conversationID; | 58 | qCWarning(KDECONNECT_CONVERSATIONS) << "Got a conversationID for a conversation with no messages!" << conversationID; | ||
59 | } | 59 | } | ||
60 | 60 | | |||
61 | m_telephonyInterface.requestConversation(conversationID); | 61 | m_smsInterface.requestConversation(conversationID); | ||
62 | 62 | | |||
63 | // Messages are sorted in ascending order of keys, meaning the front of the list has the oldest | 63 | // Messages are sorted in ascending order of keys, meaning the front of the list has the oldest | ||
64 | // messages (smallest timestamp number) | 64 | // messages (smallest timestamp number) | ||
65 | // Therefore, return the end of the list first (most recent messages) | 65 | // Therefore, return the end of the list first (most recent messages) | ||
66 | int i = start; | 66 | int i = start; | ||
67 | for(auto it = messagesList.crbegin(); it != messagesList.crend(); ++it) | 67 | for(auto it = messagesList.crbegin(); it != messagesList.crend(); ++it) | ||
68 | { | 68 | { | ||
69 | Q_EMIT conversationMessageReceived(it->toVariant(), i); | 69 | Q_EMIT conversationMessageReceived(it->toVariant(), i); | ||
Show All 36 Lines | |||||
106 | } | 106 | } | ||
107 | 107 | | |||
108 | void ConversationsDbusInterface::replyToConversation(const QString& conversationID, const QString& message) | 108 | void ConversationsDbusInterface::replyToConversation(const QString& conversationID, const QString& message) | ||
109 | { | 109 | { | ||
110 | const auto messagesList = m_conversations[conversationID]; | 110 | const auto messagesList = m_conversations[conversationID]; | ||
111 | if (messagesList.isEmpty()) | 111 | if (messagesList.isEmpty()) | ||
112 | { | 112 | { | ||
113 | // Since there are no messages in the conversation, we can't do anything sensible | 113 | // Since there are no messages in the conversation, we can't do anything sensible | ||
114 | qCWarning(KDECONNECT_PLUGIN_TELEPHONY) << "Got a conversationID for a conversation with no messages!"; | 114 | qCWarning(KDECONNECT_CONVERSATIONS) << "Got a conversationID for a conversation with no messages!"; | ||
115 | return; | 115 | return; | ||
116 | } | 116 | } | ||
117 | // Caution: | 117 | // Caution: | ||
118 | // This method assumes that the address of any message (in this case, whichever one pops out | 118 | // This method assumes that the address of any message (in this case, whichever one pops out | ||
119 | // with .first()) will be the same. This works fine for single-target SMS but might break down | 119 | // with .first()) will be the same. This works fine for single-target SMS but might break down | ||
120 | // for group MMS, etc. | 120 | // for group MMS, etc. | ||
121 | const QString& address = messagesList.first().address(); | 121 | const QString& address = messagesList.first().address(); | ||
122 | m_telephonyInterface.sendSms(address, message); | 122 | m_smsInterface.sendSms(address, message); | ||
123 | } | 123 | } | ||
124 | 124 | | |||
125 | void ConversationsDbusInterface::requestAllConversationThreads() | 125 | void ConversationsDbusInterface::requestAllConversationThreads() | ||
126 | { | 126 | { | ||
127 | // Prepare the list of conversations by requesting the first in every thread | 127 | // Prepare the list of conversations by requesting the first in every thread | ||
128 | m_telephonyInterface.requestAllConversations(); | 128 | m_smsInterface.requestAllConversations(); | ||
129 | } | 129 | } | ||
130 | 130 | | |||
131 | QString ConversationsDbusInterface::newId() | 131 | QString ConversationsDbusInterface::newId() | ||
132 | { | 132 | { | ||
133 | return QString::number(++m_lastId); | 133 | return QString::number(++m_lastId); | ||
134 | } | 134 | } |