aboutsummaryrefslogtreecommitdiffstats
path: root/web/widget-api.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/widget-api.js')
-rw-r--r--web/widget-api.js66
1 files changed, 0 insertions, 66 deletions
diff --git a/web/widget-api.js b/web/widget-api.js
deleted file mode 100644
index 3efca0e..0000000
--- a/web/widget-api.js
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (c) 2020 Tulir Asokan
-//
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-let widgetId = null
-
-window.onmessage = event => {
- if (!window.parent || !event.data) {
- return
- }
-
- const request = event.data
- if (!request.requestId || !request.widgetId || !request.action || request.api !== "toWidget") {
- return
- }
-
- if (widgetId) {
- if (widgetId !== request.widgetId) {
- return
- }
- } else {
- widgetId = request.widgetId
- }
-
- let response
-
- if (request.action === "visibility") {
- response = {}
- } else if (request.action === "capabilities") {
- response = { capabilities: ["m.sticker"] }
- } else {
- response = { error: { message: "Action not supported" } }
- }
-
- window.parent.postMessage({ ...request, response }, event.origin)
-}
-
-export function sendSticker(content) {
- const data = {
- content: { ...content },
- // `name` is for Element Web (and also the spec)
- // Element Android uses content -> body as the name
- name: content.body,
- }
- // Custom field that stores the ID even for non-telegram stickers
- delete data.content.id
-
- // This is for Element iOS
- const widgetData = {
- ...data,
- description: content.body,
- file: `${content.id}.png`,
- }
- // Element iOS explodes if there are extra fields present
- delete widgetData.content["net.maunium.telegram.sticker"]
-
- window.parent.postMessage({
- api: "fromWidget",
- action: "m.sticker",
- requestId: `sticker-${Date.now()}`,
- widgetId,
- data,
- widgetData,
- }, "*")
-}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage