Changeset View
Changeset View
Standalone View
Standalone View
plugins/sms/conversationsdbusinterface.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 51 | for (auto it = m_conversations.cbegin(); it != m_conversations.cend(); ++it) { | |||
---|---|---|---|---|---|
61 | toReturn.append(message); | 61 | toReturn.append(message); | ||
62 | } | 62 | } | ||
63 | 63 | | |||
64 | return toReturn; | 64 | return toReturn; | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | void ConversationsDbusInterface::requestConversation(const QString& conversationID, int start, int end) | 67 | void ConversationsDbusInterface::requestConversation(const QString& conversationID, int start, int end) | ||
68 | { | 68 | { | ||
69 | const auto messagesList = m_conversations[conversationID].values(); | 69 | auto messagesList = m_conversations[conversationID].values(); | ||
apol: Use `m_conversations.value(conversationID)`. Otherwise, if conversationId doesn't exist, it… | |||||
This is actually fixed in D16475 sredman: This is actually fixed in D16475 | |||||
70 | 70 | | |||
71 | if (messagesList.isEmpty()) { | 71 | if (messagesList.isEmpty()) { | ||
72 | // 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 | ||
73 | 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; | ||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | // TODO: Check local cache before requesting new messages | 76 | if (!(messagesList.length() > end)) { | ||
apol: `messagesList.length() <= end` | |||||
77 | // If we don't have enough messages in cache, go get some more | ||||
77 | // TODO: Make Android interface capable of requesting small window of messages | 78 | // TODO: Make Android interface capable of requesting small window of messages | ||
78 | m_smsInterface.requestConversation(conversationID); | 79 | m_smsInterface.requestConversation(conversationID); | ||
80 | messagesList = m_conversations[conversationID].values(); | ||||
81 | } | ||||
79 | 82 | | |||
80 | // 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 | ||
81 | // messages (smallest timestamp number) | 84 | // messages (smallest timestamp number) | ||
82 | // Therefore, return the end of the list first (most recent messages) | 85 | // Therefore, return the end of the list first (most recent messages) | ||
83 | int i = start; | 86 | int i = start; | ||
84 | for(auto it = messagesList.crbegin() + start; it != messagesList.crend(); ++it) { | 87 | for(auto it = messagesList.crbegin() + start; it != messagesList.crend(); ++it) { | ||
85 | Q_EMIT conversationMessageReceived(it->toVariant(), i); | 88 | Q_EMIT conversationUpdated(it->toVariant()); | ||
86 | i++; | 89 | i++; | ||
87 | if (i >= end) { | 90 | if (i >= end) { | ||
88 | break; | 91 | break; | ||
89 | } | 92 | } | ||
90 | } | 93 | } | ||
91 | } | 94 | } | ||
92 | 95 | | |||
93 | void ConversationsDbusInterface::addMessage(const ConversationMessage &message) | 96 | void ConversationsDbusInterface::addMessage(const ConversationMessage &message) | ||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |
Use m_conversations.value(conversationID). Otherwise, if conversationId doesn't exist, it will create the entry and leave it empty.