diff --git a/plugins/sms/conversationsdbusinterface.h b/plugins/sms/conversationsdbusinterface.h --- a/plugins/sms/conversationsdbusinterface.h +++ b/plugins/sms/conversationsdbusinterface.h @@ -68,6 +68,11 @@ */ void replyToConversation(const QString& conversationID, const QString& message); + /** + * Send a new message to an empty conversation + */ + void createNewConversation(const QString& address, const QString& message); + /** * Send the request to the Telephony plugin to update the list of conversation threads */ @@ -76,8 +81,8 @@ Q_SIGNALS: Q_SCRIPTABLE void conversationCreated(const QVariantMap& msg); Q_SCRIPTABLE void conversationRemoved(const QString& threadID); - Q_SCRIPTABLE void conversationUpdated(const QVariantMap& msg); - Q_SCRIPTABLE void conversationMessageReceived(const QVariantMap& msg, int pos); + Q_SCRIPTABLE void conversationUpdated(const QVariantMap& msg) const; + Q_SCRIPTABLE void conversationMessageReceived(const QVariantMap& msg, int pos) const; private /*methods*/: QString newId(); //Generates successive identifitiers to use as public ids diff --git a/plugins/sms/conversationsdbusinterface.cpp b/plugins/sms/conversationsdbusinterface.cpp --- a/plugins/sms/conversationsdbusinterface.cpp +++ b/plugins/sms/conversationsdbusinterface.cpp @@ -122,7 +122,9 @@ const auto messagesList = m_conversations[conversationID]; if (messagesList.isEmpty()) { // Since there are no messages in the conversation, we can't do anything sensible - qCWarning(KDECONNECT_CONVERSATIONS) << "Got a conversationID for a conversation with no messages!"; + // qCDebug(KDECONNECT_CONVERSATIONS) << "Got a conversationID for a conversation with no messages!"; + qCDebug(KDECONNECT_CONVERSATIONS) << "Trying to send a new message to new conversation with address " << conversationID << endl; + createNewConversation(conversationID, message); return; } // Caution: @@ -133,6 +135,10 @@ m_smsInterface.sendSms(address, message); } +void ConversationsDbusInterface::createNewConversation(const QString& address, const QString& message) { + m_smsInterface.sendSms(address, message); +} + void ConversationsDbusInterface::requestAllConversationThreads() { // Prepare the list of conversations by requesting the first in every thread diff --git a/smsapp/conversationlistmodel.h b/smsapp/conversationlistmodel.h --- a/smsapp/conversationlistmodel.h +++ b/smsapp/conversationlistmodel.h @@ -90,6 +90,7 @@ void handleCreatedConversation(const QVariantMap& msg); void handleConversationUpdated(const QVariantMap& msg); void createRowFromMessage(const QVariantMap& message); + void createRowFromAddress(const QString& address); void printDBusError(const QDBusError& error); private: diff --git a/smsapp/conversationlistmodel.cpp b/smsapp/conversationlistmodel.cpp --- a/smsapp/conversationlistmodel.cpp +++ b/smsapp/conversationlistmodel.cpp @@ -166,6 +166,25 @@ appendRow(item); } +void ConversationListModel::createRowFromAddress(const QString& address) { + QScopedPointer personData(lookupPersonByAddress(address)); + QStandardItem* item = new QStandardItem(); + if (personData) { + item->setText(personData->name()); + item->setIcon(QIcon(personData->photo())); + item->setData(personData->personUri(), PersonUriRole); + } else { + item->setData(QString(), PersonUriRole); + item->setText(address); + } + item->setData(address.toInt(), ConversationIdRole); + item->setData(address, AddressRole); + item->setData(ConversationMessage::MessageTypeSent, FromMeRole); + item->setData("[New conversation]", Qt::ToolTipRole); + item->setData(1, DateRole); + appendRow(item); +} + KPeople::PersonData* ConversationListModel::lookupPersonByAddress(const QString& address) { const QString& canonicalAddress = canonicalizePhoneNumber(address); diff --git a/smsapp/qml/ConversationList.qml b/smsapp/qml/ConversationList.qml --- a/smsapp/qml/ConversationList.qml +++ b/smsapp/qml/ConversationList.qml @@ -65,6 +65,7 @@ filterCaseSensitivity: Qt.CaseInsensitive sourceModel: ConversationListModel { deviceId: device ? device.id() : "" + id: address } } @@ -79,6 +80,10 @@ Keys.onUpPressed: view.currentIndex = Math.max(view.currentIndex-1, 0) Keys.onDownPressed: view.currentIndex = Math.min(view.currentIndex+1, view.count-1) onAccepted: { + if(view.count == 0) { + address.createRowFromAddress(filter.text) + view.currentIndex = 1 // the first possible seleciton + } view.currentItem.startChat() } Shortcut {