define("discourse/plugins/discourse-presence/discourse/components/composer-presence-display",["exports","discourse/plugins/discourse-presence/discourse/lib/presence","@ember/runloop","discourse-common/utils/decorators","@ember/object/computed","@ember/component","@ember/service"],(function(e,s,t,r,i,n,c){"use strict";var o,a,l,u,p,d,h,b,m;function f(e,s,t,r,i){var n={};return Object.keys(r).forEach((function(e){n[e]=r[e]})),n.enumerable=!!n.enumerable,n.configurable=!!n.configurable,("value"in n||n.initializer)&&(n.writable=!0),n=t.slice().reverse().reduce((function(t,r){return r(e,s,t)||t}),n),i&&void 0!==n.initializer&&(n.value=n.initializer?n.initializer.call(i):void 0,n.initializer=void 0),void 0===n.initializer&&(Object.defineProperty(e,s,n),n=null),n}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var g=n.default.extend((o=(0,r.default)("model.topic.id"),a=(0,r.default)("model.topic.id"),l=(0,r.on)("didInsertElement"),u=(0,r.default)("model.post.id","editingUsers.@each.last_seen","users.@each.last_seen","isReply","isEdit"),p=(0,r.observes)("model.reply","model.title"),d=(0,r.observes)("model.whisper"),h=(0,r.observes)("model.action","model.topic.id"),b=(0,r.on)("willDestroyElement"),f(m={presenceManager:(0,c.inject)(),users:function(e){return this.presenceManager.users(e)},editingUsers:function(e){return this.presenceManager.editingUsers(e)},isReply:(0,i.readOnly)("model.replyingToTopic"),isEdit:(0,i.readOnly)("model.editingPost"),subscribe:function(){this.presenceManager.subscribe(this.get("model.topic.id"),s.COMPOSER_TYPE)},presenceUsers:function(e,s,t,r,i){return i?s.filterBy("post_id",e):r?t:[]},shouldDisplay:(0,i.gt)("presenceUsers.length",0),typing:function(){(0,t.throttle)(this,this._typing,1e3*s.KEEP_ALIVE_DURATION_SECONDS)},_typing:function(){if((this.isReply||this.isEdit)&&this.get("model.composerOpened")){var e={topicId:this.get("model.topic.id"),state:this.isEdit?s.EDITING:s.REPLYING,whisper:this.get("model.whisper"),postId:this.get("model.post.id"),presenceStaffOnly:this.get("model._presenceStaffOnly")};this._prevPublishData=e,this._throttle=this.presenceManager.publish(e.topicId,e.state,e.whisper,e.postId,e.presenceStaffOnly)}},cancelThrottle:function(){this._cancelThrottle()},composerState:function(){this._prevPublishData&&(this.presenceManager.publish(this._prevPublishData.topicId,s.CLOSED,this._prevPublishData.whisper,this._prevPublishData.postId),this._prevPublishData=null)},closeComposer:function(){this._cancelThrottle(),this._prevPublishData=null,this.presenceManager.cleanUpPresence(s.COMPOSER_TYPE)},_cancelThrottle:function(){this._throttle&&((0,t.cancel)(this._throttle),this._throttle=null)}},"users",[o],Object.getOwnPropertyDescriptor(m,"users"),m),f(m,"editingUsers",[a],Object.getOwnPropertyDescriptor(m,"editingUsers"),m),f(m,"subscribe",[l],Object.getOwnPropertyDescriptor(m,"subscribe"),m),f(m,"presenceUsers",[u],Object.getOwnPropertyDescriptor(m,"presenceUsers"),m),f(m,"typing",[p],Object.getOwnPropertyDescriptor(m,"typing"),m),f(m,"cancelThrottle",[d],Object.getOwnPropertyDescriptor(m,"cancelThrottle"),m),f(m,"composerState",[h],Object.getOwnPropertyDescriptor(m,"composerState"),m),f(m,"closeComposer",[b],Object.getOwnPropertyDescriptor(m,"closeComposer"),m),m));e.default=g})),define("discourse/plugins/discourse-presence/discourse/components/topic-presence-display",["exports","discourse-common/utils/decorators","@ember/component","discourse/plugins/discourse-presence/discourse/lib/presence","@ember/object/computed","@ember/service"],(function(e,s,t,r,i,n){"use strict";var c,o,a,l;function u(e,s,t,r,i){var n={};return Object.keys(r).forEach((function(e){n[e]=r[e]})),n.enumerable=!!n.enumerable,n.configurable=!!n.configurable,("value"in n||n.initializer)&&(n.writable=!0),n=t.slice().reverse().reduce((function(t,r){return r(e,s,t)||t}),n),i&&void 0!==n.initializer&&(n.value=n.initializer?n.initializer.call(i):void 0,n.initializer=void 0),void 0===n.initializer&&(Object.defineProperty(e,s,n),n=null),n}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var p=t.default.extend((c=(0,s.default)("topic.id"),o=(0,s.on)("didInsertElement"),a=(0,s.on)("willDestroyElement"),l={topic:null,topicId:null,presenceManager:(0,n.inject)(),users:function(e){return this.presenceManager.users(e)},shouldDisplay:(0,i.gt)("users.length",0),didReceiveAttrs:function(){this._super.apply(this,arguments),this.topicId&&this.presenceManager.unsubscribe(this.topicId,r.TOPIC_TYPE),this.set("topicId",this.get("topic.id"))},subscribe:function(){this.set("topicId",this.get("topic.id")),this.presenceManager.subscribe(this.get("topic.id"),r.TOPIC_TYPE)},_destroyed:function(){this.presenceManager.unsubscribe(this.get("topic.id"),r.TOPIC_TYPE)}},u(l,"users",[c],Object.getOwnPropertyDescriptor(l,"users"),l),u(l,"subscribe",[o],Object.getOwnPropertyDescriptor(l,"subscribe"),l),u(l,"_destroyed",[a],Object.getOwnPropertyDescriptor(l,"_destroyed"),l),l));e.default=p})),define("discourse/plugins/discourse-presence/discourse/lib/presence",["exports","@ember/runloop","@ember/object","discourse/lib/ajax","discourse-common/utils/decorators"],(function(e,s,t,r,i){"use strict";var n,c;Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.COMPOSER_TYPE=e.TOPIC_TYPE=e.CLOSED=e.EDITING=e.REPLYING=e.KEEP_ALIVE_DURATION_SECONDS=void 0;e.KEEP_ALIVE_DURATION_SECONDS=10;var o="replying";e.REPLYING=o;var a="editing";e.EDITING=a;var l="closed";e.CLOSED=l;e.TOPIC_TYPE="topic";e.COMPOSER_TYPE="composer";var u,p,d,h,b,m,f=t.default.extend((n=(0,i.default)("topicId"),c={users:null,editingUsers:null,subscribers:null,topicId:null,currentUser:null,messageBus:null,siteSettings:null,init:function(){this._super.apply(this,arguments),this.setProperties({users:[],editingUsers:[],subscribers:new Set})},subscribe:function(e){var s=this;0===this.subscribers.size&&this.messageBus.subscribe(this.channel,(function(e){var t=e.user,r=e.state;if(s.get("currentUser.id")!==t.id)switch(r){case o:s._appendUser(s.users,t);break;case a:s._appendUser(s.editingUsers,t,{post_id:parseInt(e.post_id,10)});break;case l:s._removeUser(t)}}),0),this.subscribers.add(e)},unsubscribe:function(e){this.subscribers.delete(e);var s=0===this.subscribers.size;return s&&(this.messageBus.unsubscribe(this.channel),this._stopTimer(),this.setProperties({users:[],editingUsers:[]})),s},channel:function(e){return"/presence/".concat(e)},publish:function(e,s,t,i){var n=this.get("currentUser.user_option.hide_profile_and_presence");if(void 0===n&&(n=this.get("currentUser.hide_profile_and_presence")),!n||!this.get("siteSettings.allow_users_to_hide_profile")){var c={state:e,topic_id:this.topicId};return s&&(c.is_whisper=!0),t&&e===a&&(c.post_id=t),i&&(c.staff_only=!0),(0,r.ajax)("/presence/publish",{type:"POST",data:c})}},_removeUser:function(e){[this.users,this.editingUsers].forEach((function(s){var t=s.findBy("id",e.id);t&&s.removeObject(t)}))},_cleanUpUsers:function(){return[this.users,this.editingUsers].forEach((function(e){var s=[];e.forEach((function(e){e.last_seen<=Date.now()-12e3&&s.push(e)})),e.removeObjects(s)})),0===this.users.length&&0===this.editingUsers.length},_appendUser:function(e,s,r){var i,n=this,c=0;e.forEach((function(e){e.id===s.id&&(i=e),r&&r.post_id?e.post_id===r.post_id&&c++:c++}));var o=r||{};if(o.last_seen=Date.now(),i)i.setProperties(o);else{var a=this.get("siteSettings.presence_max_users_shown");c