From 0405d76ebf262f4f5f781a0445969c4bd3091f8e Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 20 Mar 2019 23:53:10 -0600 Subject: [PATCH] Add some documentation for custom stickers and support disabling them --- config/default.yaml | 21 ++++++++-- docs/custom_stickerpacks.md | 41 +++++++++++++++++++ src/api/dimension/DimensionStickerService.ts | 23 +++++++++++ src/config.ts | 5 +++ .../stickerpicker.component.html | 5 ++- .../stickerpicker/stickerpicker.component.ts | 9 ++++ web/app/shared/models/integration.ts | 6 +++ .../integrations/sticker-api.service.ts | 6 ++- 8 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 docs/custom_stickerpacks.md diff --git a/config/default.yaml b/config/default.yaml index 8095995..0c08b3c 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -23,10 +23,10 @@ homeserver: # stickers. If not supplied or left empty Dimension will use the clientServerUrl. #mediaUrl: "https://t2bot.io" - # The access token Dimension should use for miscellaneous access to the homeserver. This - # should be for a user on the configured homeserver: any user will do, however it is - # recommended to use a dedicated user (such as @dimension:t2bot.io). For information on - # how to acquire an access token, visit https://t2bot.io/docs/access_tokens + # The access token Dimension should use for miscellaneous access to the homeserver, and + # for tracking custom sticker pack updates. This should be a user configured on the homeserver + # and be dedicated to Dimension (create a user named "dimension" on your homeserver). For + # information on how to acquire an access token, visit https://t2bot.io/docs/access_tokens accessToken: "something" # These users can modify the integrations this Dimension supports. @@ -73,6 +73,19 @@ telegram: # Talk to @BotFather on Telegram to get a token botToken: "YourTokenHere" +# Custom sticker pack options. +# Largely based on https://github.com/turt2live/matrix-sticker-manager +stickers: + # Whether or not to allow people to add custom sticker packs + enabled: true + + # The sticker manager bot to promote + stickerBot: "@stickers:t2bot.io" + + # The sticker manager URL to promote + managerUrl: "https://stickers.t2bot.io" + + # Settings for controlling how logging works logging: file: logs/dimension.log diff --git a/docs/custom_stickerpacks.md b/docs/custom_stickerpacks.md new file mode 100644 index 0000000..32c9917 --- /dev/null +++ b/docs/custom_stickerpacks.md @@ -0,0 +1,41 @@ +## Custom Stickerpacks + +Share stickers and customize your experience with custom sticker packs, supported by Dimension. + +### Creating a sticker pack + +1. Start a conversation with [@stickers:t2bot.io](https://matrix.to/#/@stickers:t2bot.io) +2. Say `!stickers newpack` and follow the instructions. +3. Share the URL with your friends. + +### Adding custom sticker packs to your sticker picker + +1. Make sure you're using Dimension as an integration manager. +2. Open the sticker picker (smiley icon next to where you type messages). +3. Click the Edit button in the top right. +4. Paste the URL to the sticker pack you want to add into the box and click "Add Stickerpack". +5. Close Dimension and start using the stickers. + +### Admin/Operator guide: Enabling custom sticker packs / using your own sticker manager + +In Dimension's configuration, make sure the following section exists: + +```yaml +# Custom sticker pack options. +# Largely based on https://github.com/turt2live/matrix-sticker-manager +stickers: + # Whether or not to allow people to add custom sticker packs + enabled: true + + # The sticker manager bot to promote + stickerBot: "@stickers:t2bot.io" + + # The sticker manager URL to promote + managerUrl: "https://stickers.t2bot.io" +``` + +Provided the `enabled` flag is `true`, users will be able to add custom sticker packs to their pickers. Custom +stickers may require federation to work, and so it suggested that non-federated or closed environments use a +dedicated instance of [turt2live/matrix-sticker-manager](https://github.com/turt2live/matrix-sticker-manager) - +the project which makes `@stickers:t2bot.io` work. The `stickerBot` should be whichever user account is used by +the sticker manager, and the `managerUrl` should be the base URL of the manager. diff --git a/src/api/dimension/DimensionStickerService.ts b/src/api/dimension/DimensionStickerService.ts index 622f04c..bf0c15e 100644 --- a/src/api/dimension/DimensionStickerService.ts +++ b/src/api/dimension/DimensionStickerService.ts @@ -7,6 +7,7 @@ import UserStickerPack from "../../db/models/UserStickerPack"; import { ApiError } from "../ApiError"; import { StickerpackMetadataDownloader } from "../../utils/StickerpackMetadataDownloader"; import { MatrixStickerBot } from "../../matrix/MatrixStickerBot"; +import config from "../../config"; export interface MemoryStickerPack { id: number; @@ -52,6 +53,12 @@ interface ImportPackRequest { packUrl: string; } +interface StickerConfig { + enabled: boolean; + stickerBot: string; + managerUrl: string; +} + /** * API for stickers */ @@ -76,6 +83,18 @@ export class DimensionStickerService { return packs; } + @GET + @Path("config") + public async getConfig(@QueryParam("scalar_token") scalarToken: string): Promise { + await ScalarService.getTokenOwner(scalarToken); + + return { + enabled: config.stickers.enabled, + stickerBot: config.stickers.stickerBot, + managerUrl: config.stickers.managerUrl, + }; + } + @GET @Path("packs") public async getStickerPacks(@QueryParam("scalar_token") scalarToken: string): Promise { @@ -132,6 +151,10 @@ export class DimensionStickerService { public async importPack(@QueryParam("scalar_token") scalarToken: string, request: ImportPackRequest): Promise { await ScalarService.getTokenOwner(scalarToken); + if (!config.stickers.enabled) { + throw new ApiError(400, "Custom stickerpacks are disabled on this homeserver"); + } + const packUrl = request.packUrl.endsWith(".json") ? request.packUrl : `${request.packUrl}.json`; const metadata = await StickerpackMetadataDownloader.getMetadata(packUrl); await MatrixStickerBot.trackStickerpack(metadata.roomAlias); diff --git a/src/config.ts b/src/config.ts index 7ee4caa..ecdf0a2 100644 --- a/src/config.ts +++ b/src/config.ts @@ -27,6 +27,11 @@ export interface DimensionConfig { telegram: { botToken: string; }; + stickers: { + enabled: boolean; + stickerBot: string; + managerUrl: string; + }; logging: LogConfig; } diff --git a/web/app/configs/stickerpicker/stickerpicker.component.html b/web/app/configs/stickerpicker/stickerpicker.component.html index a9807a9..f7a6c81 100644 --- a/web/app/configs/stickerpicker/stickerpicker.component.html +++ b/web/app/configs/stickerpicker/stickerpicker.component.html @@ -7,13 +7,14 @@
Sticker packs are not enabled on this Dimension instance.
- +
diff --git a/web/app/configs/stickerpicker/stickerpicker.component.ts b/web/app/configs/stickerpicker/stickerpicker.component.ts index e5452c4..0bb8c45 100644 --- a/web/app/configs/stickerpicker/stickerpicker.component.ts +++ b/web/app/configs/stickerpicker/stickerpicker.component.ts @@ -19,6 +19,9 @@ export class StickerpickerComponent implements OnInit { // Import stuff public packUrl = ""; public isImporting = false; + public customEnabled = false; + public managerUrl: string; + public stickerBot: string; constructor(private stickerApi: StickerApiService, private media: MediaService, @@ -37,6 +40,12 @@ export class StickerpickerComponent implements OnInit { console.error(e); this.toaster.pop("error", "Failed to load sticker packs"); } + + this.stickerApi.getConfig().then(config => { + this.customEnabled = config.enabled; + this.managerUrl = config.managerUrl; + this.stickerBot = config.stickerBot; + }).catch(err => console.error(err)); } public importPack() { diff --git a/web/app/shared/models/integration.ts b/web/app/shared/models/integration.ts index c366ba5..ec62f5f 100644 --- a/web/app/shared/models/integration.ts +++ b/web/app/shared/models/integration.ts @@ -63,6 +63,12 @@ export interface FE_Sticker { }; } +export interface FE_StickerConfig { + enabled: boolean; + stickerBot: string; + managerUrl: string; +} + export interface FE_Widget extends FE_Integration { options: any; } diff --git a/web/app/shared/services/integrations/sticker-api.service.ts b/web/app/shared/services/integrations/sticker-api.service.ts index 65440d4..ffe15c8 100644 --- a/web/app/shared/services/integrations/sticker-api.service.ts +++ b/web/app/shared/services/integrations/sticker-api.service.ts @@ -1,7 +1,7 @@ import { Injectable } from "@angular/core"; import { Http } from "@angular/http"; import { AuthedApi } from "../authed-api"; -import { FE_UserStickerPack } from "../../models/integration"; +import { FE_StickerConfig, FE_UserStickerPack } from "../../models/integration"; @Injectable() export class StickerApiService extends AuthedApi { @@ -9,6 +9,10 @@ export class StickerApiService extends AuthedApi { super(http); } + public getConfig(): Promise { + return this.authedGet("/api/v1/dimension/stickers/config").map(r => r.json()).toPromise(); + } + public getPacks(): Promise { return this.authedGet("/api/v1/dimension/stickers/packs").map(r => r.json()).toPromise(); }