From 5c9bb73ffe49ad37281a55b83aca2f30de1448d4 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Sat, 3 Dec 2022 18:35:54 +0100 Subject: [PATCH] DEV: Remove discobot pm scrolling code (#19300) 1. Originally the feature did "Scroll to new posts when user is near bottom of PM" (74e188992483e8d55376a98b33a440c022c098de) 2. Then that feature was limited to "Only scroll to posts that are not your own in PMs." (4a2656192733ca84de8a702cbaf2c36651bf2368) 3. It was limited further to "Only scroll PMs on new message" (eaf7746ec9c73ea41cbf94775a9a6f842076cad7) 4. And later to "only scroll to bottom for discobot" (267d129f38d6d45d0863014bf93ad1bf932c70b3) 5. And the code was relegated to new-user-narrative plugin (48b7696dbc96e2d49a1d7ee84b68c1754bfaa0ea) 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. --- .../initializers/new-user-narrative.js | 56 ------------------- 1 file changed, 56 deletions(-) diff --git a/plugins/discourse-narrative-bot/assets/javascripts/initializers/new-user-narrative.js b/plugins/discourse-narrative-bot/assets/javascripts/initializers/new-user-narrative.js index 234e7ec2066..ef3241193a4 100644 --- a/plugins/discourse-narrative-bot/assets/javascripts/initializers/new-user-narrative.js +++ b/plugins/discourse-narrative-bot/assets/javascripts/initializers/new-user-narrative.js @@ -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;