nodebb-plugin-composer-default 10.2.51 → 10.3.1

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.2.51",
3
+ "version": "10.3.1",
4
4
  "description": "Default composer for NodeBB",
5
5
  "main": "library.js",
6
6
  "repository": {
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "readmeFilename": "README.md",
28
28
  "nbbpm": {
29
- "compatibility": "^4.0.0"
29
+ "compatibility": "^4.5.0"
30
30
  },
31
31
  "dependencies": {
32
32
  "screenfull": "^5.0.2",
@@ -92,11 +92,23 @@ define('composer/categoryList', [
92
92
  }
93
93
  }
94
94
 
95
+ function updateTopicTemplate(postContainer, category, previousCategory) {
96
+ const currentText = postContainer.find('textarea.write').val();
97
+ const previousTopicTemplate = previousCategory && previousCategory.topicTemplate;
98
+ if (category && (!currentText.length || currentText === previousTopicTemplate) &&
99
+ currentText !== category.topicTemplate) {
100
+ postContainer.find('textarea.write').val(category.topicTemplate).trigger('input');
101
+ }
102
+ }
103
+
95
104
  async function changeCategory(postContainer, postData, selectedCategory) {
105
+ const previousCategory = postData.category;
96
106
  postData.cid = selectedCategory.cid;
97
107
  const categoryData = await window.fetch(`${config.relative_path}/api/category/${encodeURIComponent(selectedCategory.cid)}`).then(r => r.json());
98
108
  postData.category = categoryData;
99
109
  updateTaskbarByCategory(postContainer, categoryData);
110
+ updateTopicTemplate(postContainer, categoryData, previousCategory);
111
+
100
112
  require(['composer/scheduler', 'composer/tags', 'composer/post-queue'], function (scheduler, tags, postQueue) {
101
113
  scheduler.onChangeCategory(categoryData);
102
114
  tags.onChangeCategory(postContainer, postData, selectedCategory.cid, categoryData);
@@ -41,7 +41,6 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
41
41
  });
42
42
 
43
43
  drafts.migrateGuest();
44
- drafts.migrateThumbs(...arguments);
45
44
  };
46
45
 
47
46
  function getStorage(uid) {
@@ -100,6 +99,7 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
100
99
  draftData.tags = tags;
101
100
  draftData.title = title;
102
101
  draftData.cid = postData.cid;
102
+ draftData.thumbs = postData.thumbs || [];
103
103
  } else if (postData.action === 'posts.reply') {
104
104
  // new reply only
105
105
  draftData.title = postData.title;
@@ -108,6 +108,7 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
108
108
  } else if (postData.action === 'posts.edit') {
109
109
  draftData.pid = postData.pid;
110
110
  draftData.title = title || postData.title;
111
+ draftData.thumbs = postData.thumbs || [];
111
112
  }
112
113
  if (!app.user.uid) {
113
114
  draftData.handle = postContainer.find('input.handle').val();
@@ -208,26 +209,6 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
208
209
  }
209
210
  };
210
211
 
211
- drafts.migrateThumbs = function (postContainer, postData) {
212
- if (!app.uid) {
213
- return;
214
- }
215
-
216
- // If any thumbs were uploaded, migrate them to this new composer's uuid
217
- const newUUID = postContainer.attr('data-uuid');
218
- const draft = drafts.get(postData.save_id);
219
-
220
- if (draft && draft.uuid) {
221
- api.put(`/topics/${draft.uuid}/thumbs`, {
222
- tid: newUUID,
223
- }).then(() => {
224
- require(['composer'], function (composer) {
225
- composer.updateThumbCount(newUUID, postContainer);
226
- });
227
- });
228
- }
229
- };
230
-
231
212
  drafts.listAvailable = function () {
232
213
  const available = drafts.getList('available');
233
214
  return available.map(drafts.get).filter(Boolean);
@@ -286,6 +267,7 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
286
267
  title: utils.escapeHTML(draft.title),
287
268
  body: draft.text,
288
269
  tags: String(draft.tags || '').split(','),
270
+ thumbs: draft.thumbs || [],
289
271
  });
