Compare commits

...

3 Commits

Author SHA1 Message Date
Charlotte 1a1247da7a
Merge 2fe1ea6c7f into dbc3a9fbb8 2024-06-08 10:30:58 +01:00
Tulir Asokan dbc3a9fbb8 Don't prompt for giphy api key by default 2024-06-05 13:02:34 +03:00
Charlotte 🦝 Delenk 2fe1ea6c7f
Make Element Desktop send telegram sticker info
Element Desktop removes additional properties in the sticker info, but
not the media info. Element Android removes them in both currently. This
commit moves the net.maunium.telegram.sticker property to the media
info. This can be combined with a change to mautrix-telegram that
bridges telegram-imported matrix stickers to matrix stickers.
2022-08-23 08:12:07 +01:00
5 changed files with 12 additions and 18 deletions

View File

@ -55,23 +55,10 @@ async def load_config(path: str) -> None:
config = json.load(config_file) config = json.load(config_file)
homeserver_url = config["homeserver"] homeserver_url = config["homeserver"]
access_token = config["access_token"] access_token = config["access_token"]
try:
giphy_api_key = config["giphy_api_key"]
giphy_mxc_prefix = config["giphy_mxc_prefix"]
except KeyError:
# these two are not mandatory, assume GIF search is disabled
print("Giphy related parameters not found in the config file.")
except FileNotFoundError: except FileNotFoundError:
print("Matrix config file not found. Please enter your homeserver and access token.") print("Matrix config file not found. Please enter your homeserver and access token.")
homeserver_url = input("Homeserver URL: ") homeserver_url = input("Homeserver URL: ")
access_token = input("Access token: ") access_token = input("Access token: ")
print("If you want to enable GIF search, enter your giphy API key. Otherwise, leave it empty.")
giphy_api_key = input("Giphy API key: ").strip()
giphy_mxc_prefix = "mxc://giphy.mau.dev/"
if giphy_api_key:
print("If you want to self-host the matrix->giphy proxy, enter the mxc URI prefix here")
print("Defaults to mxc://giphy.mau.dev/ if left empty.")
giphy_mxc_prefix = input("Giphy MXC prefix: ").strip() or giphy_mxc_prefix
whoami_url = URL(homeserver_url) / "_matrix" / "client" / "r0" / "account" / "whoami" whoami_url = URL(homeserver_url) / "_matrix" / "client" / "r0" / "account" / "whoami"
if whoami_url.scheme not in ("https", "http"): if whoami_url.scheme not in ("https", "http"):
whoami_url = whoami_url.with_scheme("https") whoami_url = whoami_url.with_scheme("https")

View File

@ -45,7 +45,7 @@ def add_meta(document: Document, info: matrix.StickerInfo, pack: StickerSetFull)
if isinstance(attr, DocumentAttributeSticker): if isinstance(attr, DocumentAttributeSticker):
info["body"] = attr.alt info["body"] = attr.alt
info["id"] = f"tg-{document.id}" info["id"] = f"tg-{document.id}"
info["net.maunium.telegram.sticker"] = { info["info"]["net.maunium.telegram.sticker"] = {
"pack": { "pack": {
"id": str(pack.set.id), "id": str(pack.set.id),
"short_name": pack.set.short_name, "short_name": pack.set.short_name,
@ -73,7 +73,7 @@ async def reupload_pack(client: TelegramClient, pack: StickerSetFull, output_dir
try: try:
with util.open_utf8(pack_path) as pack_file: with util.open_utf8(pack_path) as pack_file:
existing_pack = json.load(pack_file) existing_pack = json.load(pack_file)
already_uploaded = {int(sticker["net.maunium.telegram.sticker"]["id"]): sticker already_uploaded = {int(sticker["info"]["net.maunium.telegram.sticker"]["id"]): sticker
for sticker in existing_pack["stickers"]} for sticker in existing_pack["stickers"]}
print(f"Found {len(already_uploaded)} already reuploaded stickers") print(f"Found {len(already_uploaded)} already reuploaded stickers")
except FileNotFoundError: except FileNotFoundError:
@ -97,7 +97,7 @@ async def reupload_pack(client: TelegramClient, pack: StickerSetFull, output_dir
# If there was no sticker metadata, use the first emoji we find # If there was no sticker metadata, use the first emoji we find
if doc["body"] == "": if doc["body"] == "":
doc["body"] = sticker.emoticon doc["body"] = sticker.emoticon
doc["net.maunium.telegram.sticker"]["emoticons"].append(sticker.emoticon) doc["info"]["net.maunium.telegram.sticker"]["emoticons"].append(sticker.emoticon)
with util.open_utf8(pack_path, "w") as pack_file: with util.open_utf8(pack_path, "w") as pack_file:
json.dump({ json.dump({

View File

@ -3,7 +3,7 @@ import * as widgetAPI from "./widget-api.js";
import {SearchBox} from "./search-box.js"; import {SearchBox} from "./search-box.js";
const GIPHY_SEARCH_DEBOUNCE = 1000 const GIPHY_SEARCH_DEBOUNCE = 1000
let GIPHY_API_KEY = "" let GIPHY_API_KEY = "HQku8974Uq5MZn3MZns46kXn2R4GDm75"
let GIPHY_MXC_PREFIX = "mxc://giphy.mau.dev/" let GIPHY_MXC_PREFIX = "mxc://giphy.mau.dev/"
export function giphyIsEnabled() { export function giphyIsEnabled() {

View File

@ -166,7 +166,9 @@ class App extends Component {
} }
const indexData = await indexRes.json() const indexData = await indexRes.json()
HOMESERVER_URL = indexData.homeserver_url || HOMESERVER_URL HOMESERVER_URL = indexData.homeserver_url || HOMESERVER_URL
if (indexData.giphy_api_key !== undefined) {
setGiphyAPIKey(indexData.giphy_api_key, indexData.giphy_mxc_prefix) setGiphyAPIKey(indexData.giphy_api_key, indexData.giphy_mxc_prefix)
}
// TODO only load pack metadata when scrolled into view? // TODO only load pack metadata when scrolled into view?
for (const packFile of indexData.packs) { for (const packFile of indexData.packs) {
let packRes let packRes

View File

@ -47,6 +47,11 @@ window.onmessage = event => {
} }
export function sendSticker(content) { export function sendSticker(content) {
if (content["info"]["net.maunium.telegram.sticker"] === undefined) {
// Old sticker, move the property to its new location
content["info"]["net.maunium.telegram.sticker"] = content["net.maunium.telegram.sticker"];
delete content["net.maunium.telegram.sticker"];
}
const data = { const data = {
content: { ...content }, content: { ...content },
// `name` is for Element Web (and also the spec) // `name` is for Element Web (and also the spec)