From 325c1955b8c0cc97c99b88384d1ac7c6f96a5f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 30 May 2023 19:06:02 -0400 Subject: [PATCH] feat: allow more params to app.newTopic/newReply closes #11649 --- public/src/app.js | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index a4e25beab2..74648d2627 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -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) { + 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) {