Introduce possibility to display stickers as emojis

This commit is contained in:
Sebastian Wolf 2021-05-20 23:41:55 +02:00
parent cefa87767a
commit 109913c9ca
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
22 changed files with 149 additions and 11 deletions

View file

@ -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

View file

@ -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 ?

View file

@ -59,7 +59,7 @@ Page {
}
Label {
text: "Fernschreiber 0.8.2"
text: "Fernschreiber 0.9"
horizontalAlignment: Text.AlignHCenter
font.pixelSize: Theme.fontSizeExtraLarge
anchors {

View file

@ -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
}
}

@ -1 +1 @@
Subproject commit bf3d272df3916a0c34575ac8286cb0fe672fd0d4
Subproject commit 7c5b40cbb87422e5a74691d4d9907948c8c0d479

View file

@ -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

View file

@ -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

View file

@ -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();

View file

@ -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();

View file

@ -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);

View file

@ -1717,6 +1717,14 @@
<source>Focus text input on chat open</source>
<translation>Texteingabe fokussieren beim Öffnen eines Chats</translation>
</message>
<message>
<source>Show stickers as emojis</source>
<translation>Sticker als Emojis anzeigen</translation>
</message>
<message>
<source>Only display emojis instead of the actual stickers</source>
<translation>Nur Emojis anstelle der eigentlichen Sticker anzeigen</translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1719,6 +1719,14 @@ messages</numerusform>
<source>Focus text input on chat open</source>
<translation>Focus text input on chat open</translation>
</message>
<message>
<source>Show stickers as emojis</source>
<translation>Show stickers as emojis</translation>
</message>
<message>
<source>Only display emojis instead of the actual stickers</source>
<translation>Only display emojis instead of the actual stickers</translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1717,6 +1717,14 @@
<source>Focus text input on chat open</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show stickers as emojis</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Only display emojis instead of the actual stickers</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1718,6 +1718,14 @@
<source>Focus text input on chat open</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show stickers as emojis</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Only display emojis instead of the actual stickers</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1690,6 +1690,14 @@
<source>Focus text input on chat open</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show stickers as emojis</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Only display emojis instead of the actual stickers</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1717,6 +1717,14 @@
<source>Focus text input on chat open</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show stickers as emojis</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Only display emojis instead of the actual stickers</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1744,6 +1744,14 @@
<source>Focus text input on chat open</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show stickers as emojis</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Only display emojis instead of the actual stickers</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1747,6 +1747,14 @@
<source>Focus text input on chat open</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show stickers as emojis</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Only display emojis instead of the actual stickers</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1744,6 +1744,14 @@
<source>Focus text input on chat open</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show stickers as emojis</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Only display emojis instead of the actual stickers</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1717,6 +1717,14 @@
<source>Focus text input on chat open</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show stickers as emojis</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Only display emojis instead of the actual stickers</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1691,6 +1691,14 @@
<source>Focus text input on chat open</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show stickers as emojis</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Only display emojis instead of the actual stickers</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1717,6 +1717,14 @@
<source>Focus text input on chat open</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show stickers as emojis</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Only display emojis instead of the actual stickers</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>