mirror of
https://github.com/flarum/framework.git
synced 2025-01-22 18:05:32 +08:00
c8a1ec722d
Includes transpiled JS/TS. [skip ci]
2 lines
3.6 KiB
JavaScript
2 lines
3.6 KiB
JavaScript
(()=>{var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var s in n)e.o(n,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:n[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};(()=>{"use strict";e.r(t);const n=flarum.core.compat.extend,s=flarum.core.compat.app;var o=e.n(s);const r=flarum.core.compat["components/DiscussionList"];var i=e.n(r);const u=flarum.core.compat["components/DiscussionPage"];var a=e.n(u);const c=flarum.core.compat["components/IndexPage"];var d=e.n(c);const p=flarum.core.compat["components/Button"];var f=e.n(p);o().initializers.add("flarum-pusher",(function(){var e=new Promise((function(e){$.getScript("//cdn.jsdelivr.net/npm/pusher-js@7.0.3/dist/web/pusher.min.js",(function(){var t=new Pusher(o().forum.attribute("pusherKey"),{authEndpoint:o().forum.attribute("apiUrl")+"/pusher/auth",cluster:o().forum.attribute("pusherCluster"),auth:{headers:{"X-CSRF-Token":o().session.csrfToken}}});return e({channels:{main:t.subscribe("public"),user:o().session.user?t.subscribe("private-user"+o().session.user.id()):null},pusher:t})}))}));o().pusher=e,o().pushedUpdates=[],(0,n.extend)(i().prototype,"oncreate",(function(){o().pusher.then((function(e){e.pusher.bind("newPost",(function(e){var t=o().discussions.getParams();if(!t.q&&!t.sort&&!t.filter){if(t.tags){var n=o().store.getBy("tags","slug",t.tags);if(-1===e.tagIds.indexOf(n.id()))return}var s=String(e.discussionId);o().current.get("discussion")&&s===o().current.get("discussion").id()||-1!==o().pushedUpdates.indexOf(s)||(o().pushedUpdates.push(s),o().current.matches(d())&&o().setTitleCount(o().pushedUpdates.length),m.redraw())}}))}))})),(0,n.extend)(i().prototype,"onremove",(function(){o().pusher.then((function(e){e.pusher.unbind("newPost")}))})),(0,n.extend)(i().prototype,"view",(function(e){var t=this;if(o().pushedUpdates){var n=o().pushedUpdates.length;n&&e.children.unshift(f().component({className:"Button Button--block DiscussionList-update",onclick:function(){t.attrs.state.refresh(!1).then((function(){t.loadingUpdated=!1,o().pushedUpdates=[],o().setTitleCount(0),m.redraw()})),t.loadingUpdated=!0},loading:this.loadingUpdated},o().translator.trans("flarum-pusher.forum.discussion_list.show_updates_text",{count:n})))}})),(0,n.extend)(i().prototype,"addDiscussion",(function(e,t){var n=o().pushedUpdates.indexOf(t.id());-1!==n&&o().pushedUpdates.splice(n,1),o().current.matches(d())&&o().setTitleCount(o().pushedUpdates.length),m.redraw()})),(0,n.extend)(a().prototype,"oncreate",(function(){var e=this;o().pusher.then((function(t){t.pusher.bind("newPost",(function(t){var n=String(t.discussionId);if(e.discussion&&e.discussion.id()===n&&e.stream){var s=e.discussion.commentCount();o().store.find("discussions",e.discussion.id()).then((function(){e.stream.update().then(m.redraw),document.hasFocus()||(o().setTitleCount(Math.max(0,e.discussion.commentCount()-s)),$(window).one("focus",(function(){return o().setTitleCount(0)})))}))}}))}))})),(0,n.extend)(a().prototype,"onremove",(function(){o().pusher.then((function(e){e.pusher.unbind("newPost")}))})),(0,n.extend)(d().prototype,"actionItems",(function(e){e.remove("refresh")})),o().pusher.then((function(e){var t=e.channels;t.user&&t.user.bind("notification",(function(){o().session.user.pushAttributes({unreadNotificationCount:o().session.user.unreadNotificationCount()+1,newNotificationCount:o().session.user.newNotificationCount()+1}),o().notifications.clear(),m.redraw()}))}))}))})(),module.exports=t})();
|
|
//# sourceMappingURL=forum.js.map
|