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};
}
void
utils::stripReplyFromBody(QString &body)
std::string
utils::stripReplyFromBody(const std::string &bodyi)
{
QString body = QString::fromStdString(bodyi);
QRegularExpression plainQuote("^>.*?$\n?", QRegularExpression::MultilineOption);
while (body.startsWith(">"))
body.remove(plainQuote);
if (body.startsWith("\n"))
body.remove(0, 1);
return body.toStdString();
}
void
utils::stripReplyFromFormattedBody(QString &formatted_body)
std::string
utils::stripReplyFromFormattedBody(const std::string &formatted_bodyi)
{
QString formatted_body = QString::fromStdString(formatted_bodyi);
formatted_body.remove(QRegularExpression("<mx-reply>.*</mx-reply>",
QRegularExpression::DotMatchesEverythingOption));
formatted_body.replace("@room", "@\u2060aroom");
return formatted_body.toStdString();
}
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
// etc
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.replace("@room", QString::fromUtf8("@\u2060room"));
// get quoted body and strip reply fallback
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_;
return related;

View File

@ -42,12 +42,12 @@ namespace utils {
using TimelineEvent = mtx::events::collections::TimelineEvents;
//! Helper function to remove reply fallback from body
void
stripReplyFromBody(QString &body);
std::string
stripReplyFromBody(const std::string &body);
//! Helper function to remove reply fallback from formatted body
void
stripReplyFromFormattedBody(QString &formatted_body);
std::string
stripReplyFromFormattedBody(const std::string &formatted_body);
RelatedInfo
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 &originalFilename,
mtx::http::RequestErr err) {
if (err) {
if (err)
return;
}
auto data = mtx::crypto::to_string(
mtx::crypto::decrypt_file(res, encryptionInfo.value()));
@ -654,7 +653,7 @@ TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEven
}
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<
decltype(ev.content)> ==
mtx::events::EventType::RoomMessage) {

View File

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