framework/extensions/pusher/js/dist/forum.js

2 lines
3.6 KiB
JavaScript
Raw Normal View History

(()=>{var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},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 s=flarum.core.compat["forum/app"];var n=e.n(s);const o=flarum.core.compat["common/extend"],r=flarum.core.compat["forum/components/DiscussionList"];var i=e.n(r);const u=flarum.core.compat["forum/components/DiscussionPage"];var a=e.n(u);const c=flarum.core.compat["forum/components/IndexPage"];var d=e.n(c);const p=flarum.core.compat["common/components/Button"];var l=e.n(p);n().initializers.add("flarum-pusher",(()=>{n().pusher=(async()=>{await import("//cdn.jsdelivr.net/npm/pusher-js@7.0.3/dist/web/pusher.min.js");const e=new Pusher(n().forum.attribute("pusherKey"),{authEndpoint:"".concat(n().forum.attribute("apiUrl"),"/pusher/auth"),cluster:n().forum.attribute("pusherCluster"),auth:{headers:{"X-CSRF-Token":n().session.csrfToken}}});return{channels:{main:e.subscribe("public"),user:n().session.user?e.subscribe("private-user".concat(n().session.user.id())):null},pusher:e}})(),n().pushedUpdates=[],(0,o.extend)(i().prototype,"oncreate",(function(){n().pusher.then((e=>{e.pusher.bind("newPost",(e=>{const t=n().discussions.getParams();if(!t.q&&!t.sort&&!t.filter){if(t.tags){const s=n().store.getBy("tags","slug",t.tags),o=null==s?void 0:s.id();if(!o||!e.tagIds.includes(o))return}const s=String(e.discussionId);n().current.get("discussion")&&s===n().current.get("discussion").id()||-1!==n().pushedUpdates.indexOf(s)||(n().pushedUpdates.push(s),n().current.matches(d())&&n().setTitleCount(n().pushedUpdates.length),m.redraw())}}))}))})),(0,o.extend)(i().prototype,"onremove",(function(){n().pusher.then((e=>{e.pusher.unbind("newPost")}))})),(0,o.extend)(i().prototype,"view",(function(e){if(n().pushedUpdates){const t=n().pushedUpdates.length;t&&"object"==typeof e&&e&&"children"in e&&e.children instanceof Array&&e.children.unshift(m(l(),{className:"Button Button--block DiscussionList-update",onclick:()=>{this.attrs.state.refresh().then((()=>{this.loadingUpdated=!1,n().pushedUpdates=[],n().setTitleCount(0),m.redraw()})),this.loadingUpdated=!0},loading:this.loadingUpdated},n().translator.trans("flarum-pusher.forum.discussion_list.show_updates_text",{count:t})))}})),(0,o.extend)(a().prototype,"oncreate",(function(){n().pusher.then((e=>{e.pusher.bind("newPost",(e=>{var t;const s=String(e.discussionId),o=null==(t=this.discussion)?void 0:t.id();if(this.discussion&&o===s&&this.stream){var r;const e=null!=(r=this.discussion.commentCount())?r:0;n().store.find("discussions",o).then((()=>{var t,s,o;null==(t=this.stream)||t.update().then(m.redraw),document.hasFocus()||(n().setTitleCount(Math.max(0,(null!=(s=null==(o=this.discussion)?void 0:o.commentCount())?s:0)-e)),window.addEventListener("focus",(()=>n().setTitleCount(0)),{once:!0}))}))}}))}))})),(0,o.extend)(a().prototype,"onremove",(function(){n().pusher.then((e=>{e.pusher.unbind("newPost")}))})),(0,o.extend)(d().prototype,"actionItems",(e=>{e.remove("refresh")})),n().pusher.then((e=>{const t=e.channels;t.user&&t.user.bind("notification",(()=>{var e,t;n().session.user&&n().session.user.pushAttributes({unreadNotificationCount:null!=(e=n().session.user.unreadNotificationCount())?e:1,newNotificationCount:null!=(t=n().session.user.newNotificationCount())?t:1}),n().notifications.clear(),m.redraw()}))}))}))})(),module.exports=t})();
//# sourceMappingURL=forum.js.map