framework/extensions/pusher/js/dist/forum.js
flarum-bot caefacbecd Bundled output for commit a47bd2d457
Includes transpiled JS/TS, and Typescript declaration files (typings).

[skip ci]
2024-10-19 17:44:34 +00:00

2 lines
3.3 KiB
JavaScript
Generated

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