mirror of
https://ghfast.top/https://github.com/discourse/discourse-signatures.git
synced 2026-07-15 11:26:42 +08:00
* FEATURE: Add decorateCookedSignature plugin API method
Adds a new plugin API method that allows themes and plugins to
decorate signature content, similar to decorateCookedElement for
posts and decorateChatMessage for chat messages.
Usage:
api.decorateCookedSignature((element, helper, post) => {
// modify signature element
});
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Gabriel Grubba <gabriel@discourse.org>
82 lines
2 KiB
Text
82 lines
2 KiB
Text
import Component from "@glimmer/component";
|
|
import { service } from "@ember/service";
|
|
import { trustHTML } from "@ember/template";
|
|
import DecoratedHtml from "discourse/components/decorated-html";
|
|
import { bind } from "discourse/lib/decorators";
|
|
|
|
let _signatureDecorators = [];
|
|
|
|
export function addSignatureDecorator(decorator) {
|
|
_signatureDecorators.push(decorator);
|
|
}
|
|
|
|
export function resetSignatureDecorators() {
|
|
_signatureDecorators = [];
|
|
}
|
|
|
|
export default class PostSignature extends Component {
|
|
static shouldRender(args, context) {
|
|
const enabled =
|
|
context.currentUser?.custom_fields?.see_signatures ??
|
|
context.siteSettings.signatures_visible_by_default;
|
|
|
|
if (!enabled || !args.post.user_signature) {
|
|
return false;
|
|
}
|
|
|
|
if (
|
|
context.siteSettings.signatures_first_post_only &&
|
|
args.post.post_number !== 1
|
|
) {
|
|
return false;
|
|
}
|
|
|
|
const allowedCategories =
|
|
context.siteSettings.signatures_show_in_categories;
|
|
if (allowedCategories) {
|
|
const categoryIds = allowedCategories
|
|
.split("|")
|
|
.map((id) => parseInt(id, 10));
|
|
const postCategoryId = args.post.topic?.category_id;
|
|
if (!categoryIds.includes(postCategoryId)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
@service siteSettings;
|
|
|
|
get isAdvancedModeEnabled() {
|
|
return this.siteSettings.signatures_advanced_mode;
|
|
}
|
|
|
|
get imageMaxHeight() {
|
|
return `max-height: ${this.siteSettings.signatures_max_image_height}px`;
|
|
}
|
|
|
|
@bind
|
|
decorateSignature(element, helper) {
|
|
_signatureDecorators.forEach((decorator) => {
|
|
decorator(element, helper, this.args.post);
|
|
});
|
|
}
|
|
|
|
<template>
|
|
<hr />
|
|
{{#if this.isAdvancedModeEnabled}}
|
|
<DecoratedHtml
|
|
@html={{trustHTML @post.user_signature}}
|
|
@decorate={{this.decorateSignature}}
|
|
@className="user-signature"
|
|
/>
|
|
{{else}}
|
|
<img
|
|
class="signature-img"
|
|
src={{@post.user_signature}}
|
|
style={{this.imageMaxHeight}}
|
|
/>
|
|
{{/if}}
|
|
</template>
|
|
}
|