nodebb-plugin-composer-default 10.3.23 → 10.3.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-composer-default",
3
- "version": "10.3.23",
3
+ "version": "10.3.25",
4
4
  "description": "Default composer for NodeBB",
5
5
  "main": "library.js",
6
6
  "repository": {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
3
+ define('composer/drafts', ['api', 'hooks'], function (api, hooks) {
4
4
  const drafts = {};
5
5
  const draftSaveDelay = 1000;
6
6
  drafts.init = function (postContainer, postData) {
@@ -78,7 +78,7 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
78
78
  }
79
79
  };
80
80
 
81
- function saveDraft(postContainer, draftIconEl, postData) {
81
+ async function saveDraft(postContainer, draftIconEl, postData) {
82
82
  if (canSave(app.user.uid ? 'localStorage' : 'sessionStorage') && postData && postData.save_id && postContainer.length) {
83
83
  const titleEl = postContainer.find('input.title');
84
84
  const title = titleEl && titleEl.length && titleEl.val();
@@ -114,16 +114,17 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
114
114
  draftData.handle = postContainer.find('input.handle').val();
115
115
  }
116
116
 
117
+ await hooks.fire('filter:composer.drafts.save', { draft: draftData, postData, postContainer });
118
+
117
119
  // save all draft data into single item as json
118
120
  storage.setItem(postData.save_id, JSON.stringify(draftData));
119
121
 
120
122
  $(window).trigger('action:composer.drafts.save', {
121
- storage: storage,
122
- postData: postData,
123
- postContainer: postContainer,
123
+ storage,
124
+ postData,
125
+ postContainer,
124
126
  });
125
127
  draftIconEl.toggleClass('active', true);
126
-
127
128
  }
128
129
  }
129
130
 
@@ -249,51 +250,51 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
249
250
  }
250
251
  };
251
252
 
252
- function openComposer(save_id, draft) {
253
+ async function openComposer(save_id, draft) {
253
254
  const saveObj = save_id.split(':');
254
255
  const uid = saveObj[1];
255
256
  // Don't open other peoples' drafts
256
257
  if (parseInt(app.user.uid, 10) !== parseInt(uid, 10)) {
257
258
  return;
258
259
  }
259
- require(['composer'], function (composer) {
260
- if (draft.action === 'topics.post') {
261
- composer.newTopic({
262
- fromDraft: true,
263
- save_id: draft.save_id,
264
- cid: draft.cid,
265
- handle: app.user && app.user.uid ? undefined : utils.escapeHTML(draft.handle),
266
- title: utils.escapeHTML(draft.title),
267
- body: draft.text,
268
- tags: String(draft.tags || '').split(','),
269
- thumbs: draft.thumbs || [],
270
- });
271
- } else if (draft.action === 'posts.reply') {
272
- api.get('/topics/' + draft.tid, {}, function (err, topicObj) {
273
- if (err) {
274
- return alerts.error(err);
275
- }
276
-
277
- composer.newReply({
278
- fromDraft: true,
279
- save_id: draft.save_id,
280
- tid: draft.tid,
281
- toPid: draft.toPid,
282
- title: topicObj.title,
283
- body: draft.text,
284
- });
285
- });
286
- } else if (draft.action === 'posts.edit') {
287
- composer.editPost({
288
- fromDraft: true,
289
- save_id: draft.save_id,
290
- pid: draft.pid,
291
- title: draft.title ? utils.escapeHTML(draft.title) : undefined,
292
- body: draft.text,
293
- thumbs: draft.thumbs || [],
294
- });
295
- }
296
- });
260
+ const composer = await app.require('composer');
261
+ if (draft.action === 'topics.post') {
262
+ let composerData = {
263
+ fromDraft: true,
264
+ save_id: draft.save_id,
265
+ cid: draft.cid,
266
+ handle: app.user && app.user.uid ? undefined : utils.escapeHTML(draft.handle),
267
+ title: utils.escapeHTML(draft.title),
268
+ body: draft.text,
269
+ tags: String(draft.tags || '').split(','),
270
+ thumbs: draft.thumbs || [],
271
+ };
272
+ ({ composerData } = await hooks.fire('filter:composer.drafts.open', { draft, composerData }));
273
+ composer.newTopic(composerData);
274
+ } else if (draft.action === 'posts.reply') {
275
+ const topicObj = await api.get('/topics/' + draft.tid, {});
276
+ let composerData = {
277
+ fromDraft: true,
278
+ save_id: draft.save_id,
279
+ tid: draft.tid,
280
+ toPid: draft.toPid,
281
+ title: topicObj.title,
282
+ body: draft.text,
283
+ };
284
+ ({ composerData } = await hooks.fire('filter:composer.drafts.open', { draft, composerData }));
285
+ composer.newReply(composerData);
286
+ } else if (draft.action === 'posts.edit') {
287
+ let composerData = {
288
+ fromDraft: true,
289
+ save_id: draft.save_id,
290
+ pid: draft.pid,
291
+ title: draft.title ? utils.escapeHTML(draft.title) : undefined,
292
+ body: draft.text,
293
+ thumbs: draft.thumbs || [],
294
+ };
295
+ ({ composerData } = await hooks.fire('filter:composer.drafts.open', { draft, composerData }));
296
+ composer.editPost(composerData);
297
+ }
297
298
  }
298
299
 
299
300
  // Feature detection courtesy of: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API
@@ -253,20 +253,24 @@ define('composer', [
253
253
  });
254
254
  };
255
255
 
256
- composer.newReply = function (data) {
257
- translator.translate(data.body, config.defaultLang, function (translated) {
258
- push({
259
- fromDraft: data.fromDraft,
260
- save_id: data.save_id,
261
- action: 'posts.reply',
262
- tid: data.tid,
263
- toPid: data.toPid,
264
- title: data.title,
265
- body: translated,
266
- modified: !!(translated && translated.length),
267
- isMain: false,
268
- });
269
- });
256
+ composer.newReply = async function (data) {
257
+ const translated = await translator.translate(data.body, config.defaultLang);
258
+ let pushData = {
259
+ fromDraft: data.fromDraft,
260
+ save_id: data.save_id,
261
+ action: 'posts.reply',
262
+ tid: data.tid,
263
+ toPid: data.toPid,
264
+ title: data.title,
265
+ body: translated,
266
+ modified: !!(translated && translated.length),
267
+ isMain: false,
268
+ };
269
+ ({ pushData } = await hooks.fire('filter:composer.reply.push', {
270
+ data: data,
271
+ pushData: pushData,
272
+ }));
273
+ push(pushData);
270
274
  };
271
275
 
272
276
  composer.editPost = function (data) {
@@ -880,5 +884,12 @@ define('composer', [
880
884
  }
881
885
  };
882
886
 
887
+ composer.updateFormattingBtnBadgeCount = function (postContainer, formatName, count) {
888
+ const formatEl = postContainer.find(`[data-format="${formatName}"]`);
889
+ formatEl.find('.badge')
890
+ .text(count)
891
+ .toggleClass('hidden', !count);
892
+ };
893
+
883
894
  return composer;
884
895
  });
package/websockets.js CHANGED
@@ -15,7 +15,7 @@ Sockets.push = async function (socket, pid) {
15
15
  }
16
16
 
17
17
  const postData = await posts.getPostFields(pid, ['content', 'sourceContent', 'tid', 'uid', 'handle', 'timestamp']);
18
- if (!postData && !postData.content) {
18
+ if (!postData || (!postData.content && !postData.sourceContent)) {
19
19
  throw new Error('[[error:invalid-pid]]');
20
20
  }
21
21