summaryrefslogtreecommitdiffstats
path: root/sticker.pinapelz.com/src/widget-api.js
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2026-05-27 00:53:18 -0700
committerPinapelz <yukais@pinapelz.com>2026-05-27 00:55:26 -0700
commit36e053f4f0a2f63c08f7c28b9492c067f1ca42bc (patch)
treec28973073c8e26775ee4d18d1016df44afdfeceb /sticker.pinapelz.com/src/widget-api.js
parenta01e0666fd66c367745cdaff76fcd6ea7568c31c (diff)
migrate pinapelz.moe -> pinapelz.com
Diffstat (limited to 'sticker.pinapelz.com/src/widget-api.js')
-rw-r--r--sticker.pinapelz.com/src/widget-api.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/sticker.pinapelz.com/src/widget-api.js b/sticker.pinapelz.com/src/widget-api.js
new file mode 100644
index 0000000..d9964a7
--- /dev/null
+++ b/sticker.pinapelz.com/src/widget-api.js
@@ -0,0 +1,77 @@
+// maunium-stickerpicker - A fast and simple Matrix sticker picker widget.
+// Copyright (C) 2020 Tulir Asokan
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+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.filename ?? `${content.id}.png`,
+ }
+ delete widgetData.content.filename
+ // 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