Changeset View
Changeset View
Standalone View
Standalone View
plugins/sms/conversationsdbusinterface.cpp
Show All 37 Lines | |||||
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 | QVariantList ConversationsDbusInterface::activeConversations() | ||
47 | { | 47 | { | ||
48 | return m_conversations.keys(); | 48 | QList<QVariant> toReturn; | ||
49 | toReturn.reserve(m_conversations.size()); | ||||
50 | | ||||
51 | for (auto it = m_conversations.cbegin(); it != m_conversations.cend(); ++it) | ||||
52 | { | ||||
53 | const auto& conversation = it.value(); | ||||
apol: Looks like it's casting twice? How about `toReturn += conversation.cbegin()->toVariant()`?
Also… | |||||
The double cast was because I was trying to resolve a (different) issue. Good catch on the "null" dereference, thank you! sredman: The double cast was because I was trying to resolve a (different) issue. Good catch on the… | |||||
54 | if (conversation.isEmpty()) | ||||
55 | { | ||||
56 | // This should really never happen because we create a conversation at the same time | ||||
57 | // as adding a message, but better safe than sorry | ||||
58 | qCWarning(KDECONNECT_CONVERSATIONS) | ||||
59 | << "Conversation with ID" << it.key() << "is unexpectedly empty"; | ||||
60 | break; | ||||
61 | } | ||||
62 | const QVariantMap& message = (*conversation.cbegin()).toVariant(); | ||||
63 | toReturn.append(message); | ||||
64 | } | ||||
65 | | ||||
66 | return toReturn; | ||||
49 | } | 67 | } | ||
50 | 68 | | |||
51 | void ConversationsDbusInterface::requestConversation(const QString& conversationID, int start, int end) | 69 | void ConversationsDbusInterface::requestConversation(const QString& conversationID, int start, int end) | ||
52 | { | 70 | { | ||
53 | const auto messagesList = m_conversations[conversationID].values(); | 71 | const auto messagesList = m_conversations[conversationID].values(); | ||
54 | 72 | | |||
55 | if (messagesList.isEmpty()) | 73 | if (messagesList.isEmpty()) | ||
56 | { | 74 | { | ||
57 | // Since there are no messages in the conversation, it's likely that it is a junk ID, but go ahead anyway | 75 | // Since there are no messages in the conversation, it's likely that it is a junk ID, but go ahead anyway | ||
58 | qCWarning(KDECONNECT_CONVERSATIONS) << "Got a conversationID for a conversation with no messages!" << conversationID; | 76 | qCWarning(KDECONNECT_CONVERSATIONS) << "Got a conversationID for a conversation with no messages!" << conversationID; | ||
59 | } | 77 | } | ||
60 | 78 | | |||
79 | // TODO: Check local cache before requesting new messages | ||||
80 | // TODO: Make Android interface capable of requesting small window of messages | ||||
61 | m_smsInterface.requestConversation(conversationID); | 81 | m_smsInterface.requestConversation(conversationID); | ||
62 | 82 | | |||
63 | // Messages are sorted in ascending order of keys, meaning the front of the list has the oldest | 83 | // Messages are sorted in ascending order of keys, meaning the front of the list has the oldest | ||
64 | // messages (smallest timestamp number) | 84 | // messages (smallest timestamp number) | ||
65 | // Therefore, return the end of the list first (most recent messages) | 85 | // Therefore, return the end of the list first (most recent messages) | ||
66 | int i = start; | 86 | int i = start; | ||
67 | for(auto it = messagesList.crbegin(); it != messagesList.crend(); ++it) | 87 | for(auto it = messagesList.crbegin() + start; it != messagesList.crend(); ++it) | ||
apol: Should probably offset it by start? | |||||
I forgot I could use a different dbus viewer to make the call: Now I have been able to test this and it appears to work! sredman: I forgot I could use a different dbus viewer to make the call: Now I have been able to test… | |||||
68 | { | 88 | { | ||
69 | Q_EMIT conversationMessageReceived(it->toVariant(), i); | 89 | Q_EMIT conversationMessageReceived(it->toVariant(), i); | ||
70 | i++; | 90 | i++; | ||
71 | if (i >= end) | 91 | if (i >= end) | ||
72 | { | 92 | { | ||
73 | break; | 93 | break; | ||
74 | } | 94 | } | ||
75 | } | 95 | } | ||
Show All 12 Lines | 99 | { | |||
88 | // Store the Message in the list corresponding to its thread | 108 | // Store the Message in the list corresponding to its thread | ||
89 | bool newConversation = !m_conversations.contains(threadId); | 109 | bool newConversation = !m_conversations.contains(threadId); | ||
90 | m_conversations[threadId].insert(message.date(), message); | 110 | m_conversations[threadId].insert(message.date(), message); | ||
91 | m_known_messages[threadId].insert(message.uID()); | 111 | m_known_messages[threadId].insert(message.uID()); | ||
92 | 112 | | |||
93 | // Tell the world about what just happened | 113 | // Tell the world about what just happened | ||
94 | if (newConversation) | 114 | if (newConversation) | ||
95 | { | 115 | { | ||
96 | Q_EMIT conversationCreated(threadId); | 116 | Q_EMIT conversationCreated(message.toVariant()); | ||
97 | } else | 117 | } else | ||
98 | { | 118 | { | ||
99 | Q_EMIT conversationUpdated(message.toVariant()); | 119 | Q_EMIT conversationUpdated(message.toVariant()); | ||
100 | } | 120 | } | ||
101 | } | 121 | } | ||
102 | 122 | | |||
103 | void ConversationsDbusInterface::removeMessage(const QString& internalId) | 123 | void ConversationsDbusInterface::removeMessage(const QString& internalId) | ||
104 | { | 124 | { | ||
Show All 30 Lines |
Looks like it's casting twice? How about toReturn += conversation.cbegin()->toVariant()?
Also we probably should make sure it's not empty.