Skip to content
Snippets Groups Projects
Commit 50888a28 authored by Aline Gondim Santos's avatar Aline Gondim Santos
Browse files

shortcut: add option to edit last sent message

GitLab: #892
Change-Id: Ia62ac144d187e705644742ebaa9b1679c45d2ae0
parent eb003449
Branches
Tags
No related merge requests found
...@@ -53,6 +53,7 @@ CurrentConversation::updateData() ...@@ -53,6 +53,7 @@ CurrentConversation::updateData()
const auto& accInfo = lrcInstance_->accountModel().getAccountInfo(accountId); const auto& accInfo = lrcInstance_->accountModel().getAccountInfo(accountId);
if (auto optConv = accInfo.conversationModel->getConversationForUid(convId)) { if (auto optConv = accInfo.conversationModel->getConversationForUid(convId)) {
auto& convInfo = optConv->get(); auto& convInfo = optConv->get();
set_lastSelfMessageId(convInfo.lastSelfMessageId);
set_uris(convInfo.participantsUris()); set_uris(convInfo.participantsUris());
set_isSwarm(convInfo.isSwarm()); set_isSwarm(convInfo.isSwarm());
set_isLegacy(convInfo.isLegacy()); set_isLegacy(convInfo.isLegacy());
......
...@@ -54,6 +54,7 @@ class CurrentConversation final : public QObject ...@@ -54,6 +54,7 @@ class CurrentConversation final : public QObject
QML_PROPERTY(QVariantList, activeCalls) QML_PROPERTY(QVariantList, activeCalls)
QML_PROPERTY(QStringList, errors) QML_PROPERTY(QStringList, errors)
QML_PROPERTY(QStringList, backendErrors) QML_PROPERTY(QStringList, backendErrors)
QML_PROPERTY(QString, lastSelfMessageId)
// TODO: these belong in CurrentCall(which doesn't exist yet) // TODO: these belong in CurrentCall(which doesn't exist yet)
QML_PROPERTY(bool, hideSelf) QML_PROPERTY(bool, hideSelf)
......
...@@ -124,7 +124,6 @@ Rectangle { ...@@ -124,7 +124,6 @@ Rectangle {
} }
} }
Connections { Connections {
target: CurrentConversation target: CurrentConversation
enabled: true enabled: true
...@@ -293,4 +292,14 @@ Rectangle { ...@@ -293,4 +292,14 @@ Rectangle {
} }
} }
} }
Shortcut {
sequence: "Ctrl+Escape"
context: Qt.WindowShortcut
enabled: root.visible
onActivated: {
MessagesAdapter.replyToId = ""
MessagesAdapter.editId = ""
}
}
} }
...@@ -105,6 +105,14 @@ Window { ...@@ -105,6 +105,14 @@ Window {
shortcut: "Shift + Ctrl + A" shortcut: "Shift + Ctrl + A"
description: qsTr("Accept contact request") description: qsTr("Accept contact request")
} }
ListElement {
shortcut: ""
description: qsTr("Edit last message")
}
ListElement {
shortcut: "Ctrl + Esc"
description: qsTr("Cancel message edition")
}
} }
ListModel { ListModel {
......
...@@ -104,6 +104,12 @@ JamiFlickable { ...@@ -104,6 +104,12 @@ JamiFlickable {
if (keyEvent.matches(StandardKey.Paste)) { if (keyEvent.matches(StandardKey.Paste)) {
MessagesAdapter.onPaste() MessagesAdapter.onPaste()
keyEvent.accepted = true keyEvent.accepted = true
} else if (keyEvent.matches(StandardKey.MoveToPreviousLine)) {
if (root.text !== "")
return
MessagesAdapter.replyToId = ""
MessagesAdapter.editId = CurrentConversation.lastSelfMessageId
keyEvent.accepted = true;
} else if (keyEvent.key === Qt.Key_Enter || } else if (keyEvent.key === Qt.Key_Enter ||
keyEvent.key === Qt.Key_Return) { keyEvent.key === Qt.Key_Return) {
if (!(keyEvent.modifiers & Qt.ShiftModifier)) { if (!(keyEvent.modifiers & Qt.ShiftModifier)) {
......
...@@ -78,6 +78,7 @@ struct Info ...@@ -78,6 +78,7 @@ struct Info
QString confId; QString confId;
std::unique_ptr<MessageListModel> interactions; std::unique_ptr<MessageListModel> interactions;
QString lastMessageUid; QString lastMessageUid;
QString lastSelfMessageId;
QHash<QString, QString> parentsId; // pair messageid/parentid for messages without parent loaded QHash<QString, QString> parentsId; // pair messageid/parentid for messages without parent loaded
unsigned int unreadMessages = 0; unsigned int unreadMessages = 0;
QVector<QPair<int, QString>> errors; QVector<QPair<int, QString>> errors;
......
...@@ -1307,6 +1307,7 @@ ConversationModel::sendMessage(const QString& uid, const QString& body, const QS ...@@ -1307,6 +1307,7 @@ ConversationModel::sendMessage(const QString& uid, const QString& body, const QS
} }
newConv.lastMessageUid = msgId; newConv.lastMessageUid = msgId;
newConv.lastSelfMessageId = msgId;
// Emit this signal for chatview in the client // Emit this signal for chatview in the client
Q_EMIT newInteraction(convId, msgId, msg); Q_EMIT newInteraction(convId, msgId, msg);
// This conversation is now at the top of the list // This conversation is now at the top of the list
...@@ -1486,6 +1487,9 @@ ConversationModel::clearInteractionFromConversation(const QString& convId, ...@@ -1486,6 +1487,9 @@ ConversationModel::clearInteractionFromConversation(const QString& convId,
conversation.lastMessageUid = newLastId; conversation.lastMessageUid = newLastId;
lastInteractionUpdated = true; lastInteractionUpdated = true;
} }
if (conversation.lastSelfMessageId == interactionId) {
conversation.lastSelfMessageId = conversation.interactions->lastSelfMessageId();
}
} catch (const std::out_of_range& e) { } catch (const std::out_of_range& e) {
qDebug() << "can't clear interaction from conversation: " << e.what(); qDebug() << "can't clear interaction from conversation: " << e.what();
...@@ -1521,6 +1525,7 @@ ConversationModel::clearInteractionsCache(const QString& convId) ...@@ -1521,6 +1525,7 @@ ConversationModel::clearInteractionsCache(const QString& convId)
} }
conversation.allMessagesLoaded = false; conversation.allMessagesLoaded = false;
conversation.lastMessageUid = ""; conversation.lastMessageUid = "";
conversation.lastSelfMessageId = "";
ConfigurationManager::instance().loadConversationMessages(owner.id, convId, "", 1); ConfigurationManager::instance().loadConversationMessages(owner.id, convId, "", 1);
} }
} catch (const std::out_of_range& e) { } catch (const std::out_of_range& e) {
...@@ -2469,6 +2474,7 @@ ConversationModelPimpl::slotConversationLoaded(uint32_t requestId, ...@@ -2469,6 +2474,7 @@ ConversationModelPimpl::slotConversationLoaded(uint32_t requestId,
} }
conversation.lastMessageUid = conversation.interactions->lastMessageUid(); conversation.lastMessageUid = conversation.interactions->lastMessageUid();
conversation.lastSelfMessageId = conversation.interactions->lastSelfMessageId();
if (conversation.lastMessageUid.isEmpty() && !conversation.allMessagesLoaded if (conversation.lastMessageUid.isEmpty() && !conversation.allMessagesLoaded
&& messages.size() != 0) { && messages.size() != 0) {
if (conversation.interactions->size() > 0) { if (conversation.interactions->size() > 0) {
...@@ -2627,6 +2633,7 @@ ConversationModelPimpl::slotMessageReceived(const QString& accountId, ...@@ -2627,6 +2633,7 @@ ConversationModelPimpl::slotMessageReceived(const QString& accountId,
return; return;
} }
conversation.lastMessageUid = conversation.interactions->lastMessageUid(); conversation.lastMessageUid = conversation.interactions->lastMessageUid();
conversation.lastSelfMessageId = conversation.interactions->lastSelfMessageId();
invalidateModel(); invalidateModel();
if (!interaction::isOutgoing(msg)) { if (!interaction::isOutgoing(msg)) {
Q_EMIT behaviorController.newUnreadInteraction(linked.owner.id, Q_EMIT behaviorController.newUnreadInteraction(linked.owner.id,
......
...@@ -648,4 +648,17 @@ MessageListModel::lastMessageUid() const ...@@ -648,4 +648,17 @@ MessageListModel::lastMessageUid() const
return {}; return {};
} }
QString
MessageListModel::lastSelfMessageId() const
{
for (auto it = interactions_.rbegin(); it != interactions_.rend(); ++it) {
auto lastType = it->second.type;
if (lastType == interaction::Type::TEXT
and !it->second.body.isEmpty() and it->second.authorUri.isEmpty()) {
return it->first;
}
}
return {};
}
} // namespace lrc } // namespace lrc
...@@ -138,6 +138,7 @@ public: ...@@ -138,6 +138,7 @@ public:
void addEdition(const QString& msgId, const interaction::Info& info, bool end); void addEdition(const QString& msgId, const interaction::Info& info, bool end);
void editMessage(const QString& msgId, interaction::Info& info); void editMessage(const QString& msgId, interaction::Info& info);
QString lastMessageUid() const; QString lastMessageUid() const;
QString lastSelfMessageId() const;
protected: protected:
using Role = MessageList::Role; using Role = MessageList::Role;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment