Add an ugly custom emote completer using ~
This commit is contained in:
parent
3e8734dbd5
commit
ea6b19b307
5 changed files with 64 additions and 22 deletions
|
|
@ -3580,24 +3580,26 @@ Cache::getImagePacks(const std::string &room_id, std::optional<bool> stickers)
|
|||
auto addPack = [&infos, stickers](const mtx::events::msc2545::ImagePack &pack,
|
||||
const std::string &source_room,
|
||||
const std::string &state_key) {
|
||||
if (!pack.pack || !stickers.has_value() ||
|
||||
(stickers.value() ? pack.pack->is_sticker() : pack.pack->is_emoji())) {
|
||||
ImagePackInfo info;
|
||||
info.source_room = source_room;
|
||||
info.state_key = state_key;
|
||||
info.pack.pack = pack.pack;
|
||||
bool pack_matches = !stickers.has_value() ||
|
||||
(stickers.value() ? pack.pack->is_sticker() : pack.pack->is_emoji());
|
||||
|
||||
for (const auto &img : pack.images) {
|
||||
if (stickers.has_value() && img.second.overrides_usage() &&
|
||||
(stickers ? !img.second.is_sticker() : !img.second.is_emoji()))
|
||||
continue;
|
||||
ImagePackInfo info;
|
||||
info.source_room = source_room;
|
||||
info.state_key = state_key;
|
||||
info.pack.pack = pack.pack;
|
||||
|
||||
info.pack.images.insert(img);
|
||||
}
|
||||
for (const auto &img : pack.images) {
|
||||
if (stickers.has_value() &&
|
||||
(img.second.overrides_usage()
|
||||
? (!stickers.value() ? img.second.is_sticker() : img.second.is_emoji())
|
||||
: !pack_matches))
|
||||
continue;
|
||||
|
||||
if (!info.pack.images.empty())
|
||||
infos.push_back(std::move(info));
|
||||
info.pack.images.insert(img);
|
||||
}
|
||||
|
||||
if (!info.pack.images.empty())
|
||||
infos.push_back(std::move(info));
|
||||
};
|
||||
|
||||
// packs from account data
|
||||
|
|
|
|||
|
|
@ -56,7 +56,9 @@ CombinedImagePackModel::data(const QModelIndex &index, int role) const
|
|||
if (hasIndex(index.row(), index.column(), index.parent())) {
|
||||
switch (role) {
|
||||
case CompletionModel::CompletionRole:
|
||||
return QString::fromStdString(images[index.row()].image.url);
|
||||
return QString("<img data-mx-emoticon height=32 src=\"%1\" alt=\"%2\" title=\"%2\">")
|
||||
.arg(QString::fromStdString(images[index.row()].image.url).toHtmlEscaped(),
|
||||
images[index.row()].shortcode);
|
||||
case Roles::Url:
|
||||
return QString::fromStdString(images[index.row()].image.url);
|
||||
case CompletionModel::SearchRole:
|
||||
|
|
|
|||
|
|
@ -550,6 +550,11 @@ TimelineViewManager::completerFor(QString completerName, QString roomId)
|
|||
auto proxy = new CompletionProxyModel(stickerModel, 1, static_cast<size_t>(-1) / 4);
|
||||
stickerModel->setParent(proxy);
|
||||
return proxy;
|
||||
} else if (completerName == "customEmoji") {
|
||||
auto stickerModel = new CombinedImagePackModel(roomId.toStdString(), false);
|
||||
auto proxy = new CompletionProxyModel(stickerModel);
|
||||
stickerModel->setParent(proxy);
|
||||
return proxy;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue