nodebb-plugin-composer-default 10.3.4 → 10.3.6

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.4",
3
+ "version": "10.3.6",
4
4
  "description": "Default composer for NodeBB",
5
5
  "main": "library.js",
6
6
  "repository": {
@@ -27,6 +27,7 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
27
27
  postContainer.on('click', '[component="category/list"] [data-cid]', utils.debounce(doSaveDraft, draftSaveDelay));
28
28
  postContainer.on('itemAdded', '.tags', utils.debounce(doSaveDraft, draftSaveDelay));
29
29
  postContainer.on('thumb.uploaded', doSaveDraft);
30
+ postContainer.on('composer.minimize', doSaveDraft);
30
31
 
31
32
  draftIconEl.on('animationend', function () {
32
33
  $(this).toggleClass('active', false);
@@ -84,48 +85,45 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
84
85
  const raw = postContainer.find('textarea').val();
85
86
  const storage = getStorage(app.user.uid);
86
87
 
87
- if (raw.length || (title && title.length)) {
88
- const draftData = {
89
- save_id: postData.save_id,
90
- action: postData.action,
91
- text: raw,
92
- uuid: postContainer.attr('data-uuid'),
93
- timestamp: Date.now(),
94
- };
95
-
96
- if (postData.action === 'topics.post') {
97
- // New topic only
98
- const tags = postContainer.find('input.tags').val();
99
- draftData.tags = tags;
100
- draftData.title = title;
101
- draftData.cid = postData.cid;
102
- draftData.thumbs = postData.thumbs || [];
103
- } else if (postData.action === 'posts.reply') {
104
- // new reply only
105
- draftData.title = postData.title;
106
- draftData.tid = postData.tid;
107
- draftData.toPid = postData.toPid;
108
- } else if (postData.action === 'posts.edit') {
109
- draftData.pid = postData.pid;
110
- draftData.title = title || postData.title;
111
- draftData.thumbs = postData.thumbs || [];
112
- }
113
- if (!app.user.uid) {
114
- draftData.handle = postContainer.find('input.handle').val();
115
- }
88
+ const draftData = {
89
+ save_id: postData.save_id,
90
+ action: postData.action,
91
+ text: raw,
92
+ uuid: postContainer.attr('data-uuid'),
93
+ timestamp: Date.now(),
94
+ };
95
+
96
+ if (postData.action === 'topics.post') {
97
+ // New topic only
98
+ const tags = postContainer.find('input.tags').val();
99
+ draftData.tags = tags;
100
+ draftData.title = title;
101
+ draftData.cid = postData.cid;
102
+ draftData.thumbs = postData.thumbs || [];
103
+ } else if (postData.action === 'posts.reply') {
104
+ // new reply only
105
+ draftData.title = postData.title;
106
+ draftData.tid = postData.tid;
107
+ draftData.toPid = postData.toPid;
108
+ } else if (postData.action === 'posts.edit') {
109
+ draftData.pid = postData.pid;
110
+ draftData.title = title || postData.title;
111
+ draftData.thumbs = postData.thumbs || [];
112
+ }
113
+ if (!app.user.uid) {
114
+ draftData.handle = postContainer.find('input.handle').val();
115
+ }
116
116
 
117
- // save all draft data into single item as json
118
- storage.setItem(postData.save_id, JSON.stringify(draftData));
117
+ // save all draft data into single item as json
118
+ storage.setItem(postData.save_id, JSON.stringify(draftData));
119
+
120
+ $(window).trigger('action:composer.drafts.save', {
121
+ storage: storage,
122
+ postData: postData,
123
+ postContainer: postContainer,
124
+ });
125
+ draftIconEl.toggleClass('active', true);
119
126
 
120
- $(window).trigger('action:composer.drafts.save', {
121
- storage: storage,
122
- postData: postData,
123
- postContainer: postContainer,
124
- });
125
- draftIconEl.toggleClass('active', true);
126
- } else {
127
- drafts.removeDraft(postData.save_id);
128
- }
129
127
  }
130
128
  }
131
129
 
@@ -226,23 +226,24 @@ define('composer', [
226
226
  if (data.body) {
227
227
  data.body = '> ' + data.body.replace(/\n/g, '\n> ') + '\n\n';
228
228
  }
229
- var link = '[' + escapedTitle + '](' + config.relative_path + '/post/' + encodeURIComponent(data.selectedPid || data.toPid) + ')';
229
+
230
+ const composerTid = data.uuid ? composer.posts[data.uuid].tid : data.tid;
231
+ const inDifferentTopic = parseInt(data.tid, 10) !== parseInt(composerTid, 10);
232
+ const useTopicLink = data.title && (data.selectedPid || data.toPid) && inDifferentTopic;
233
+ const postHref = `${config.relative_path}/post/${encodeURIComponent(data.selectedPid || data.toPid)}`;
234
+ const topicLink = `[${escapedTitle}](${postHref})`;
235
+
236
+ const quoteKey = useTopicLink ?
237
+ '> [[modules:composer.user-said-in, ' + data.username + ', ' + topicLink + ']]\n>\n' :
238
+ '> [[modules:composer.user-said, ' + data.username + ', ' + postHref + ']]\n>\n';
239
+
230
240
  if (data.uuid === undefined) {
231
- if (data.title && (data.selectedPid || data.toPid)) {
232
- composer.newReply({
233
- tid: data.tid,
234
- toPid: data.toPid,
235
- title: data.title,
236
- body: '[[modules:composer.user-said-in, ' + data.username + ', ' + link + ']]\n' + data.body,
237
- });
238
- } else {
239
- composer.newReply({
240
- tid: data.tid,
241
- toPid: data.toPid,
242
- title: data.title,
243
- body: '[[modules:composer.user-said, ' + data.username + ']]\n' + data.body,
244
- });
245
- }
241
+ composer.newReply({
242
+ tid: data.tid,
243
+ toPid: data.toPid,
244
+ title: data.title,
245
+ body: quoteKey + data.body,
246
+ });
246
247
  return;
247
248
  } else if (data.uuid !== composer.active) {
248
249
  // If the composer is not currently active, activate it
@@ -252,18 +253,13 @@ define('composer', [
252
253
  var postContainer = $('.composer[data-uuid="' + data.uuid + '"]');
253
254
  var bodyEl = postContainer.find('textarea');
254
255
  var prevText = bodyEl.val();
255
- if (data.title && (data.selectedPid || data.toPid)) {
256
- translator.translate('[[modules:composer.user-said-in, ' + data.username + ', ' + link + ']]\n', config.defaultLang, onTranslated);
257
- } else {
258
- translator.translate('[[modules:composer.user-said, ' + data.username + ']]\n', config.defaultLang, onTranslated);
259
- }
260
256
 
261
- function onTranslated(translated) {
257
+ translator.translate(quoteKey, config.defaultLang, function (translated) {
262
258
  composer.posts[data.uuid].body = (prevText.length ? prevText + '\n\n' : '') + translated + data.body;
263
259
  bodyEl.val(composer.posts[data.uuid].body);
264
260
  focusElements(postContainer);
265
261
  preview.render(postContainer);
266
- }
262
+ });
267
263
  };
268
264
 
269
265
  composer.newReply = function (data) {
@@ -871,6 +867,7 @@ define('composer', [
871
867
  post_uuid: post_uuid,
872
868
  });
873
869
 
870
+ postContainer.trigger('composer.minimize');
874
871
  onHide();
875
872
  };
876
873