DEV: Remove discobot pm scrolling code (#19300)
1. Originally the feature did "Scroll to new posts when user is near bottom of PM" (74e1889924
) 2. Then that feature was limited to "Only scroll to posts that are not your own in PMs." (4a26561927
) 3. It was limited further to "Only scroll PMs on new message" (eaf7746ec9
) 4. And later to "only scroll to bottom for discobot" (267d129f38
) 5. And the code was relegated to new-user-narrative plugin (48b7696dbc
) I don't think it's worth it to keep this scrolling code just for this very small specific case. This did potentially confict with other post scrolling code, and also using `modifyClass` is something we'd like to avoid.
This commit is contained in:
parent
a72c9b96ab
commit
5c9bb73ffe
|
@ -1,6 +1,3 @@
|
|||
import { debounce } from "discourse-common/utils/decorators";
|
||||
import { headerOffset } from "discourse/lib/offset-calculator";
|
||||
import isElementInViewport from "discourse/lib/is-element-in-viewport";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
|
||||
const PLUGIN_ID = "new-user-narrative";
|
||||
|
@ -18,59 +15,6 @@ function initialize(api) {
|
|||
},
|
||||
});
|
||||
|
||||
api.modifyClass("controller:topic", {
|
||||
pluginId: PLUGIN_ID,
|
||||
|
||||
subscribe() {
|
||||
this._super(...arguments);
|
||||
|
||||
this.messageBus.subscribe(`/topic/${this.model.id}`, (data) => {
|
||||
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;
|
||||
|
||||
if (
|
||||
notInPostStream &&
|
||||
postNumberDifference > 0 &&
|
||||
postNumberDifference < 7
|
||||
) {
|
||||
this._scrollToDiscobotPost(data.post_number);
|
||||
}
|
||||
}
|
||||
});
|
||||
// No need to unsubscribe, core unsubscribes /topic/* routes
|
||||
},
|
||||
|
||||
@debounce(500)
|
||||
_scrollToDiscobotPost(postNumber) {
|
||||
const post = document.querySelector(
|
||||
`.topic-post article#post_${postNumber}`
|
||||
);
|
||||
|
||||
if (!post || isElementInViewport(post)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const viewportOffset = post.getBoundingClientRect();
|
||||
|
||||
window.scrollTo({
|
||||
top: window.scrollY + viewportOffset.top - headerOffset(),
|
||||
behavior: "smooth",
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
api.attachWidgetAction("header", "headerSearchContextTrigger", function () {
|
||||
if (this.site.mobileView) {
|
||||
this.state.skipSearchContext = false;
|
||||
|
|
Loading…
Reference in New Issue