From 109913c9ca44ffcaa027ef0608398d2f985f0a7e Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Thu, 20 May 2021 23:41:55 +0200 Subject: [PATCH] Introduce possibility to display stickers as emojis --- qml/components/messageContent/MessageSticker.qml | 12 +++++++++--- qml/js/twemoji.js | 4 ++++ qml/pages/AboutPage.qml | 2 +- qml/pages/SettingsPage.qml | 14 ++++++++++++++ rlottie | 2 +- rpm/harbour-fernschreiber.spec | 4 +--- rpm/harbour-fernschreiber.yaml | 4 ++-- src/appsettings.cpp | 15 +++++++++++++++ src/appsettings.h | 5 +++++ src/tdlibwrapper.cpp | 2 +- translations/harbour-fernschreiber-de.ts | 8 ++++++++ translations/harbour-fernschreiber-en.ts | 8 ++++++++ translations/harbour-fernschreiber-es.ts | 8 ++++++++ translations/harbour-fernschreiber-fi.ts | 8 ++++++++ translations/harbour-fernschreiber-hu.ts | 8 ++++++++ translations/harbour-fernschreiber-it.ts | 8 ++++++++ translations/harbour-fernschreiber-pl.ts | 8 ++++++++ translations/harbour-fernschreiber-ru.ts | 8 ++++++++ translations/harbour-fernschreiber-sk.ts | 8 ++++++++ translations/harbour-fernschreiber-sv.ts | 8 ++++++++ translations/harbour-fernschreiber-zh_CN.ts | 8 ++++++++ translations/harbour-fernschreiber.ts | 8 ++++++++ 22 files changed, 149 insertions(+), 11 deletions(-) diff --git a/qml/components/messageContent/MessageSticker.qml b/qml/components/messageContent/MessageSticker.qml index 77fbe4d..773185a 100644 --- a/qml/components/messageContent/MessageSticker.qml +++ b/qml/components/messageContent/MessageSticker.qml @@ -20,11 +20,13 @@ import QtQuick 2.6 import Sailfish.Silica 1.0 import WerkWolf.Fernschreiber 1.0 import "../" +import "../../js/twemoji.js" as Emoji MessageContentBase { id: thisItem readonly property var stickerData: messageListItem ? messageListItem.myMessage.content.sticker : overlayFlickable.overlayMessage.content.sticker; + readonly property bool asEmoji: appSettings.showStickersAsEmojis readonly property bool animated: stickerData.is_animated && appSettings.animateStickers readonly property bool stickerVisible: staticStickerLoader.item ? staticStickerLoader.item.visible : animatedStickerLoader.item ? animatedStickerLoader.item.visible : false @@ -52,7 +54,7 @@ MessageContentBase { Loader { id: animatedStickerLoader anchors.fill: parent - active: animated + active: animated && !asEmoji sourceComponent: Component { AnimatedImage { id: animatedSticker @@ -70,12 +72,16 @@ MessageContentBase { Loader { id: staticStickerLoader anchors.fill: parent - active: !animated + active: !animated || asEmoji sourceComponent: Component { Image { id: staticSticker anchors.fill: parent - source: file.path + source: asEmoji ? Emoji.getEmojiPath(stickerData.emoji) : file.path + sourceSize { + width: width + height: height + } fillMode: Image.PreserveAspectFit autoTransform: true asynchronous: true diff --git a/qml/js/twemoji.js b/qml/js/twemoji.js index 3255d3c..1242026 100644 --- a/qml/js/twemoji.js +++ b/qml/js/twemoji.js @@ -38,6 +38,10 @@ function toCodePoint(unicodeSurrogates) { return r.join('-'); } +function getEmojiPath(str) { + return basePath + toCodePoint(str.indexOf(U200D) < 0 ? str.replace(UFE0Fg, '') : str) + '.svg'; +} + function emojify(str, emojiSize) { return String(str).replace(re, function (rawText) { var iconId = toCodePoint(rawText.indexOf(U200D) < 0 ? diff --git a/qml/pages/AboutPage.qml b/qml/pages/AboutPage.qml index be72dd1..7f0e6cb 100644 --- a/qml/pages/AboutPage.qml +++ b/qml/pages/AboutPage.qml @@ -59,7 +59,7 @@ Page { } Label { - text: "Fernschreiber 0.8.2" + text: "Fernschreiber 0.9" horizontalAlignment: Text.AlignHCenter font.pixelSize: Theme.fontSizeExtraLarge anchors { diff --git a/qml/pages/SettingsPage.qml b/qml/pages/SettingsPage.qml index 98fb48b..2796198 100644 --- a/qml/pages/SettingsPage.qml +++ b/qml/pages/SettingsPage.qml @@ -689,6 +689,18 @@ Page { readonly property real columnWidth: width/columns + TextSwitch { + id: stickersAsEmojisTextSwitch + width: parent.columnWidth + checked: appSettings.showStickersAsEmojis + text: qsTr("Show stickers as emojis") + description: qsTr("Only display emojis instead of the actual stickers") + automaticCheck: false + onClicked: { + appSettings.showStickersAsEmojis = !checked + } + } + TextSwitch { width: parent.columnWidth checked: appSettings.showStickersAsImages @@ -698,6 +710,7 @@ Page { onClicked: { appSettings.showStickersAsImages = !checked } + enabled: !stickersAsEmojisTextSwitch.checked } TextSwitch { @@ -708,6 +721,7 @@ Page { onClicked: { appSettings.animateStickers = !checked } + enabled: !stickersAsEmojisTextSwitch.checked } } diff --git a/rlottie b/rlottie index bf3d272..7c5b40c 160000 --- a/rlottie +++ b/rlottie @@ -1 +1 @@ -Subproject commit bf3d272df3916a0c34575ac8286cb0fe672fd0d4 +Subproject commit 7c5b40cbb87422e5a74691d4d9907948c8c0d479 diff --git a/rpm/harbour-fernschreiber.spec b/rpm/harbour-fernschreiber.spec index 605c40f..71bde3c 100644 --- a/rpm/harbour-fernschreiber.spec +++ b/rpm/harbour-fernschreiber.spec @@ -6,12 +6,10 @@ Name: harbour-fernschreiber # >> macros -%define __provides_exclude_from ^%{_datadir}/.*$ -%define __requires_exclude ^libtdjson.*$ # << macros Summary: Fernschreiber is a Telegram client for Sailfish OS -Version: 0.8.2 +Version: 0.9 Release: 1 Group: Qt/Qt License: LICENSE diff --git a/rpm/harbour-fernschreiber.yaml b/rpm/harbour-fernschreiber.yaml index e438587..689fdf2 100644 --- a/rpm/harbour-fernschreiber.yaml +++ b/rpm/harbour-fernschreiber.yaml @@ -1,7 +1,7 @@ Name: harbour-fernschreiber Summary: Fernschreiber is a Telegram client for Sailfish OS -Version: 0.8.1 -Release: 2 +Version: 0.9 +Release: 1 # The contents of the Group field should be one of the groups listed here: # https://github.com/mer-tools/spectacle/blob/master/data/GROUPS Group: Qt/Qt diff --git a/src/appsettings.cpp b/src/appsettings.cpp index 5da76e1..50d4e34 100644 --- a/src/appsettings.cpp +++ b/src/appsettings.cpp @@ -24,6 +24,7 @@ namespace { const QString KEY_SEND_BY_ENTER("sendByEnter"); const QString KEY_FOCUS_TEXTAREA_AFTER_SEND("focusTextAreaAfterSend"); const QString KEY_USE_OPEN_WITH("useOpenWith"); + const QString KEY_SHOW_STICKERS_AS_EMOJIS("showStickersAsEmojis"); const QString KEY_SHOW_STICKERS_AS_IMAGES("showStickersAsImages"); const QString KEY_ANIMATE_STICKERS("animateStickers"); const QString KEY_NOTIFICATION_TURNS_DISPLAY_ON("notificationTurnsDisplayOn"); @@ -83,6 +84,20 @@ void AppSettings::setUseOpenWith(bool useOpenWith) } } +bool AppSettings::showStickersAsEmojis() const +{ + return settings.value(KEY_SHOW_STICKERS_AS_EMOJIS, false).toBool(); +} + +void AppSettings::setShowStickersAsEmojis(bool showAsEmojis) +{ + if (showStickersAsEmojis() != showAsEmojis) { + LOG(KEY_SHOW_STICKERS_AS_EMOJIS << showAsEmojis); + settings.setValue(KEY_SHOW_STICKERS_AS_EMOJIS, showAsEmojis); + emit showStickersAsEmojisChanged(); + } +} + bool AppSettings::showStickersAsImages() const { return settings.value(KEY_SHOW_STICKERS_AS_IMAGES, true).toBool(); diff --git a/src/appsettings.h b/src/appsettings.h index ff14009..61febbb 100644 --- a/src/appsettings.h +++ b/src/appsettings.h @@ -26,6 +26,7 @@ class AppSettings : public QObject { Q_PROPERTY(bool sendByEnter READ getSendByEnter WRITE setSendByEnter NOTIFY sendByEnterChanged) Q_PROPERTY(bool focusTextAreaAfterSend READ getFocusTextAreaAfterSend WRITE setFocusTextAreaAfterSend NOTIFY focusTextAreaAfterSendChanged) Q_PROPERTY(bool useOpenWith READ getUseOpenWith WRITE setUseOpenWith NOTIFY useOpenWithChanged) + Q_PROPERTY(bool showStickersAsEmojis READ showStickersAsEmojis WRITE setShowStickersAsEmojis NOTIFY showStickersAsEmojisChanged) Q_PROPERTY(bool showStickersAsImages READ showStickersAsImages WRITE setShowStickersAsImages NOTIFY showStickersAsImagesChanged) Q_PROPERTY(bool animateStickers READ animateStickers WRITE setAnimateStickers NOTIFY animateStickersChanged) Q_PROPERTY(bool notificationTurnsDisplayOn READ notificationTurnsDisplayOn WRITE setNotificationTurnsDisplayOn NOTIFY notificationTurnsDisplayOnChanged) @@ -59,6 +60,9 @@ public: bool getUseOpenWith() const; void setUseOpenWith(bool useOpenWith); + bool showStickersAsEmojis() const; + void setShowStickersAsEmojis(bool showAsEmojis); + bool showStickersAsImages() const; void setShowStickersAsImages(bool showAsImages); @@ -96,6 +100,7 @@ signals: void sendByEnterChanged(); void focusTextAreaAfterSendChanged(); void useOpenWithChanged(); + void showStickersAsEmojisChanged(); void showStickersAsImagesChanged(); void animateStickersChanged(); void notificationTurnsDisplayOnChanged(); diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 612513a..6f69803 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -1853,7 +1853,7 @@ void TDLibWrapper::setInitialParameters() QSettings hardwareSettings("/etc/hw-release", QSettings::NativeFormat); initialParameters.insert("device_model", hardwareSettings.value("NAME", "Unknown Mobile Device").toString()); initialParameters.insert("system_version", QSysInfo::prettyProductName()); - initialParameters.insert("application_version", "0.8.2"); + initialParameters.insert("application_version", "0.9"); initialParameters.insert("enable_storage_optimizer", appSettings->storageOptimizer()); // initialParameters.insert("use_test_dc", true); requestObject.insert("parameters", initialParameters); diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index eba53f8..313a050 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -1717,6 +1717,14 @@ Focus text input on chat open Texteingabe fokussieren beim Öffnen eines Chats + + Show stickers as emojis + Sticker als Emojis anzeigen + + + Only display emojis instead of the actual stickers + Nur Emojis anstelle der eigentlichen Sticker anzeigen + StickerPicker diff --git a/translations/harbour-fernschreiber-en.ts b/translations/harbour-fernschreiber-en.ts index 3cac7a1..69f8bd3 100644 --- a/translations/harbour-fernschreiber-en.ts +++ b/translations/harbour-fernschreiber-en.ts @@ -1719,6 +1719,14 @@ messages Focus text input on chat open Focus text input on chat open + + Show stickers as emojis + Show stickers as emojis + + + Only display emojis instead of the actual stickers + Only display emojis instead of the actual stickers + StickerPicker diff --git a/translations/harbour-fernschreiber-es.ts b/translations/harbour-fernschreiber-es.ts index f74379d..10e930c 100644 --- a/translations/harbour-fernschreiber-es.ts +++ b/translations/harbour-fernschreiber-es.ts @@ -1717,6 +1717,14 @@ Focus text input on chat open + + Show stickers as emojis + + + + Only display emojis instead of the actual stickers + + StickerPicker diff --git a/translations/harbour-fernschreiber-fi.ts b/translations/harbour-fernschreiber-fi.ts index a6d63e7..4e85048 100644 --- a/translations/harbour-fernschreiber-fi.ts +++ b/translations/harbour-fernschreiber-fi.ts @@ -1718,6 +1718,14 @@ Focus text input on chat open + + Show stickers as emojis + + + + Only display emojis instead of the actual stickers + + StickerPicker diff --git a/translations/harbour-fernschreiber-hu.ts b/translations/harbour-fernschreiber-hu.ts index ed65417..98171fb 100644 --- a/translations/harbour-fernschreiber-hu.ts +++ b/translations/harbour-fernschreiber-hu.ts @@ -1690,6 +1690,14 @@ Focus text input on chat open + + Show stickers as emojis + + + + Only display emojis instead of the actual stickers + + StickerPicker diff --git a/translations/harbour-fernschreiber-it.ts b/translations/harbour-fernschreiber-it.ts index 97a4941..2e090fd 100644 --- a/translations/harbour-fernschreiber-it.ts +++ b/translations/harbour-fernschreiber-it.ts @@ -1717,6 +1717,14 @@ Focus text input on chat open + + Show stickers as emojis + + + + Only display emojis instead of the actual stickers + + StickerPicker diff --git a/translations/harbour-fernschreiber-pl.ts b/translations/harbour-fernschreiber-pl.ts index c652809..bb48731 100644 --- a/translations/harbour-fernschreiber-pl.ts +++ b/translations/harbour-fernschreiber-pl.ts @@ -1744,6 +1744,14 @@ Focus text input on chat open + + Show stickers as emojis + + + + Only display emojis instead of the actual stickers + + StickerPicker diff --git a/translations/harbour-fernschreiber-ru.ts b/translations/harbour-fernschreiber-ru.ts index 65f20d4..7e88823 100644 --- a/translations/harbour-fernschreiber-ru.ts +++ b/translations/harbour-fernschreiber-ru.ts @@ -1747,6 +1747,14 @@ Focus text input on chat open + + Show stickers as emojis + + + + Only display emojis instead of the actual stickers + + StickerPicker diff --git a/translations/harbour-fernschreiber-sk.ts b/translations/harbour-fernschreiber-sk.ts index ddccf38..115b94b 100644 --- a/translations/harbour-fernschreiber-sk.ts +++ b/translations/harbour-fernschreiber-sk.ts @@ -1744,6 +1744,14 @@ Focus text input on chat open + + Show stickers as emojis + + + + Only display emojis instead of the actual stickers + + StickerPicker diff --git a/translations/harbour-fernschreiber-sv.ts b/translations/harbour-fernschreiber-sv.ts index 11f4345..cd0c924 100644 --- a/translations/harbour-fernschreiber-sv.ts +++ b/translations/harbour-fernschreiber-sv.ts @@ -1717,6 +1717,14 @@ Focus text input on chat open + + Show stickers as emojis + + + + Only display emojis instead of the actual stickers + + StickerPicker diff --git a/translations/harbour-fernschreiber-zh_CN.ts b/translations/harbour-fernschreiber-zh_CN.ts index b37d4d3..e3296e0 100644 --- a/translations/harbour-fernschreiber-zh_CN.ts +++ b/translations/harbour-fernschreiber-zh_CN.ts @@ -1691,6 +1691,14 @@ Focus text input on chat open + + Show stickers as emojis + + + + Only display emojis instead of the actual stickers + + StickerPicker diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index 9c72426..3bdfb9a 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -1717,6 +1717,14 @@ Focus text input on chat open + + Show stickers as emojis + + + + Only display emojis instead of the actual stickers + + StickerPicker