Skip to content
Snippets Groups Projects
Commit 506eb7bc authored by Sébastien Blin's avatar Sébastien Blin
Browse files

messagelistmodel: never ever edit body from client

This is impossible to follow correctly, causing weird things.
Now Body always contains the original Body from the libclient,
LinkifiedBody the linkified Body and Linkified is empty if the
message is not linkified.

Change-Id: I29e5f7cf1c5a2093f5e4b7785216e8b9b24e9ad8
GitLab: #961
parent 5f6f86b2
No related branches found
No related tags found
No related merge requests found
......@@ -52,7 +52,12 @@ SBSMessageBase {
padding: isEmojiOnly ? 0 : JamiTheme.preferredMarginSize
anchors.right: isOutgoing ? parent.right : undefined
text: Body === "" ? "*("+ JamiStrings.deletedMessage +")*" : Body
text: {
if (LinkifiedBody !== "" && Linkified.length === 0) {
MessagesAdapter.parseMessageUrls(Id, Body, UtilsAdapter.getAppValue(Settings.DisplayHyperlinkPreviews), root.colorUrl)
}
return (LinkifiedBody !== "") ? LinkifiedBody : "*("+ JamiStrings.deletedMessage +")*"
}
horizontalAlignment: Text.AlignLeft
HoverHandler {
......@@ -268,7 +273,7 @@ SBSMessageBase {
opacity: 0
Behavior on opacity { NumberAnimation { duration: 100 } }
Component.onCompleted: {
if (!Linkified) {
if (Linkified.length === 0) {
MessagesAdapter.parseMessageUrls(Id, Body, UtilsAdapter.getAppValue(Settings.DisplayHyperlinkPreviews), root.colorUrl)
}
opacity = 1
......
......@@ -34,8 +34,7 @@ Rectangle {
property var body: {
if (MessagesAdapter.editId === "")
return ""
return MessagesAdapter.dataForInteraction(MessagesAdapter.editId, MessageList.Body)
return MessagesAdapter.dataForInteraction(MessagesAdapter.editId, MessageList.LinkifiedBody)
}
RowLayout {
......
......@@ -312,7 +312,7 @@ struct Info
bool isRead = false;
MapStringString commit;
QVariantMap linkPreviewInfo = {};
bool linkified = false;
QString linkified;
QVariantMap reactions;
QString react_to;
QVector<Body> previousBodies;
......
......@@ -455,6 +455,12 @@ MessageListModel::dataForItem(item_t item, int, int role) const
return QVariant(item.second.linkPreviewInfo);
case Role::Linkified:
return QVariant(item.second.linkified);
case Role::LinkifiedBody: {
if (!item.second.linkified.isEmpty()) {
return QVariant(item.second.linkified);
}
return QVariant(item.second.body);
}
case Role::ActionUri:
return QVariant(item.second.commit["uri"]);
case Role::ConfId:
......@@ -474,10 +480,14 @@ MessageListModel::dataForItem(item_t item, int, int role) const
return QVariant(replyId);
case Role::ReplyToAuthor:
return repliedMsg == -1 ? QVariant("") : QVariant(data(repliedMsg, Role::Author));
case Role::ReplyToBody:
return repliedMsg == -1
? QVariant("")
: QVariant(data(repliedMsg, Role::Body).toString().replace("\n", " "));
case Role::ReplyToBody: {
if (repliedMsg == -1)
return QVariant("");
auto linkified = data(repliedMsg, Role::Linkified).toString();
if (!linkified.isEmpty())
return QVariant(linkified.replace("\n", " "));
return QVariant(data(repliedMsg, Role::Body).toString().replace("\n", " "));
}
case Role::TotalSize:
return QVariant(item.second.commit["totalSize"].toInt());
case Role::TransferName:
......@@ -545,9 +555,8 @@ MessageListModel::linkifyMessage(const QString& messageId, const QString& linkif
return;
}
QModelIndex modelIndex = QAbstractListModel::index(index, 0);
interactions_[index].second.body = linkified;
interactions_[index].second.linkified = true;
Q_EMIT dataChanged(modelIndex, modelIndex, {Role::Body, Role::Linkified});
interactions_[index].second.linkified = linkified;
Q_EMIT dataChanged(modelIndex, modelIndex, {Role::Linkified, Role::LinkifiedBody});
}
void
......@@ -700,9 +709,12 @@ MessageListModel::editMessage(const QString& msgId, interaction::Info& info)
}
}
info.body = it->rbegin()->body;
info.linkified.clear();
editedBodies_.erase(it);
emitDataChanged(msgId,
{MessageList::Role::Body,
MessageList::Role::Linkified,
MessageList::Role::LinkifiedBody,
MessageList::Role::PreviousBodies,
MessageList::Role::IsEmojiOnly});
......
......@@ -46,6 +46,7 @@ struct Info;
X(DeviceId) \
X(LinkPreviewInfo) \
X(Linkified) \
X(LinkifiedBody) \
X(PreviousBodies) \
X(Reactions) \
X(ReplyTo) \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment