Fix custom emojis being visible in the sticker selector
This commit is contained in:
@@ -4,17 +4,27 @@
|
|||||||
#include "emoticonfiltermodel.h"
|
#include "emoticonfiltermodel.h"
|
||||||
|
|
||||||
#include "accountemoticonmodel.h"
|
#include "accountemoticonmodel.h"
|
||||||
|
#include "stickermodel.h"
|
||||||
|
|
||||||
EmoticonFilterModel::EmoticonFilterModel(QObject *parent)
|
EmoticonFilterModel::EmoticonFilterModel(QObject *parent)
|
||||||
: QSortFilterProxyModel(parent)
|
: QSortFilterProxyModel(parent)
|
||||||
{
|
{
|
||||||
|
connect(this, &EmoticonFilterModel::sourceModelChanged, this, [this]() {
|
||||||
|
if (dynamic_cast<StickerModel *>(sourceModel())) {
|
||||||
|
m_stickerRole = StickerModel::IsStickerRole;
|
||||||
|
m_emojiRole = StickerModel::IsEmojiRole;
|
||||||
|
} else {
|
||||||
|
m_stickerRole = AccountEmoticonModel::IsStickerRole;
|
||||||
|
m_emojiRole = AccountEmoticonModel::IsEmojiRole;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmoticonFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
bool EmoticonFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(sourceParent);
|
Q_UNUSED(sourceParent);
|
||||||
auto stickerUsage = sourceModel()->data(sourceModel()->index(sourceRow, 0), AccountEmoticonModel::IsStickerRole).toBool();
|
auto stickerUsage = sourceModel()->data(sourceModel()->index(sourceRow, 0), m_stickerRole).toBool();
|
||||||
auto emojiUsage = sourceModel()->data(sourceModel()->index(sourceRow, 0), AccountEmoticonModel::IsEmojiRole).toBool();
|
auto emojiUsage = sourceModel()->data(sourceModel()->index(sourceRow, 0), m_emojiRole).toBool();
|
||||||
return (stickerUsage && m_showStickers) || (emojiUsage && m_showEmojis);
|
return (stickerUsage && m_showStickers) || (emojiUsage && m_showEmojis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,4 +46,6 @@ Q_SIGNALS:
|
|||||||
private:
|
private:
|
||||||
bool m_showStickers = false;
|
bool m_showStickers = false;
|
||||||
bool m_showEmojis = false;
|
bool m_showEmojis = false;
|
||||||
|
int m_stickerRole = 0;
|
||||||
|
int m_emojiRole = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ ImagePacksModel::ImagePacksModel(QObject *parent)
|
|||||||
|
|
||||||
int ImagePacksModel::rowCount(const QModelIndex &index) const
|
int ImagePacksModel::rowCount(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(index);
|
||||||
return m_events.count();
|
return m_events.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,16 +82,20 @@ void ImagePacksModel::reloadImages()
|
|||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_events.clear();
|
m_events.clear();
|
||||||
|
|
||||||
|
// Load emoticons from the account data
|
||||||
if (m_room->connection()->hasAccountData("im.ponies.user_emotes"_ls)) {
|
if (m_room->connection()->hasAccountData("im.ponies.user_emotes"_ls)) {
|
||||||
auto json = m_room->connection()->accountData("im.ponies.user_emotes"_ls)->contentJson();
|
auto json = m_room->connection()->accountData("im.ponies.user_emotes"_ls)->contentJson();
|
||||||
json["pack"] = QJsonObject{
|
json["pack"] = QJsonObject{
|
||||||
{"display_name", i18n("Own Stickers")},
|
{"display_name", m_showStickers ? i18nc("As in 'The user's own Stickers'", "Own Stickers") : i18nc("As in 'The user's own emojis", "Own Emojis")},
|
||||||
};
|
};
|
||||||
const auto &content = ImagePackEventContent(json);
|
const auto &content = ImagePackEventContent(json);
|
||||||
if (!content.images.isEmpty()) {
|
if (!content.images.isEmpty()) {
|
||||||
m_events += ImagePackEventContent(json);
|
m_events += ImagePackEventContent(json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load emoticons from the saved rooms
|
||||||
const auto &accountData = m_room->connection()->accountData("im.ponies.emote_rooms"_ls);
|
const auto &accountData = m_room->connection()->accountData("im.ponies.emote_rooms"_ls);
|
||||||
if (accountData) {
|
if (accountData) {
|
||||||
const auto &rooms = accountData->contentJson()["rooms"_ls].toObject();
|
const auto &rooms = accountData->contentJson()["rooms"_ls].toObject();
|
||||||
@@ -104,11 +109,10 @@ void ImagePacksModel::reloadImages()
|
|||||||
#ifdef QUOTIENT_07
|
#ifdef QUOTIENT_07
|
||||||
if (const auto &pack = stickerRoom->currentState().get<ImagePackEvent>(packKey)) {
|
if (const auto &pack = stickerRoom->currentState().get<ImagePackEvent>(packKey)) {
|
||||||
const auto packContent = pack->content();
|
const auto packContent = pack->content();
|
||||||
if (packContent.pack.has_value()) {
|
if ((!packContent.pack || !packContent.pack->usage || (packContent.pack->usage->contains("emoticon") && showEmoticons())
|
||||||
if (!packContent.pack->usage || (packContent.pack->usage->contains("emoticon") && showEmoticons())
|
|| (packContent.pack->usage->contains("sticker") && showStickers()))
|
||||||
|| (packContent.pack->usage->contains("sticker") && showStickers())) {
|
&& !packContent.images.isEmpty()) {
|
||||||
m_events += packContent;
|
m_events += packContent;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -116,6 +120,8 @@ void ImagePacksModel::reloadImages()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef QUOTIENT_07
|
#ifdef QUOTIENT_07
|
||||||
|
|
||||||
|
// Load emoticons from the current room
|
||||||
auto events = m_room->currentState().eventsOfType("im.ponies.room_emotes");
|
auto events = m_room->currentState().eventsOfType("im.ponies.room_emotes");
|
||||||
for (const auto &event : events) {
|
for (const auto &event : events) {
|
||||||
auto packContent = eventCast<const ImagePackEvent>(event)->content();
|
auto packContent = eventCast<const ImagePackEvent>(event)->content();
|
||||||
|
|||||||
@@ -14,30 +14,45 @@ StickerModel::StickerModel(QObject *parent)
|
|||||||
|
|
||||||
int StickerModel::rowCount(const QModelIndex &index) const
|
int StickerModel::rowCount(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(index);
|
||||||
return m_images.size();
|
return m_images.size();
|
||||||
}
|
}
|
||||||
QVariant StickerModel::data(const QModelIndex &index, int role) const
|
QVariant StickerModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
const auto &row = index.row();
|
const auto &row = index.row();
|
||||||
const auto &image = m_images[row];
|
const auto &image = m_images[row];
|
||||||
if (role == Url) {
|
if (role == UrlRole) {
|
||||||
#ifdef QUOTIENT_07
|
#ifdef QUOTIENT_07
|
||||||
return m_room->connection()->makeMediaUrl(image.url);
|
return m_room->connection()->makeMediaUrl(image.url);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (role == Body) {
|
if (role == BodyRole) {
|
||||||
if (image.body) {
|
if (image.body) {
|
||||||
return *image.body;
|
return *image.body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (role == IsStickerRole) {
|
||||||
|
if (image.usage) {
|
||||||
|
return image.usage->isEmpty() || image.usage->contains("sticker"_ls);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (role == IsEmojiRole) {
|
||||||
|
if (image.usage) {
|
||||||
|
return image.usage->isEmpty() || image.usage->contains("emoticon"_ls);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> StickerModel::roleNames() const
|
QHash<int, QByteArray> StickerModel::roleNames() const
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
{StickerModel::Url, "url"},
|
{UrlRole, "url"},
|
||||||
{StickerModel::Body, "body"},
|
{BodyRole, "body"},
|
||||||
|
{IsStickerRole, "isSticker"},
|
||||||
|
{IsEmojiRole, "isEmoji"},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
ImagePacksModel *StickerModel::model() const
|
ImagePacksModel *StickerModel::model() const
|
||||||
|
|||||||
@@ -47,8 +47,10 @@ public:
|
|||||||
* @brief Defines the model roles.
|
* @brief Defines the model roles.
|
||||||
*/
|
*/
|
||||||
enum Roles {
|
enum Roles {
|
||||||
Url = Qt::UserRole + 1, /**< The source mxc URL for the image. */
|
UrlRole = Qt::UserRole + 1, /**< The source mxc URL for the image. */
|
||||||
Body, /**< The image caption, if any. */
|
BodyRole, /**< The image caption, if any. */
|
||||||
|
IsStickerRole, /**< Whether this emoticon is a sticker. */
|
||||||
|
IsEmojiRole, /**< Whether this emoticon is an emoji. */
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit StickerModel(QObject *parent = nullptr);
|
explicit StickerModel(QObject *parent = nullptr);
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ ColumnLayout {
|
|||||||
EmojiGrid {
|
EmojiGrid {
|
||||||
id: emojiGrid
|
id: emojiGrid
|
||||||
targetIconSize: root.currentCategory === EmojiModel.Custom ? Kirigami.Units.gridUnit * 3 : root.categoryIconSize // Custom emojis are bigger
|
targetIconSize: root.currentCategory === EmojiModel.Custom ? Kirigami.Units.gridUnit * 3 : root.categoryIconSize // Custom emojis are bigger
|
||||||
model: root.selectedType === 1 ? stickerModel : searchField.text.length === 0 ? EmojiModel.emojis(root.currentCategory) : (root.includeCustom ? EmojiModel.filterModel(searchField.text, false) : EmojiModel.filterModelNoCustom(searchField.text, false))
|
model: root.selectedType === 1 ? emoticonFilterModel : searchField.text.length === 0 ? EmojiModel.emojis(root.currentCategory) : (root.includeCustom ? EmojiModel.filterModel(searchField.text, false) : EmojiModel.filterModelNoCustom(searchField.text, false))
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
withCustom: root.includeCustom
|
withCustom: root.includeCustom
|
||||||
@@ -115,7 +115,7 @@ ColumnLayout {
|
|||||||
header: categories
|
header: categories
|
||||||
Keys.forwardTo: searchField
|
Keys.forwardTo: searchField
|
||||||
stickers: root.selectedType === 1
|
stickers: root.selectedType === 1
|
||||||
onStickerChosen: stickerModel.postSticker(index)
|
onStickerChosen: stickerModel.postSticker(emoticonFilterModel.mapToSource(emoticonFilterModel.index(index, 0)).row)
|
||||||
}
|
}
|
||||||
|
|
||||||
Kirigami.Separator {
|
Kirigami.Separator {
|
||||||
@@ -163,6 +163,12 @@ ColumnLayout {
|
|||||||
room: currentRoom
|
room: currentRoom
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EmoticonFilterModel {
|
||||||
|
id: emoticonFilterModel
|
||||||
|
sourceModel: stickerModel
|
||||||
|
showStickers: true
|
||||||
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: emojiDelegate
|
id: emojiDelegate
|
||||||
Kirigami.NavigationTabButton {
|
Kirigami.NavigationTabButton {
|
||||||
|
|||||||
Reference in New Issue
Block a user