Skip to content

Commit

Permalink
feat: allow more params to app.newTopic/newReply
Browse files Browse the repository at this point in the history
closes #11649
  • Loading branch information
barisusakli committed May 30, 2023
1 parent 3b53f41 commit 325c195
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions public/src/app.js
Expand Up @@ -280,24 +280,40 @@ if (document.readyState === 'loading') {
});
};

app.newTopic = function (cid, tags) {
app.newTopic = function (params) {
// backwards compatibilty for old signature (cid, tags)
if (typeof params !== 'object' || params) {

This comment has been minimized.

Copy link
@ShlomoCode

ShlomoCode May 30, 2023

@barisusakli why || params needed? 🤔

This comment has been minimized.

Copy link
@barisusakli

barisusakli May 31, 2023

Author Member

@ShlomoCode I removed it in 9f3bdf7 should work now.

if (params) {
console.warn('[deprecated] app.newTopic(cid, tags) please pass in an object');
}
params = {
cid: params,
tags: arguments[1] || (ajaxify.data.tag ? [ajaxify.data.tag] : []),
};
}

require(['hooks'], function (hooks) {
hooks.fire('action:composer.topic.new', {
cid: cid || ajaxify.data.cid || 0,
tags: tags || (ajaxify.data.tag ? [ajaxify.data.tag] : []),
});
params.cid = params.cid || ajaxify.data.cid || 0;
params.tags = params.tags || (ajaxify.data.tag ? [ajaxify.data.tag] : []);
hooks.fire('action:composer.topic.new', params);
});
};

app.newReply = async function (tid) {
app.newReply = async function (params) {
// backwards compatibilty for old signature (tid)
if (typeof params !== 'object') {
console.warn('[deprecated] app.newReply(tid) please pass in an object');
params = {
tid: params,
};
}

const [hooks, api] = await app.require(['hooks', 'api']);
const titleRaw = ajaxify.data.template.topic ?
params.title = (ajaxify.data.template.topic ?
ajaxify.data.titleRaw :
(await api.get(`/topics/${tid}`)).titleRaw;
hooks.fire('action:composer.post.new', {
tid: tid,
topicName: titleRaw,
});
(await api.get(`/topics/${params.tid}`)).titleRaw);

hooks.fire('action:composer.post.new', params);
};

app.loadJQueryUI = function (callback) {
Expand Down

0 comments on commit 325c195

Please sign in to comment.