Revert "DEV: Clean up all message bus subscriptions (#18675)" (#19267)

This reverts commit b0839ccf27217d9a2be6866a6ac7e824d5104474.
This commit is contained in:
Jarek Radosz
2022-11-30 17:29:10 +01:00
committed by GitHub
parent 6a389fd15a
commit 49e0fc04f7
21 changed files with 496 additions and 624 deletions

View File

@ -1,4 +1,4 @@
import { bind, debounce } from "discourse-common/utils/decorators";
import { debounce } from "discourse-common/utils/decorators";
import { ajax } from "discourse/lib/ajax";
import { headerOffset } from "discourse/lib/offset-calculator";
import isElementInViewport from "discourse/lib/is-element-in-viewport";
@ -43,32 +43,35 @@ function initialize(api) {
return this._super(bookmark, post);
},
@bind
onMessage(data) {
subscribe() {
this._super(...arguments);
const topic = this.model;
// scroll only for discobot (-2 is discobot id)
if (
topic.isPrivateMessage &&
this.currentUser &&
this.currentUser.id !== data.user_id &&
data.user_id === -2 &&
data.type === "created"
) {
const postNumber = data.post_number;
const notInPostStream = topic.get("highest_post_number") <= postNumber;
const postNumberDifference = postNumber - topic.currentPost;
this.messageBus.subscribe(`/topic/${this.model.id}`, (data) => {
const topic = this.model;
// scroll only for discobot (-2 is discobot id)
if (
notInPostStream &&
postNumberDifference > 0 &&
postNumberDifference < 7
topic.isPrivateMessage &&
this.currentUser &&
this.currentUser.id !== data.user_id &&
data.user_id === -2 &&
data.type === "created"
) {
this._scrollToDiscobotPost(data.post_number);
const postNumber = data.post_number;
const notInPostStream =
topic.get("highest_post_number") <= postNumber;
const postNumberDifference = postNumber - topic.currentPost;
if (
notInPostStream &&
postNumberDifference > 0 &&
postNumberDifference < 7
) {
this._scrollToDiscobotPost(data.post_number);
}
}
}
});
// No need to unsubscribe, core unsubscribes /topic/* routes
},
@debounce(500)