Changeset View
Changeset View
Standalone View
Standalone View
smsapp/conversationmodel.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
47 | void ConversationModel::setThreadId(const QString &threadId) | 47 | void ConversationModel::setThreadId(const QString &threadId) | ||
48 | { | 48 | { | ||
49 | if (m_threadId == threadId) | 49 | if (m_threadId == threadId) | ||
50 | return; | 50 | return; | ||
51 | 51 | | |||
52 | m_threadId = threadId; | 52 | m_threadId = threadId; | ||
53 | clear(); | 53 | clear(); | ||
54 | if (!threadId.isEmpty()) { | 54 | if (!threadId.isEmpty()) { | ||
55 | m_conversationsInterface->requestConversation(threadId, 0, 10); | 55 | requestMoreMessages(); | ||
56 | } | 56 | } | ||
57 | } | 57 | } | ||
58 | 58 | | |||
59 | void ConversationModel::setDeviceId(const QString& deviceId) | 59 | void ConversationModel::setDeviceId(const QString& deviceId) | ||
60 | { | 60 | { | ||
61 | if (deviceId == m_deviceId) | 61 | if (deviceId == m_deviceId) | ||
62 | return; | 62 | return; | ||
63 | 63 | | |||
64 | qCDebug(KDECONNECT_SMS_CONVERSATION_MODEL) << "setDeviceId" << "of" << this; | 64 | qCDebug(KDECONNECT_SMS_CONVERSATION_MODEL) << "setDeviceId" << "of" << this; | ||
65 | if (m_conversationsInterface) { | 65 | if (m_conversationsInterface) { | ||
66 | disconnect(m_conversationsInterface, SIGNAL(conversationMessageReceived(QVariantMap, int)), this, SLOT(createRowFromMessage(QVariantMap, int))); | | |||
67 | disconnect(m_conversationsInterface, SIGNAL(conversationUpdated(QVariantMap)), this, SLOT(handleConversationUpdate(QVariantMap))); | 66 | disconnect(m_conversationsInterface, SIGNAL(conversationUpdated(QVariantMap)), this, SLOT(handleConversationUpdate(QVariantMap))); | ||
68 | delete m_conversationsInterface; | 67 | delete m_conversationsInterface; | ||
69 | } | 68 | } | ||
70 | 69 | | |||
71 | m_deviceId = deviceId; | 70 | m_deviceId = deviceId; | ||
72 | 71 | | |||
73 | m_conversationsInterface = new DeviceConversationsDbusInterface(deviceId, this); | 72 | m_conversationsInterface = new DeviceConversationsDbusInterface(deviceId, this); | ||
74 | connect(m_conversationsInterface, SIGNAL(conversationMessageReceived(QVariantMap,int)), this, SLOT(createRowFromMessage(QVariantMap,int))); | | |||
75 | connect(m_conversationsInterface, SIGNAL(conversationUpdated(QVariantMap)), this, SLOT(handleConversationUpdate(QVariantMap))); | 73 | connect(m_conversationsInterface, SIGNAL(conversationUpdated(QVariantMap)), this, SLOT(handleConversationUpdate(QVariantMap))); | ||
76 | } | 74 | } | ||
77 | 75 | | |||
78 | void ConversationModel::sendReplyToConversation(const QString& message) | 76 | void ConversationModel::sendReplyToConversation(const QString& message) | ||
79 | { | 77 | { | ||
80 | qCDebug(KDECONNECT_SMS_CONVERSATION_MODEL) << "Trying to send" << message << "to conversation with ID" << m_threadId; | 78 | qCDebug(KDECONNECT_SMS_CONVERSATION_MODEL) << "Trying to send" << message << "to conversation with ID" << m_threadId; | ||
81 | m_conversationsInterface->replyToConversation(m_threadId, message); | 79 | m_conversationsInterface->replyToConversation(m_threadId, message); | ||
82 | } | 80 | } | ||
83 | 81 | | |||
82 | void ConversationModel::requestMoreMessages(const quint32& howMany) | ||||
83 | { | ||||
84 | if (m_threadId.isEmpty()) { | ||||
85 | return; | ||||
86 | } | ||||
87 | const auto& numMessages = rowCount(); | ||||
88 | m_conversationsInterface->requestConversation(m_threadId, numMessages, numMessages + howMany); | ||||
89 | } | ||||
90 | | ||||
84 | void ConversationModel::createRowFromMessage(const QVariantMap& msg, int pos) | 91 | void ConversationModel::createRowFromMessage(const QVariantMap& msg, int pos) | ||
85 | { | 92 | { | ||
86 | const ConversationMessage message(msg); | 93 | const ConversationMessage message(msg); | ||
87 | 94 | | |||
88 | if (!(message.threadID() == m_threadId.toInt())) { | 95 | if (!(message.threadID() == m_threadId.toInt())) { | ||
89 | // Because of the asynchronous nature of the current implementation of this model, if the | 96 | // Because of the asynchronous nature of the current implementation of this model, if the | ||
90 | // user clicks quickly between threads or for some other reason a message comes when we're | 97 | // user clicks quickly between threads or for some other reason a message comes when we're | ||
91 | // not expecting it, we should not display it in the wrong place | 98 | // not expecting it, we should not display it in the wrong place | ||
Show All 27 Lines |