fix macos build error

This commit is contained in:
targetakhil 2021-04-22 08:19:27 +05:30
parent 5a5aba662e
commit ddb1983c63
4 changed files with 22 additions and 23 deletions

View File

@ -52,22 +52,26 @@ createDescriptionInfo(const Event &event, const QString &localUser, const QStrin
ts}; ts};
} }
void std::string
utils::stripReplyFromBody(QString &body) utils::stripReplyFromBody(const std::string &bodyi)
{ {
QString body = QString::fromStdString(bodyi);
QRegularExpression plainQuote("^>.*?$\n?", QRegularExpression::MultilineOption); QRegularExpression plainQuote("^>.*?$\n?", QRegularExpression::MultilineOption);
while (body.startsWith(">")) while (body.startsWith(">"))
body.remove(plainQuote); body.remove(plainQuote);
if (body.startsWith("\n")) if (body.startsWith("\n"))
body.remove(0, 1); body.remove(0, 1);
return body.toStdString();
} }
void std::string
utils::stripReplyFromFormattedBody(QString &formatted_body) utils::stripReplyFromFormattedBody(const std::string &formatted_bodyi)
{ {
QString formatted_body = QString::fromStdString(formatted_bodyi);
formatted_body.remove(QRegularExpression("<mx-reply>.*</mx-reply>", formatted_body.remove(QRegularExpression("<mx-reply>.*</mx-reply>",
QRegularExpression::DotMatchesEverythingOption)); QRegularExpression::DotMatchesEverythingOption));
formatted_body.replace("@room", "@\u2060aroom"); formatted_body.replace("@room", "@\u2060aroom");
return formatted_body.toStdString();
} }
RelatedInfo RelatedInfo
@ -81,13 +85,15 @@ utils::stripReplyFallbacks(const TimelineEvent &event, std::string id, QString r
// get body, strip reply fallback, then transform the event to text, if it is a media event // get body, strip reply fallback, then transform the event to text, if it is a media event
// etc // etc
related.quoted_body = QString::fromStdString(mtx::accessors::body(event)); related.quoted_body = QString::fromStdString(mtx::accessors::body(event));
stripReplyFromBody(related.quoted_body); related.quoted_body =
QString::fromStdString(stripReplyFromBody(related.quoted_body.toStdString()));
related.quoted_body = utils::getQuoteBody(related); related.quoted_body = utils::getQuoteBody(related);
related.quoted_body.replace("@room", QString::fromUtf8("@\u2060room")); related.quoted_body.replace("@room", QString::fromUtf8("@\u2060room"));
// get quoted body and strip reply fallback // get quoted body and strip reply fallback
related.quoted_formatted_body = mtx::accessors::formattedBodyWithFallback(event); related.quoted_formatted_body = mtx::accessors::formattedBodyWithFallback(event);
stripReplyFromFormattedBody(related.quoted_formatted_body); related.quoted_formatted_body = QString::fromStdString(
stripReplyFromFormattedBody(related.quoted_formatted_body.toStdString()));
related.room = room_id_; related.room = room_id_;
return related; return related;

View File

@ -42,12 +42,12 @@ namespace utils {
using TimelineEvent = mtx::events::collections::TimelineEvents; using TimelineEvent = mtx::events::collections::TimelineEvents;
//! Helper function to remove reply fallback from body //! Helper function to remove reply fallback from body
void std::string
stripReplyFromBody(QString &body); stripReplyFromBody(const std::string &body);
//! Helper function to remove reply fallback from formatted body //! Helper function to remove reply fallback from formatted body
void std::string
stripReplyFromFormattedBody(QString &formatted_body); stripReplyFromFormattedBody(const std::string &formatted_body);
RelatedInfo RelatedInfo
stripReplyFallbacks(const TimelineEvent &event, std::string id, QString room_id_); stripReplyFallbacks(const TimelineEvent &event, std::string id, QString room_id_);

View File

@ -632,9 +632,8 @@ TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEven
const std::string &content_type, const std::string &content_type,
const std::string &originalFilename, const std::string &originalFilename,
mtx::http::RequestErr err) { mtx::http::RequestErr err) {
if (err) { if (err)
return; return;
}
auto data = mtx::crypto::to_string( auto data = mtx::crypto::to_string(
mtx::crypto::decrypt_file(res, encryptionInfo.value())); mtx::crypto::decrypt_file(res, encryptionInfo.value()));
@ -654,7 +653,7 @@ TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEven
} }
std::visit( std::visit(
[this, roomId, e, url = res.content_uri](auto ev) { [this, roomId, url = res.content_uri](auto ev) {
if constexpr (mtx::events::message_content_to_type< if constexpr (mtx::events::message_content_to_type<
decltype(ev.content)> == decltype(ev.content)> ==
mtx::events::EventType::RoomMessage) { mtx::events::EventType::RoomMessage) {

View File

@ -182,25 +182,19 @@ private:
if constexpr (std::is_same_v<std::optional<std::string>, if constexpr (std::is_same_v<std::optional<std::string>,
std::remove_cv_t<decltype(e.content.body)>>) { std::remove_cv_t<decltype(e.content.body)>>) {
if (e.content.body) { if (e.content.body) {
QString body = QString::fromStdString(e.content.body); e.content.body = utils::stripReplyFromBody(e.content.body);
utils::stripReplyFromBody(body);
e.content.body = body.toStdString();
} }
} else if constexpr (std::is_same_v< } else if constexpr (std::is_same_v<
std::string, std::string,
std::remove_cv_t<decltype(e.content.body)>>) { std::remove_cv_t<decltype(e.content.body)>>) {
QString body = QString::fromStdString(e.content.body); e.content.body = utils::stripReplyFromBody(e.content.body);
utils::stripReplyFromBody(body);
e.content.body = body.toStdString();
} }
} }
if constexpr (is_detected<formatted_body_t, T>::value) { if constexpr (is_detected<formatted_body_t, T>::value) {
if (e.content.format == "org.matrix.custom.html") { if (e.content.format == "org.matrix.custom.html") {
QString formattedBody = e.content.formatted_body =
QString::fromStdString(e.content.formatted_body); utils::stripReplyFromFormattedBody(e.content.formatted_body);
utils::stripReplyFromFormattedBody(formattedBody);
e.content.formatted_body = formattedBody.toStdString();
} }
} }
} }