Changeset View
Changeset View
Standalone View
Standalone View
plugins/sms/conversationsdbusinterface.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
43 | { | 43 | { | ||
44 | } | 44 | } | ||
45 | 45 | | |||
46 | QVariantList ConversationsDbusInterface::activeConversations() | 46 | QVariantList ConversationsDbusInterface::activeConversations() | ||
47 | { | 47 | { | ||
48 | QList<QVariant> toReturn; | 48 | QList<QVariant> toReturn; | ||
49 | toReturn.reserve(m_conversations.size()); | 49 | toReturn.reserve(m_conversations.size()); | ||
50 | 50 | | |||
51 | for (const auto& conversation : m_conversations) | 51 | for (auto it = m_conversations.cbegin(); it != m_conversations.cend(); ++it) { | ||
52 | { | 52 | const auto& conversation = it.value().values(); | ||
53 | const QVariantMap& message = (*conversation.cbegin()).toVariant(); | 53 | if (conversation.isEmpty()) { | ||
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 | toReturn.append(QVariant(message)); | 54 | // This should really never happen because we create a conversation at the same time | ||
55 | // as adding a message, but better safe than sorry | ||||
56 | qCWarning(KDECONNECT_CONVERSATIONS) | ||||
57 | << "Conversation with ID" << it.key() << "is unexpectedly empty"; | ||||
58 | break; | ||||
59 | } | ||||
60 | const QVariantMap& message = (*conversation.crbegin()).toVariant(); | ||||
61 | toReturn.append(message); | ||||
55 | } | 62 | } | ||
56 | 63 | | |||
57 | return toReturn; | 64 | return toReturn; | ||
58 | } | 65 | } | ||
59 | 66 | | |||
60 | void ConversationsDbusInterface::requestConversation(const QString& conversationID, int start, int end) | 67 | void ConversationsDbusInterface::requestConversation(const QString& conversationID, int start, int end) | ||
61 | { | 68 | { | ||
62 | const auto messagesList = m_conversations[conversationID].values(); | 69 | const auto messagesList = m_conversations[conversationID].values(); | ||
63 | 70 | | |||
64 | if (messagesList.isEmpty()) { | 71 | if (messagesList.isEmpty()) { | ||
65 | // Since there are no messages in the conversation, it's likely that it is a junk ID, but go ahead anyway | 72 | // Since there are no messages in the conversation, it's likely that it is a junk ID, but go ahead anyway | ||
66 | qCWarning(KDECONNECT_CONVERSATIONS) << "Got a conversationID for a conversation with no messages!" << conversationID; | 73 | qCWarning(KDECONNECT_CONVERSATIONS) << "Got a conversationID for a conversation with no messages!" << conversationID; | ||
67 | } | 74 | } | ||
68 | 75 | | |||
69 | // TODO: Check local cache before requesting new messages | 76 | // TODO: Check local cache before requesting new messages | ||
70 | // TODO: Make Android interface capable of requesting small window of messages | 77 | // TODO: Make Android interface capable of requesting small window of messages | ||
71 | m_smsInterface.requestConversation(conversationID); | 78 | m_smsInterface.requestConversation(conversationID); | ||
72 | 79 | | |||
73 | // Messages are sorted in ascending order of keys, meaning the front of the list has the oldest | 80 | // Messages are sorted in ascending order of keys, meaning the front of the list has the oldest | ||
74 | // messages (smallest timestamp number) | 81 | // messages (smallest timestamp number) | ||
75 | // Therefore, return the end of the list first (most recent messages) | 82 | // Therefore, return the end of the list first (most recent messages) | ||
76 | int i = start; | 83 | int i = start; | ||
77 | // TODO: BUG: What if the caller asked for start != 0? | 84 | 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… | |||||
78 | for(auto it = messagesList.crbegin(); it != messagesList.crend(); ++it) | | |||
79 | { | | |||
80 | Q_EMIT conversationMessageReceived(it->toVariant(), i); | 85 | Q_EMIT conversationMessageReceived(it->toVariant(), i); | ||
81 | i++; | 86 | i++; | ||
82 | if (i >= end) { | 87 | if (i >= end) { | ||
83 | break; | 88 | break; | ||
84 | } | 89 | } | ||
85 | } | 90 | } | ||
86 | } | 91 | } | ||
87 | 92 | | |||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |
Looks like it's casting twice? How about toReturn += conversation.cbegin()->toVariant()?
Also we probably should make sure it's not empty.