mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 01:31:35 +08:00
missing prettified files
This commit is contained in:
@ -1,5 +1,9 @@
|
||||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { default as computed, observes, on } from 'ember-addons/ember-computed-decorators';
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import {
|
||||
default as computed,
|
||||
observes,
|
||||
on
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
|
||||
export const keepAliveDuration = 10000;
|
||||
export const bufferTime = 3000;
|
||||
@ -20,90 +24,103 @@ export default Ember.Component.extend({
|
||||
presenceUsers: null,
|
||||
channel: null,
|
||||
|
||||
@on('didInsertElement')
|
||||
@on("didInsertElement")
|
||||
composerOpened() {
|
||||
this._lastPublish = new Date();
|
||||
Ember.run.once(this, 'updateState');
|
||||
Ember.run.once(this, "updateState");
|
||||
},
|
||||
|
||||
@observes('action', 'post.id', 'topic.id')
|
||||
@observes("action", "post.id", "topic.id")
|
||||
composerStateChanged() {
|
||||
Ember.run.once(this, 'updateState');
|
||||
Ember.run.once(this, "updateState");
|
||||
},
|
||||
|
||||
@observes('reply', 'title')
|
||||
@observes("reply", "title")
|
||||
typing() {
|
||||
if (new Date() - this._lastPublish > keepAliveDuration) {
|
||||
this.publish({ current: this.get('currentState') });
|
||||
this.publish({ current: this.get("currentState") });
|
||||
}
|
||||
},
|
||||
|
||||
@on('willDestroyElement')
|
||||
@on("willDestroyElement")
|
||||
composerClosing() {
|
||||
this.publish({ previous: this.get('currentState') });
|
||||
this.publish({ previous: this.get("currentState") });
|
||||
Ember.run.cancel(this._pingTimer);
|
||||
Ember.run.cancel(this._clearTimer);
|
||||
},
|
||||
|
||||
updateState() {
|
||||
let state = null;
|
||||
const action = this.get('action');
|
||||
const action = this.get("action");
|
||||
|
||||
if (action === 'reply' || action === 'edit') {
|
||||
if (action === "reply" || action === "edit") {
|
||||
state = { action };
|
||||
if (action === 'reply') state.topic_id = this.get('topic.id');
|
||||
if (action === 'edit') state.post_id = this.get('post.id');
|
||||
if (action === "reply") state.topic_id = this.get("topic.id");
|
||||
if (action === "edit") state.post_id = this.get("post.id");
|
||||
}
|
||||
|
||||
this.set('previousState', this.get('currentState'));
|
||||
this.set('currentState', state);
|
||||
this.set("previousState", this.get("currentState"));
|
||||
this.set("currentState", state);
|
||||
},
|
||||
|
||||
@observes('currentState')
|
||||
@observes("currentState")
|
||||
currentStateChanged() {
|
||||
if (this.get('channel')) {
|
||||
this.messageBus.unsubscribe(this.get('channel'));
|
||||
this.set('channel', null);
|
||||
if (this.get("channel")) {
|
||||
this.messageBus.unsubscribe(this.get("channel"));
|
||||
this.set("channel", null);
|
||||
}
|
||||
|
||||
this.clear();
|
||||
|
||||
if (!['reply', 'edit'].includes(this.get('action'))) {
|
||||
if (!["reply", "edit"].includes(this.get("action"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.publish({
|
||||
response_needed: true,
|
||||
previous: this.get('previousState'),
|
||||
current: this.get('currentState')
|
||||
previous: this.get("previousState"),
|
||||
current: this.get("currentState")
|
||||
}).then(r => {
|
||||
if (this.get('isDestroyed')) { return; }
|
||||
this.set('presenceUsers', r.users);
|
||||
this.set('channel', r.messagebus_channel);
|
||||
if (this.get("isDestroyed")) {
|
||||
return;
|
||||
}
|
||||
this.set("presenceUsers", r.users);
|
||||
this.set("channel", r.messagebus_channel);
|
||||
|
||||
if (!r.messagebus_channel) { return; }
|
||||
if (!r.messagebus_channel) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.messageBus.subscribe(r.messagebus_channel, message => {
|
||||
if (!this.get('isDestroyed')) this.set('presenceUsers', message.users);
|
||||
this._clearTimer = Ember.run.debounce(this, 'clear', keepAliveDuration + bufferTime);
|
||||
}, r.messagebus_id);
|
||||
this.messageBus.subscribe(
|
||||
r.messagebus_channel,
|
||||
message => {
|
||||
if (!this.get("isDestroyed"))
|
||||
this.set("presenceUsers", message.users);
|
||||
this._clearTimer = Ember.run.debounce(
|
||||
this,
|
||||
"clear",
|
||||
keepAliveDuration + bufferTime
|
||||
);
|
||||
},
|
||||
r.messagebus_id
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
clear() {
|
||||
if (!this.get('isDestroyed')) this.set('presenceUsers', []);
|
||||
if (!this.get("isDestroyed")) this.set("presenceUsers", []);
|
||||
},
|
||||
|
||||
publish(data) {
|
||||
this._lastPublish = new Date();
|
||||
return ajax('/presence/publish', { type: 'POST', data });
|
||||
return ajax("/presence/publish", { type: "POST", data });
|
||||
},
|
||||
|
||||
@computed('presenceUsers', 'currentUser.id')
|
||||
@computed("presenceUsers", "currentUser.id")
|
||||
users(users, currentUserId) {
|
||||
return (users || []).filter(user => user.id !== currentUserId);
|
||||
},
|
||||
|
||||
isReply: Ember.computed.equal('action', 'reply'),
|
||||
shouldDisplay: Ember.computed.gt('users.length', 0)
|
||||
isReply: Ember.computed.equal("action", "reply"),
|
||||
shouldDisplay: Ember.computed.gt("users.length", 0)
|
||||
});
|
||||
|
@ -1,5 +1,11 @@
|
||||
import { default as computed, on } from 'ember-addons/ember-computed-decorators';
|
||||
import { keepAliveDuration, bufferTime } from 'discourse/plugins/discourse-presence/discourse/components/composer-presence-display';
|
||||
import {
|
||||
default as computed,
|
||||
on
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import {
|
||||
keepAliveDuration,
|
||||
bufferTime
|
||||
} from "discourse/plugins/discourse-presence/discourse/components/composer-presence-display";
|
||||
|
||||
const MB_GET_LAST_MESSAGE = -2;
|
||||
|
||||
@ -8,35 +14,42 @@ export default Ember.Component.extend({
|
||||
presenceUsers: null,
|
||||
|
||||
clear() {
|
||||
if (!this.get('isDestroyed')) this.set('presenceUsers', []);
|
||||
if (!this.get("isDestroyed")) this.set("presenceUsers", []);
|
||||
},
|
||||
|
||||
@on('didInsertElement')
|
||||
@on("didInsertElement")
|
||||
_inserted() {
|
||||
this.clear();
|
||||
|
||||
this.messageBus.subscribe(this.get('channel'), message => {
|
||||
if (!this.get('isDestroyed')) this.set('presenceUsers', message.users);
|
||||
this._clearTimer = Ember.run.debounce(this, 'clear', keepAliveDuration + bufferTime);
|
||||
}, MB_GET_LAST_MESSAGE);
|
||||
this.messageBus.subscribe(
|
||||
this.get("channel"),
|
||||
message => {
|
||||
if (!this.get("isDestroyed")) this.set("presenceUsers", message.users);
|
||||
this._clearTimer = Ember.run.debounce(
|
||||
this,
|
||||
"clear",
|
||||
keepAliveDuration + bufferTime
|
||||
);
|
||||
},
|
||||
MB_GET_LAST_MESSAGE
|
||||
);
|
||||
},
|
||||
|
||||
@on('willDestroyElement')
|
||||
@on("willDestroyElement")
|
||||
_destroyed() {
|
||||
Ember.run.cancel(this._clearTimer);
|
||||
this.messageBus.unsubscribe(this.get('channel'));
|
||||
this.messageBus.unsubscribe(this.get("channel"));
|
||||
},
|
||||
|
||||
@computed('topicId')
|
||||
@computed("topicId")
|
||||
channel(topicId) {
|
||||
return `/presence/topic/${topicId}`;
|
||||
},
|
||||
|
||||
@computed('presenceUsers', 'currentUser.id')
|
||||
@computed("presenceUsers", "currentUser.id")
|
||||
users(users, currentUserId) {
|
||||
return (users || []).filter(user => user.id !== currentUserId);
|
||||
},
|
||||
|
||||
shouldDisplay: Ember.computed.gt('users.length', 0)
|
||||
|
||||
shouldDisplay: Ember.computed.gt("users.length", 0)
|
||||
});
|
||||
|
Reference in New Issue
Block a user