FEATURE: 2.0
- Cook on advanced mode is server side and properly cached now - Remove deprecated dependencies on client-side code Attention: Users on advanced mode from previous versions should re-enter their signatures.
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||
import RawHtml from 'discourse/widgets/raw-html';
|
||||
import { cook } from 'discourse/lib/text';
|
||||
|
||||
function attachSignature(api) {
|
||||
function attachSignature(api, siteSettings) {
|
||||
api.includePostAttributes('user_signature');
|
||||
|
||||
api.decorateWidget('post-contents:after-cooked', dec => {
|
||||
@@ -11,12 +10,11 @@ function attachSignature(api) {
|
||||
if (Ember.isEmpty(attrs.user_signature)) { return; }
|
||||
|
||||
const currentUser = api.getCurrentUser();
|
||||
const siteSettings = Discourse.SiteSettings; // TODO: change way to get the sitesettings
|
||||
if (currentUser) {
|
||||
const enabled = currentUser.get('custom_fields.see_signatures');
|
||||
if (enabled) {
|
||||
if (siteSettings.signatures_advanced_mode) {
|
||||
return [dec.h('hr'), dec.h('div', new RawHtml({html: `<div class='user-signature'>${cook(attrs.user_signature)}</div>`}))];
|
||||
return [dec.h('hr'), dec.h('div', new RawHtml({html: `<div class='user-signature'>${attrs.user_signature}</div>`}))];
|
||||
} else {
|
||||
return [dec.h('hr'), dec.h('img.signature-img', {attributes: {src: attrs.user_signature}})];
|
||||
}
|
||||
@@ -30,7 +28,7 @@ export default {
|
||||
initialize(container) {
|
||||
const siteSettings = container.lookup('site-settings:main');
|
||||
if (siteSettings.signatures_enabled) {
|
||||
withPluginApi('0.1', attachSignature);
|
||||
withPluginApi('0.1', api => attachSignature(api, siteSettings));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+5
-4
@@ -1,22 +1,23 @@
|
||||
{{#if siteSettings.signatures_enabled}}
|
||||
<div class="control-group signatures">
|
||||
<label class="control-label">Signatures</label>
|
||||
<label class="control-label">Enable Signatures</label>
|
||||
<div class="controls">
|
||||
<label class='checkbox-label'>
|
||||
{{input type="checkbox" checked=model.custom_fields.see_signatures}}
|
||||
See user signatures below posts
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group signatures">
|
||||
<label class="control-label">My Signature</label>
|
||||
<div class="controls">
|
||||
<label>Signature</label>
|
||||
{{#if siteSettings.signatures_advanced_mode}}
|
||||
{{d-editor value=model.custom_fields.signature_raw showUploadModal="showUploadModal"}}
|
||||
{{else}}
|
||||
<label class='text-label'>
|
||||
{{input type="text" value=model.custom_fields.signature_url}}
|
||||
{{input type="text" class="input-xxlarge" value=model.custom_fields.signature_url}}
|
||||
</label>
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="instructions">Signature Code</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# name: discourse-signatures
|
||||
# about: A plugin to get that nostalgia signatures in Discourse Foruns
|
||||
# version: 1.0.0
|
||||
# version: 2.0.0
|
||||
# author: Rafael Silva <xfalcox@gmail.com>
|
||||
# url: https://github.com/xfalcox/discourse-signatures
|
||||
|
||||
@@ -19,7 +19,7 @@ after_initialize do
|
||||
if SiteSetting.signatures_enabled then
|
||||
add_to_serializer(:post, :user_signature, false) {
|
||||
if SiteSetting.signatures_advanced_mode then
|
||||
object.user.custom_fields['signature_raw'] if object.user
|
||||
object.user.custom_fields['signature_cooked'] if object.user
|
||||
else
|
||||
object.user.custom_fields['signature_url'] if object.user
|
||||
end
|
||||
@@ -34,6 +34,15 @@ after_initialize do
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
# This is the code responsible for cooking a new advanced mode sig on user update
|
||||
DiscourseEvent.on(:user_updated) do |user|
|
||||
if SiteSetting.signatures_enabled? && SiteSetting.signatures_advanced_mode
|
||||
cooked_sig = PrettyText.cook(user.custom_fields['signature_raw'], omit_nofollow: user.has_trust_level?(TrustLevel[3]) && !SiteSetting.tl3_links_no_follow)
|
||||
user.custom_fields['signature_cooked'] = cooked_sig
|
||||
user.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
register_asset "javascripts/discourse/templates/connectors/user-custom-preferences/signature-preferences.hbs"
|
||||
|
||||
Reference in New Issue
Block a user