Files
discourse/plugins/chat/assets/javascripts/discourse/services/chat-thread-composer.js
Joffrey JAFFEUX f9eae75972 DEV: improves keyboard sizing (#26372)
This commit is making the following changes:

- replaces `mobile-keyboard` initializer and `chat-vh` with a new template-less component: `d-vh`
- ensures body scroll lock is released when page/tab focus changes
- correctly locks body on chat channels and chat threads when composer is focused
- removes `bodyScrollFix` as we now use body scroll lock
- `onViewportResize` has been debounced to ensure it's not a bad performance vector
- adds a reverse option do body scroll lock, this is made to support reversed scroll areas (like chat channels and threads)

---------

Co-authored-by: Penar Musaraj <pmusaraj@gmail.com>
2024-03-27 08:50:32 +01:00

54 lines
1.2 KiB
JavaScript

import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import { schedule } from "@ember/runloop";
import Service, { service } from "@ember/service";
import { disableBodyScroll } from "discourse/lib/body-scroll-lock";
export default class ChatThreadComposer extends Service {
@service chat;
@service capabilities;
@service appEvents;
@tracked textarea;
@tracked scrollable;
init() {
super.init(...arguments);
this.appEvents.on("discourse:focus-changed", this, this.blur);
}
willDestroy() {
super.willDestroy(...arguments);
this.appEvents.off("discourse:focus-changed", this, this.blur);
}
@action
focus(options = {}) {
this.textarea?.focus(options);
schedule("afterRender", () => {
if (this.capabilities.isIOS && !this.capabilities.isIpadOS) {
disableBodyScroll(this.scrollable, { reverse: true });
}
});
}
@action
blur() {
this.textarea?.blur();
}
@action
edit(message) {
this.chat.activeMessage = null;
message.editing = true;
message.thread.draft = message;
this.focus({ refreshHeight: true, ensureAtEnd: true });
}
@action
replyTo() {
this.chat.activeMessage = null;
}
}