summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-09-07 20:05:30 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-09-07 20:05:30 +0300
commit9e8f0b7409ff34b1235908b4c9d619b2a43d7a11 (patch)
tree558863c4a701f159492b0ce700db3b29c8969e1c /src/timeline
parentFix double href links on username pills (diff)
downloadnheko-9e8f0b7409ff34b1235908b4c9d619b2a43d7a11.tar.xz
Initial support for sending markdown formatted messages
fixes #283
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/TimelineItem.cpp10
-rw-r--r--src/timeline/TimelineView.cpp15
2 files changed, 18 insertions, 7 deletions
diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp

index 267dea15..8e0401a8 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp
@@ -265,16 +265,16 @@ TimelineItem::TimelineItem(mtx::events::MessageType ty, auto timestamp = QDateTime::currentDateTime(); if (ty == mtx::events::MessageType::Emote) { - body = QString("* %1 %2").arg(displayName).arg(body); + body = QString("%1 %2").arg(displayName).arg(body); descriptionMsg_ = {"", userid, body, utils::descriptiveTime(timestamp), timestamp}; } else { descriptionMsg_ = { "You: ", userid, body, utils::descriptiveTime(timestamp), timestamp}; } - body = body.toHtmlEscaped(); - body.replace(conf::strings::url_regex, conf::strings::url_html); - body.replace("\n", "<br/>"); + body = QString::fromStdString(utils::markdownToHtml(body)); + body = utils::linkifyMessage(body); + generateTimestamp(timestamp); if (withSender) { @@ -489,7 +489,7 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Emote> auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts); auto displayName = Cache::displayName(room_id_, sender); - auto emoteMsg = QString("* %1 %2").arg(displayName).arg(formatted_body); + auto emoteMsg = QString("%1 %2").arg(displayName).arg(formatted_body); descriptionMsg_ = {"", sender, emoteMsg, utils::descriptiveTime(timestamp), timestamp}; diff --git a/src/timeline/TimelineView.cpp b/src/timeline/TimelineView.cpp
index bf828a8e..d09f5d5f 100644 --- a/src/timeline/TimelineView.cpp +++ b/src/timeline/TimelineView.cpp
@@ -1233,8 +1233,12 @@ template<> mtx::events::msg::Emote toRoomMessage<mtx::events::msg::Emote>(const PendingMessage &m) { + auto html = utils::markdownToHtml(m.body); + mtx::events::msg::Emote emote; - emote.body = m.body.toStdString(); + emote.body = utils::stripHtml(html); + emote.formatted_body = html; + return emote; } @@ -1254,8 +1258,15 @@ template<> mtx::events::msg::Text toRoomMessage<mtx::events::msg::Text>(const PendingMessage &m) { + auto html = utils::markdownToHtml(m.body); + mtx::events::msg::Text text; - text.body = m.body.toStdString(); + text.body = utils::stripHtml(html); + text.formatted_body = html; + + std::cout << "body: " << text.body << std::endl; + std::cout << "formatted_body: " << text.formatted_body << std::endl; + return text; }