290
272
  } else if (draft.action === 'posts.reply') {
291
273
  api.get('/topics/' + draft.tid, {}, function (err, topicObj) {
@@ -307,6 +289,7 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
307
289
  pid: draft.pid,
308
290
  title: draft.title ? utils.escapeHTML(draft.title) : undefined,
309
291
  body: draft.text,
292
+ thumbs: draft.thumbs || [],
310
293
  });
311
294
  }
312
295
  });
@@ -28,8 +28,8 @@ define('composer/formatting', [
28
28
  const composerObj = composer.posts[uuid];
29
29
 
30
30
  if (composerObj.action === 'topics.post' || (composerObj.action === 'posts.edit' && composerObj.isMain)) {
31
- topicThumbs.modal.open({ id: uuid, pid: composerObj.pid }).then(() => {
32
- postContainer.trigger('thumb.uploaded'); // toggle draft save
31
+ topicThumbs.modal.open({ id: uuid, postData: composerObj }).then(() => {
32
+ postContainer.trigger('thumb.uploaded');
33
33
 
34
34
  // Update client-side with count
35
35
  composer.updateThumbCount(uuid, postContainer);
@@ -19,7 +19,7 @@ define('composer/uploads', [
19
19
  initializePaste(post_uuid);
20
20
 
21
21
  addChangeHandlers(post_uuid);
22
- addTopicThumbHandlers(post_uuid);
22
+
23
23
  translator.translate('[[modules:composer.uploading, ' + 0 + '%]]', function (translated) {
24
24
  uploadingText = translated;
25
25
  });
@@ -37,36 +37,6 @@ define('composer/uploads', [
37
37
  });
38
38
  }
39
39
 
40
- function addTopicThumbHandlers(post_uuid) {
41
- var postContainer = $('.composer[data-uuid="' + post_uuid + '"]');
42
-
43
- postContainer.on('click', '.topic-thumb-clear-btn', function (e) {
44
- postContainer.find('input#topic-thumb-url').val('').trigger('change');
45
- resetInputFile(postContainer.find('input#topic-thumb-file'));
46
- $(this).addClass('hide');
47
- e.preventDefault();
48
- });
49
-
50
- postContainer.on('paste change keypress', 'input#topic-thumb-url', function () {
51
- var urlEl = $(this);
52
- setTimeout(function () {
53
- var url = urlEl.val();
54
- if (url) {
55
- postContainer.find('.topic-thumb-clear-btn').removeClass('hide');
56
- } else {
57
- resetInputFile(postContainer.find('input#topic-thumb-file'));
58
- postContainer.find('.topic-thumb-clear-btn').addClass('hide');
59
- }
60
- postContainer.find('img.topic-thumb-preview').attr('src', url);
61
- }, 100);
62
- });
63
- }
64
-
65
- function resetInputFile($el) {
66
- $el.wrap('<form />').closest('form').get(0).reset();
67
- $el.unwrap();
68
- }
69
-
70
40
  function initializeDragAndDrop(post_uuid) {
71
41
  var postContainer = $('.composer[data-uuid="' + post_uuid + '"]');
72
42
  uploadHelpers.handleDragDrop({
@@ -201,6 +201,7 @@ define('composer', [
201
201
  title: data.title || '',
202
202
  body: data.body || '',
203
203
  tags: data.tags || [],
204
+ thumbs: data.thumbs || [],
204
205
  modified: !!((data.title && data.title.length) || (data.body && data.body.length)),
205
206
  isMain: true,
206
207
  };
@@ -417,7 +418,7 @@ define('composer', [
417
418
  handleHelp(postContainer);
418
419
  handleSearch(postContainer);
419
420
  focusElements(postContainer);
420
- if (postData.action === 'posts.edit') {
421
+ if (postData.action === 'posts.edit' || postData.action === 'topics.post') {
421
422
  composer.updateThumbCount(post_uuid, postContainer);
422
423
  }
423
424
 
@@ -459,10 +460,11 @@ define('composer', [
459
460
  var title = postData.title.replace(/%/g, '&#37;').replace(/,/g, '&#44;');
460
461
  postData.category = await getSelectedCategory(postData);
461
462
  const privileges = postData.category ? postData.category.privileges : ajaxify.data.privileges;
463
+ const topicTemplate = isTopic && postData.category ? postData.category.topicTemplate : null;
462
464
  var data = {
463
465
  topicTitle: title,
464
466
  titleLength: title.length,
465
- body: translator.escape(utils.escapeHTML(postData.body)),
467
+ body: translator.escape(utils.escapeHTML(topicTemplate || postData.body)),
466
468
  mobile: composer.bsEnvironment === 'xs' || composer.bsEnvironment === 'sm',
467
469
  resizable: true,
468
470
  thumb: postData.thumb,
@@ -736,6 +738,7 @@ define('composer', [
736
738
  thumb: thumbEl.val() || '',
737
739
  cid: categoryList.getSelectedCid(),
738
740
  tags: tags.getTags(post_uuid),
741
+ thumbs: postData.thumbs || [],
739
742
  timestamp: scheduler.getTimestamp(),
740
743
  };
741
744
  } else if (action === 'posts.reply') {
@@ -756,7 +759,7 @@ define('composer', [
756
759
  handle: handleEl ? handleEl.val() : undefined,
757
760
  content: bodyEl.val(),
758
761
  title: titleEl.val(),
759
- thumb: thumbEl.val() || '',
762
+ thumbs: postData.thumbs || [],
760
763
  tags: tags.getTags(post_uuid),
761
764
  timestamp: scheduler.getTimestamp(),
762
765
  };
@@ -883,20 +886,12 @@ define('composer', [
883
886
 
884
887
  composer.updateThumbCount = function (uuid, postContainer) {
885
888
  const composerObj = composer.posts[uuid];
886
- if (composerObj.action === 'topics.post' || (composerObj.action === 'posts.edit' && composerObj.isMain)) {
887
- const calls = [
888
- topicThumbs.get(uuid),
889
- ];
890
- if (composerObj.pid) {
891
- calls.push(topicThumbs.getByPid(composerObj.pid));
892
- }
893
- Promise.all(calls).then((thumbs) => {
894
- const thumbCount = thumbs.flat().length;
895
- const formatEl = postContainer.find('[data-format="thumbs"]');
896
- formatEl.find('.badge')
897
- .text(thumbCount)
898
- .toggleClass('hidden', !thumbCount);
899
- });
889
+ if (composerObj && (composerObj.action === 'topics.post' || (composerObj.action === 'posts.edit' && composerObj.isMain))) {
890
+ const thumbCount = composerObj.thumbs ? composerObj.thumbs.length : 0;
891
+ const formatEl = postContainer.find('[data-format="thumbs"]');
892
+ formatEl.find('.badge')
893
+ .text(thumbCount)
894
+ .toggleClass('hidden', !thumbCount);
900
895
  }
901
896
  };
902
897
 
@@ -107,13 +107,11 @@
107
107
  color: $body-color;
108
108
  font-size: 16px;
109
109
  width: 50%;
110
+ height: 28px;
111
+ padding: 4px 6px;
110
112
  @include media-breakpoint-down(md) {
111
113
  width: 100%;
112
114
  }
113
-
114
-
115
- height: 28px;
116
- padding: 4px 6px;
117
115
  }
118
116
 
119
117
  .ui-autocomplete {
package/websockets.js CHANGED
@@ -19,9 +19,8 @@ Sockets.push = async function (socket, pid) {
19
19
  throw new Error('[[error:invalid-pid]]');
20
20
  }
21
21
 
22
- const [topic, tags, isMain] = await Promise.all([
22
+ const [topic, isMain] = await Promise.all([
23
23
  topics.getTopicDataByPid(pid),
24
- topics.getTopicTags(postData.tid),
25
24
  posts.isMain(pid),
26
25
  ]);
27
26
 
@@ -35,8 +34,8 @@ Sockets.push = async function (socket, pid) {
35
34
  handle: parseInt(meta.config.allowGuestHandles, 10) ? postData.handle : undefined,
36
35
  body: postData.sourceContent || postData.content,
37
36
  title: topic.title,
38
- thumb: topic.thumb,
39
- tags: tags,
37
+ thumbs: topic.thumbs,
38
+ tags: topic.tags.map(t => t.value),
40
39
  isMain: isMain,
41
40
  timestamp: postData.timestamp,
42
41
  });