diff --git a/Linphone/core/chat/message/content/ChatMessageContentCore.cpp b/Linphone/core/chat/message/content/ChatMessageContentCore.cpp index c68fd10e6..a1e365c5b 100644 --- a/Linphone/core/chat/message/content/ChatMessageContentCore.cpp +++ b/Linphone/core/chat/message/content/ChatMessageContentCore.cpp @@ -64,7 +64,13 @@ ChatMessageContentCore::ChatMessageContentCore(const std::shared_ptrgetUtf8Text()); auto chatRoom = chatMessageModel ? chatMessageModel->getMonitor()->getChatRoom() : nullptr; - mRichFormatText = ToolModel::encodeTextToQmlRichFormat(mUtf8Text, {}, chatRoom); + mRichFormatText = ToolModel::encodeTextToQmlRichFormat(mUtf8Text, mSearchedTextPart, {}, chatRoom); + connect(this, &ChatMessageContentCore::searchedTextPartChanged, this, [this] { + auto chatroom = mChatMessageContentModel->getChatMessageModel() + ? mChatMessageContentModel->getChatMessageModel()->getMonitor()->getChatRoom() + : nullptr; + setRichFormatText(ToolModel::encodeTextToQmlRichFormat(mUtf8Text, mSearchedTextPart, {}, chatroom)); + }); mWasDownloaded = !mFilePath.isEmpty() && QFileInfo(mFilePath).isFile(); mThumbnail = mFilePath.isEmpty() ? QUrl() @@ -246,10 +252,6 @@ ConferenceInfoGui *ChatMessageContentCore::getConferenceInfoGui() const { return mConferenceInfo ? new ConferenceInfoGui(mConferenceInfo) : nullptr; } -bool ChatMessageContentCore::wasDownloaded() const { - return mWasDownloaded; -} - QUrl ChatMessageContentCore::getThumbnail() const { return mThumbnail; } @@ -260,6 +262,10 @@ void ChatMessageContentCore::setThumbnail(const QUrl &data) { emit thumbnailChanged(); } } + +bool ChatMessageContentCore::wasDownloaded() const { + return mWasDownloaded; +} void ChatMessageContentCore::setWasDownloaded(bool wasDownloaded) { if (mWasDownloaded != wasDownloaded) { mWasDownloaded = wasDownloaded; @@ -267,6 +273,24 @@ void ChatMessageContentCore::setWasDownloaded(bool wasDownloaded) { } } +void ChatMessageContentCore::setRichFormatText(const QString &richFormatText) { + if (mRichFormatText != richFormatText) { + mRichFormatText = richFormatText; + emit richFormatTextChanged(); + } +} + +void ChatMessageContentCore::setSearchedTextPart(const QString &searchedTextPart) { + if (mSearchedTextPart != searchedTextPart) { + mSearchedTextPart = searchedTextPart; + emit searchedTextPartChanged(); + } +} + +QString ChatMessageContentCore::getSearchedTextPart() const { + return mSearchedTextPart; +} + const std::shared_ptr &ChatMessageContentCore::getContentModel() const { return mChatMessageContentModel; } diff --git a/Linphone/core/chat/message/content/ChatMessageContentCore.hpp b/Linphone/core/chat/message/content/ChatMessageContentCore.hpp index b0f33c9d2..23260cc1d 100644 --- a/Linphone/core/chat/message/content/ChatMessageContentCore.hpp +++ b/Linphone/core/chat/message/content/ChatMessageContentCore.hpp @@ -40,7 +40,8 @@ class ChatMessageContentCore : public QObject, public AbstractObject { Q_PROPERTY(bool wasDownloaded READ wasDownloaded WRITE setWasDownloaded NOTIFY wasDownloadedChanged) Q_PROPERTY(QString filePath READ getFilePath WRITE setFilePath NOTIFY filePathChanged) Q_PROPERTY(QString utf8Text READ getUtf8Text CONSTANT) - Q_PROPERTY(QString richFormatText MEMBER mRichFormatText CONSTANT) + Q_PROPERTY(QString richFormatText WRITE setRichFormatText MEMBER mRichFormatText NOTIFY richFormatTextChanged) + Q_PROPERTY(QString searchTextPart READ getSearchedTextPart WRITE setSearchedTextPart NOTIFY searchedTextPartChanged) Q_PROPERTY(bool isFile READ isFile WRITE setIsFile NOTIFY isFileChanged) Q_PROPERTY(bool isFileEncrypted READ isFileEncrypted WRITE setIsFileEncrypted NOTIFY isFileEncryptedChanged) Q_PROPERTY(bool isFileTransfer READ isFileTransfer WRITE setIsFileTransfer NOTIFY isFileTransferChanged) @@ -90,6 +91,10 @@ public: bool wasDownloaded() const; void setWasDownloaded(bool downloaded); + void setRichFormatText(const QString &richFormatText); + Q_INVOKABLE void setSearchedTextPart(const QString &searchedTextPart); + QString getSearchedTextPart() const; + const std::shared_ptr &getContentModel() const; signals: @@ -102,6 +107,8 @@ signals: void isFileEncryptedChanged(); void wasDownloadedChanged(bool downloaded); void isVideoChanged(); + void searchedTextPartChanged(); + void richFormatTextChanged(); void lCreateThumbnail(const bool &force = false); void lRemoveDownloadedFile(); @@ -124,6 +131,7 @@ private: QUrl mThumbnail; QString mUtf8Text; QString mRichFormatText; + QString mSearchedTextPart; QString mFilePath; QString mName; quint64 mFileSize; diff --git a/Linphone/data/languages/de.ts b/Linphone/data/languages/de.ts index 9a14d02d5..1575aff84 100644 --- a/Linphone/data/languages/de.ts +++ b/Linphone/data/languages/de.ts @@ -2279,24 +2279,24 @@ ChatMessageContentCore - + download_file_default_error Error downloading file %1 Fehler beim Herunterladen der Datei %1 - + info_popup_error_titile Fehler - + popup_error_title Error Fehler - + popup_open_file_error_does_not_exist_message Could not open file : unknown path %1 Datei konnte nicht geöffnet werden: unbekannter Pfad %1 @@ -2361,37 +2361,37 @@ Error Fehler - + download_error_object_doesnt_exist Internal error : message object associated to this content does not exist anymore ! Interner Fehler: Nachrichtenobjekt existiert nicht mehr! - + download_file_server_error Error while trying to download content : %1 Fehler beim Versuch, Inhalte herunterzuladen: %1 - + download_file_error_no_safe_file_path Unable to create safe file path for: %1 Speicherpfad konnte nicht erstellen für: %1 - + download_file_error_file_transfer_unavailable This file was already downloaded and is no more on the server. Your peer have to resend it if you want to get it Diese Datei wurde bereits heruntergeladen und ist nicht mehr auf dem Server verfügbar. Ihr Kontakt muss die Datei erneut senden - + download_file_error_null_name Content name is null, can't download it ! Inhaltsname nicht gesetzt, herunterladen fehlgeschlagen! - + download_file_error_unable_to_download Unable to download file of entry %1 Datei des Eintrags %1 konnte nicht heruntergeladen werden @@ -6050,49 +6050,49 @@ Um sie in einem kommerziellen Projekt zu aktivieren, kontaktieren Sie uns bitte. ToolModel - + call_error_uninterpretable_sip_address "The calling address is not an interpretable SIP address : %1 Die Anrufadresse ist keine interpretierbare SIP-Adresse: %1 - + group_call_error_no_account Kein Standardkonto gefunden, Gruppengespräch kann nicht erstellt werden - + group_call_error_participants_invite Teilnehmer konnten nicht zum Gruppengespräch eingeladen werden - + group_call_error_creation Gruppengespräch konnte nicht erstellt werden - + voice_recording_duration "Voice recording (%1)" : %1 is the duration formated in mm:ss Sprachnachricht (%1) - + conference_invitation Meeting-Einladung - + conference_invitation_updated Meeting-Änderung - + conference_invitation_cancelled Meeting-Absage - + unknown_audio_device_name Unbekannter Gerätename @@ -6100,7 +6100,7 @@ Um sie in einem kommerziellen Projekt zu aktivieren, kontaktieren Sie uns bitte. Utils - + nMinute %1 Minute @@ -6108,7 +6108,7 @@ Um sie in einem kommerziellen Projekt zu aktivieren, kontaktieren Sie uns bitte. - + nHour %1 Stunde @@ -6116,8 +6116,8 @@ Um sie in einem kommerziellen Projekt zu aktivieren, kontaktieren Sie uns bitte. - - + + nDay %1 Tag @@ -6125,7 +6125,7 @@ Um sie in einem kommerziellen Projekt zu aktivieren, kontaktieren Sie uns bitte. - + nWeek %1 Woche @@ -6133,7 +6133,7 @@ Um sie in einem kommerziellen Projekt zu aktivieren, kontaktieren Sie uns bitte. - + nSeconds %1 Sekunde @@ -6259,73 +6259,73 @@ Um sie in einem kommerziellen Projekt zu aktivieren, kontaktieren Sie uns bitte. Offline - + recorder_error Error with the recorder Fehler mit der Aufzeichnung - - - + + + chat_error Fehler im Chat - + chat_message_forward_error Cannot forward an invalid message Eine ungültige Nachricht kann nicht weitergeleitet werden - - - - - - + + + + + + info_popup_error_title Error Fehler - + info_popup_forward_message_error Could not forward message : %1 Nachricht konnte nicht weitergeleitet werden: %1 - + info_popup_send_forward_message_error_message Failed to create forward message Weiterleitungsnachricht konnte nicht erstellt werden - + chat_message_reply_error Cannot reply to invalid message Auf eine ungültige Nachricht kann nicht geantwortet werden - + info_popup_reply_message_error Could not send reply message : %1 Antwort konnte nicht gesendet werden: %1 - + info_popup_send_reply_message_error_message Failed to create reply message Antwort konnte nicht erstellt werden - + info_popup_send_voice_message_error_message Could not send voice message : %1 Sprachnachricht konnte nicht gesendet werden: %1 - + info_popup_send_voice_message_sending_error_message Failed to create message from record Nachricht aus der Aufnahme konnte nicht erstellt werden diff --git a/Linphone/data/languages/en.ts b/Linphone/data/languages/en.ts index 790fe548c..1d3d30b12 100644 --- a/Linphone/data/languages/en.ts +++ b/Linphone/data/languages/en.ts @@ -2242,24 +2242,24 @@ ChatMessageContentCore - + download_file_default_error Error downloading file %1 Error downloading file %1 - + info_popup_error_titile Error - + popup_error_title Error Error - + popup_open_file_error_does_not_exist_message Could not open file : unknown path %1 Could not open file : unknown path %1 @@ -2319,37 +2319,37 @@ Error ChatMessageContentModel - + download_error_object_doesnt_exist Internal error : message object associated to this content does not exist anymore ! Internal error : message object associated to this content does not exist anymore ! - + download_file_server_error Error while trying to download content : %1 Error while trying to download content : %1 - + download_file_error_no_safe_file_path Unable to create safe file path for: %1 Unable to create safe file path for: %1 - + download_file_error_file_transfer_unavailable This file was already downloaded and is no more on the server. Your peer have to resend it if you want to get it This file was already downloaded and is no more on the server. Your peer have to resend it if you want to get it - + download_file_error_null_name Content name is null, can't download it ! Content name is null, can't download it ! - + download_file_error_unable_to_download Unable to download file of entry %1 Unable to download file of entry %1 @@ -5915,49 +5915,49 @@ To enable them in a commercial project, please contact us. ToolModel - + call_error_uninterpretable_sip_address "The calling address is not an interpretable SIP address : %1 The calling address is not an interpretable SIP address : %1 - + group_call_error_no_account No default account found, can't create group call - + group_call_error_participants_invite Couldn't invite participants to group call - + group_call_error_creation Group call couldn't be created - + voice_recording_duration "Voice recording (%1)" : %1 is the duration formated in mm:ss Voice recording (%1) - + unknown_audio_device_name Unknown device name - + conference_invitation Meeting invitation - + conference_invitation_cancelled Meeting cancellation - + conference_invitation_updated Meeting modification @@ -5965,7 +5965,7 @@ To enable them in a commercial project, please contact us. Utils - + nSeconds %1 second @@ -5973,7 +5973,7 @@ To enable them in a commercial project, please contact us. - + nMinute %1 minute @@ -5981,43 +5981,43 @@ To enable them in a commercial project, please contact us. - + chat_message_forward_error Cannot forward an invalid message Cannot forward an invalid message - + info_popup_forward_message_error Could not forward message : %1 Could not forward message : %1 - + info_popup_send_forward_message_error_message Failed to create forward message Failed to create forward message - + chat_message_reply_error Cannot reply to invalid message Cannot reply to invalid message - + info_popup_reply_message_error Could not send reply message : %1 Could not send reply message : %1 - + info_popup_send_reply_message_error_message Failed to create reply message Failed to create reply message - + nHour %1 hour @@ -6025,8 +6025,8 @@ To enable them in a commercial project, please contact us. - - + + nDay %1 day @@ -6034,7 +6034,7 @@ To enable them in a commercial project, please contact us. - + nWeek %1 week @@ -6160,37 +6160,37 @@ To enable them in a commercial project, please contact us. Failed to create 1-1 conversation with %1 ! - + recorder_error Error with the recorder Error with the recorder - - - + + + chat_error Error in the chat - - - - - - + + + + + + info_popup_error_title Error Error - + info_popup_send_voice_message_error_message Could not send voice message : %1 Could not send voice message : %1 - + info_popup_send_voice_message_sending_error_message Failed to create message from record Failed to create message from record diff --git a/Linphone/data/languages/fr.ts b/Linphone/data/languages/fr.ts index 0c39b3b9c..1bf24354a 100644 --- a/Linphone/data/languages/fr.ts +++ b/Linphone/data/languages/fr.ts @@ -2217,24 +2217,24 @@ ChatMessageContentCore - + download_file_default_error Error downloading file %1 Erreur de téléchargement du fichier %1 - + info_popup_error_titile Erreur - + popup_error_title Error Erreur - + popup_open_file_error_does_not_exist_message Could not open file : unknown path %1 Impossible d'ouvrir le fichier : chemin inconnu (%1) @@ -2294,37 +2294,37 @@ Error ChatMessageContentModel - + download_error_object_doesnt_exist Internal error : message object associated to this content does not exist anymore ! Erreur interne : le message associé à ce contenu n'existe plus ! - + download_file_server_error Error while trying to download content : %1 Erreur en tentant de télécharger le contenu : %1 - + download_file_error_no_safe_file_path Unable to create safe file path for: %1 Impossible de créer le chemin : %1 - + download_file_error_file_transfer_unavailable This file was already downloaded and is no more on the server. Your peer have to resend it if you want to get it Le fichier a déjà été téléchargé et n'est plus disponible sur le serveur. Votre correspondant devra vous le renvoyez si vous souhaitez l'obtenir - + download_file_error_null_name Content name is null, can't download it ! Le nom du contenu est nul, impossible de le télécharger ! - + download_file_error_unable_to_download Unable to download file of entry %1 Impossible de télécharger le fichier : %1 @@ -5886,49 +5886,49 @@ Pour les activer dans un projet commercial, merci de nous contacter. ToolModel - + call_error_uninterpretable_sip_address "The calling address is not an interpretable SIP address : %1 L'adresse n'est pas interprétable comme une adresse SIP - + group_call_error_no_account Impossible de créer l'appel de groupe, le compte par défaut n'est pas défini - + group_call_error_participants_invite Impossible d'inviter les participants à l'appel de groupe - + group_call_error_creation L'appel de groupe n'a pas pu être créé - + voice_recording_duration "Voice recording (%1)" : %1 is the duration formated in mm:ss Message vocal (%1) - + unknown_audio_device_name Appareil inconnu - + conference_invitation Invitation à une réunion - + conference_invitation_cancelled Annulation d'une réunion - + conference_invitation_updated Modification d'une réunion @@ -5936,7 +5936,7 @@ Pour les activer dans un projet commercial, merci de nous contacter. Utils - + nMinute %1 minute @@ -5944,7 +5944,7 @@ Pour les activer dans un projet commercial, merci de nous contacter. - + nHour %1 heure @@ -5952,8 +5952,8 @@ Pour les activer dans un projet commercial, merci de nous contacter. - - + + nDay %1 jour @@ -5961,7 +5961,7 @@ Pour les activer dans un projet commercial, merci de nous contacter. - + nWeek %1 semaine @@ -5969,7 +5969,7 @@ Pour les activer dans un projet commercial, merci de nous contacter. - + nSeconds %1 seconde @@ -6095,73 +6095,73 @@ Pour les activer dans un projet commercial, merci de nous contacter.Erreur lors de la création de la conversation avec %1 - + recorder_error Error with the recorder Erreur avec l'enregistreur - - - + + + chat_error Erreur dans le chat - + chat_message_forward_error Cannot forward an invalid message Impossible de transférer : message invalide - - - - - - + + + + + + info_popup_error_title Error Erreur - + info_popup_forward_message_error Could not forward message : %1 Impossible de transférer le message : %1 - + info_popup_send_forward_message_error_message Failed to create forward message Impossible de créer le message - + chat_message_reply_error Cannot reply to invalid message Impossible de répondre : message invalide - + info_popup_reply_message_error Could not send reply message : %1 Impossible d'envoyer la réponse : %1 - + info_popup_send_reply_message_error_message Failed to create reply message Impossible de créer le message - + info_popup_send_voice_message_error_message Could not send voice message : %1 Impossible d'envoyer le message vocal : %1 - + info_popup_send_voice_message_sending_error_message Failed to create message from record Impossible de créer le message vocal diff --git a/Linphone/model/chat/message/content/ChatMessageContentModel.cpp b/Linphone/model/chat/message/content/ChatMessageContentModel.cpp index f2d4d1acb..d598b5d70 100644 --- a/Linphone/model/chat/message/content/ChatMessageContentModel.cpp +++ b/Linphone/model/chat/message/content/ChatMessageContentModel.cpp @@ -57,6 +57,10 @@ ChatMessageContentModel::~ChatMessageContentModel() { mustBeInLinphoneThread("~" + getClassName()); } +std::shared_ptr ChatMessageContentModel::getChatMessageModel() const { + return mChatMessageModel; +} + // Create a thumbnail from the first content that have a file void ChatMessageContentModel::createThumbnail() { auto path = Utils::coreStringToAppString(mContent->getFilePath()); diff --git a/Linphone/model/chat/message/content/ChatMessageContentModel.hpp b/Linphone/model/chat/message/content/ChatMessageContentModel.hpp index b552f536f..2df57d222 100644 --- a/Linphone/model/chat/message/content/ChatMessageContentModel.hpp +++ b/Linphone/model/chat/message/content/ChatMessageContentModel.hpp @@ -43,6 +43,7 @@ public: void setThumbnail(const QString &data); void setWasDownloaded(bool wasDownloaded); + std::shared_ptr getChatMessageModel() const; void createThumbnail(); void removeDownloadedFile(QString filePath); diff --git a/Linphone/model/tool/ToolModel.cpp b/Linphone/model/tool/ToolModel.cpp index 9e654721a..bc5dcc714 100644 --- a/Linphone/model/tool/ToolModel.cpp +++ b/Linphone/model/tool/ToolModel.cpp @@ -131,7 +131,21 @@ QString ToolModel::getDisplayName(QString address) { return nameSplitted.join(" "); } +QString ToolModel::boldTextPart(const QString &text, const QString ®ex) { + int regexIndex = text.indexOf(regex, 0, Qt::CaseInsensitive); + if (regex.isEmpty() || regexIndex == -1) return text; + QString result; + QStringList splittedText = text.split(regex, Qt::KeepEmptyParts, Qt::CaseInsensitive); + for (int i = 0; i < splittedText.size() - 1; ++i) { + result.append(splittedText[i]); + result.append("" + regex + ""); + } + if (splittedText.size() > 0) result.append(splittedText[splittedText.size() - 1]); + return result; +} + QString ToolModel::encodeTextToQmlRichFormat(const QString &text, + const QString &textPartToBold, const QVariantMap &options, std::shared_ptr chatRoom) { QStringList formattedText; @@ -230,7 +244,11 @@ QString ToolModel::encodeTextToQmlRichFormat(const QString &text, } } } - return "

" + formattedText.join(""); + QString finalText = formattedText.join(""); + if (!textPartToBold.isEmpty()) { + finalText = boldTextPart(finalText, textPartToBold); + } + return finalText; } std::shared_ptr ToolModel::findFriendByAddress(const QString &address) { diff --git a/Linphone/model/tool/ToolModel.hpp b/Linphone/model/tool/ToolModel.hpp index 6cc2924fa..0e84937eb 100644 --- a/Linphone/model/tool/ToolModel.hpp +++ b/Linphone/model/tool/ToolModel.hpp @@ -50,9 +50,11 @@ public: static QString getDisplayName(const std::shared_ptr &address); static QString getDisplayName(QString address); + static QString boldTextPart(const QString &text, const QString ®ex); static QString encodeTextToQmlRichFormat(const QString &text, - const QVariantMap &options, - std::shared_ptr chatRoom); + const QString &textPartToBold = QString(), + const QVariantMap &options = QVariantMap(), + std::shared_ptr chatRoom = nullptr); static std::shared_ptr findFriendByAddress(const QString &address); static std::shared_ptr diff --git a/Linphone/tool/Utils.cpp b/Linphone/tool/Utils.cpp index b62ec8dd7..489f473e0 100644 --- a/Linphone/tool/Utils.cpp +++ b/Linphone/tool/Utils.cpp @@ -1866,7 +1866,10 @@ QString Utils::getPresenceStatus(LinphoneEnums::Presence presence) { return presenceStatus; } -VariantObject *Utils::encodeTextToQmlRichFormat(const QString &text, const QVariantMap &options, ChatGui *chat) { +VariantObject *Utils::encodeTextToQmlRichFormat(const QString &text, + const QString &textPartToBold, + const QVariantMap &options, + ChatGui *chat) { /*QString images; QStringList imageFormat; for(auto format : QImageReader::supportedImageFormats()) @@ -1875,99 +1878,10 @@ VariantObject *Utils::encodeTextToQmlRichFormat(const QString &text, const QVari VariantObject *data = new VariantObject("encodeTextToQmlRichFormat"); if (!data) return nullptr; auto primaryColor = getDefaultStyleColor("info_500_main"); - data->makeRequest([text, options, chat, primaryColor] { - QStringList formattedText; - bool lastWasUrl = false; - - if (options.contains("noLink") && options["noLink"].toBool()) { - formattedText.append(encodeEmojiToQmlRichFormat(text)); - } else { - - auto iriParsed = UriTools::parseIri(text); - - for (int i = 0; i < iriParsed.size(); ++i) { - QString iri = iriParsed[i] - .second.replace('&', "&") - .replace('<', "\u2063<") - .replace('>', "\u2063>") - .replace('"', """) - .replace('\'', "'"); - if (!iriParsed[i].first) { - if (lastWasUrl) { - lastWasUrl = false; - if (iri.front() != ' ') iri.push_front(' '); - } - formattedText.append(encodeEmojiToQmlRichFormat(iri)); - } else { - QString uri = - iriParsed[i].second.left(3) == "www" ? "http://" + iriParsed[i].second : iriParsed[i].second; - /* TODO : preview from link - int extIndex = iriParsed[i].second.lastIndexOf('.'); - QString ext; - if( extIndex >= 0) - ext = iriParsed[i].second.mid(extIndex+1).toUpper(); - if(imageFormat.contains(ext.toLatin1())){// imagesHeight is not used because of bugs on display - (blank image if set without width) images += ""+uri+""; - }else{ - */ - formattedText.append("" + iri + - ""); - lastWasUrl = true; - /*}*/ - } - } - } - if (lastWasUrl && formattedText.last().back() != ' ') { - formattedText.push_back(" "); - } - if (chat && chat->mCore) { - auto participants = chat->mCore->getParticipants(); - auto mentionsParsed = UriTools::parseMention(formattedText.join("")); - formattedText.clear(); - - for (int i = 0; i < mentionsParsed.size(); ++i) { - QString mention = mentionsParsed[i].second; - - if (mentionsParsed[i].first) { - QString mentions = mentionsParsed[i].second; - QStringList finalMentions; - QStringList parts = mentions.split(" "); - for (auto part : parts) { - if (part.startsWith("@")) { // mention - QString username = part; - username.removeFirst(); - auto it = std::find_if( - participants.begin(), participants.end(), - [username](QSharedPointer p) { return username == p->getUsername(); }); - if (it != participants.end()) { - auto foundParticipant = participants.at(std::distance(participants.begin(), it)); - auto address = foundParticipant->getSipAddress(); - auto isFriend = ToolModel::findFriendByAddress(address); - if (isFriend) - part = "@" + Utils::coreStringToAppString(isFriend->getAddress()->getDisplayName()); - QString participantLink = "" + part + ""; - finalMentions.append(participantLink); - } else { - finalMentions.append(part); - } - } else { - finalMentions.append(part); - } - } - formattedText.push_back(finalMentions.join(" ")); - } else { - formattedText.push_back(mentionsParsed[i].second); - } - } - } - return "

" + formattedText.join(""); + data->makeRequest([text, options, chat, primaryColor, textPartToBold] { + auto chatroom = + chat && chat->mCore && chat->mCore->getModel() ? chat->mCore->getModel()->getMonitor() : nullptr; + return ToolModel::encodeTextToQmlRichFormat(text, textPartToBold, options, chatroom); }); data->requestValue(); return data; diff --git a/Linphone/tool/Utils.hpp b/Linphone/tool/Utils.hpp index 460a1b966..8dfcc798c 100644 --- a/Linphone/tool/Utils.hpp +++ b/Linphone/tool/Utils.hpp @@ -143,10 +143,10 @@ public: Q_INVOKABLE static void useFetchConfig(const QString &configUrl); Q_INVOKABLE void playDtmf(const QString &dtmf); Q_INVOKABLE bool isInteger(const QString &text); - Q_INVOKABLE QString boldTextPart(const QString &text, const QString ®ex); + Q_INVOKABLE static QString boldTextPart(const QString &text, const QString ®ex); Q_INVOKABLE static QString getFileChecksum(const QString &filePath); - Q_INVOKABLE QList append(const QList a, const QList b); - Q_INVOKABLE QString getAddressToDisplay(QVariantList addressList, QString filter, QString defaultAddress); + Q_INVOKABLE static QList append(const QList a, const QList b); + Q_INVOKABLE static QString getAddressToDisplay(QVariantList addressList, QString filter, QString defaultAddress); Q_INVOKABLE static QColor getPresenceColor(LinphoneEnums::Presence presence); Q_INVOKABLE static QUrl getPresenceIcon(LinphoneEnums::Presence presence); Q_INVOKABLE static QString getPresenceStatus(LinphoneEnums::Presence presence); @@ -156,8 +156,10 @@ public: Q_INVOKABLE static VariantObject *createGroupChat(QString subject, QStringList participantAddresses); Q_INVOKABLE static void openChat(ChatGui *chat); Q_INVOKABLE static bool isEmptyMessage(QString message); - Q_INVOKABLE static VariantObject * - encodeTextToQmlRichFormat(const QString &text, const QVariantMap &options = QVariantMap(), ChatGui *chat = nullptr); + Q_INVOKABLE static VariantObject *encodeTextToQmlRichFormat(const QString &text, + const QString &textPartToBold = QString(), + const QVariantMap &options = QVariantMap(), + ChatGui *chat = nullptr); Q_INVOKABLE static QString encodeEmojiToQmlRichFormat(const QString &body); Q_INVOKABLE static bool isOnlyEmojis(const QString &text); Q_INVOKABLE static void openContactAtAddress(const QString &address); diff --git a/Linphone/view/Control/Display/Chat/ChatTextContent.qml b/Linphone/view/Control/Display/Chat/ChatTextContent.qml index d592d87a6..2c3ae7855 100644 --- a/Linphone/view/Control/Display/Chat/ChatTextContent.qml +++ b/Linphone/view/Control/Display/Chat/ChatTextContent.qml @@ -26,9 +26,10 @@ TextEdit { readOnly: true selectByMouse: true - text: searchedTextPart !== "" - ? UtilsCpp.boldTextPart(contentGui.core.richFormatText, searchedTextPart) - : contentGui.core.richFormatText + text: contentGui.core.richFormatText + onSearchedTextPartChanged: { + contentGui.core.setSearchedTextPart(searchedTextPart) + } textFormat: Text.RichText // To supports links and imgs. wrapMode: TextEdit.Wrap