mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 13:21:01 +08:00
DEV: Modernize chat getOwner usage (#23671)
See 8958b4f76af85ddc89c8a3b6434dcfbd4274d569 for motivation
This commit is contained in:
@ -26,7 +26,7 @@ import ChatMessagesLoader from "discourse/plugins/chat/discourse/lib/chat-messag
|
|||||||
import { cached, tracked } from "@glimmer/tracking";
|
import { cached, tracked } from "@glimmer/tracking";
|
||||||
import discourseDebounce from "discourse-common/lib/debounce";
|
import discourseDebounce from "discourse-common/lib/debounce";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
import {
|
import {
|
||||||
FUTURE,
|
FUTURE,
|
||||||
PAST,
|
PAST,
|
||||||
|
@ -6,7 +6,7 @@ import { cancel, next } from "@ember/runloop";
|
|||||||
import { cloneJSON } from "discourse-common/lib/object";
|
import { cloneJSON } from "discourse-common/lib/object";
|
||||||
import { chatComposerButtons } from "discourse/plugins/chat/discourse/lib/chat-composer-buttons";
|
import { chatComposerButtons } from "discourse/plugins/chat/discourse/lib/chat-composer-buttons";
|
||||||
import TextareaInteractor from "discourse/plugins/chat/discourse/lib/textarea-interactor";
|
import TextareaInteractor from "discourse/plugins/chat/discourse/lib/textarea-interactor";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
import userSearch from "discourse/lib/user-search";
|
import userSearch from "discourse/lib/user-search";
|
||||||
import { findRawTemplate } from "discourse-common/lib/raw-templates";
|
import { findRawTemplate } from "discourse-common/lib/raw-templates";
|
||||||
import { emojiSearch, isSkinTonableEmoji } from "pretty-text/emoji";
|
import { emojiSearch, isSkinTonableEmoji } from "pretty-text/emoji";
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import Component from "@glimmer/component";
|
import Component from "@glimmer/component";
|
||||||
import ChatMessageInteractor from "discourse/plugins/chat/discourse/lib/chat-message-interactor";
|
import ChatMessageInteractor from "discourse/plugins/chat/discourse/lib/chat-message-interactor";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
import { tracked } from "@glimmer/tracking";
|
import { tracked } from "@glimmer/tracking";
|
||||||
import discourseLater from "discourse-common/lib/later";
|
import discourseLater from "discourse-common/lib/later";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
|
@ -6,7 +6,7 @@ import { cancel, schedule } from "@ember/runloop";
|
|||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
import discourseLater from "discourse-common/lib/later";
|
import discourseLater from "discourse-common/lib/later";
|
||||||
import isZoomed from "discourse/plugins/chat/discourse/lib/zoom-check";
|
import isZoomed from "discourse/plugins/chat/discourse/lib/zoom-check";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
import ChatMessageInteractor from "discourse/plugins/chat/discourse/lib/chat-message-interactor";
|
import ChatMessageInteractor from "discourse/plugins/chat/discourse/lib/chat-message-interactor";
|
||||||
import discourseDebounce from "discourse-common/lib/debounce";
|
import discourseDebounce from "discourse-common/lib/debounce";
|
||||||
import { bind } from "discourse-common/utils/decorators";
|
import { bind } from "discourse-common/utils/decorators";
|
||||||
|
@ -10,7 +10,7 @@ import { inject as service } from "@ember/service";
|
|||||||
import { cancel, next } from "@ember/runloop";
|
import { cancel, next } from "@ember/runloop";
|
||||||
import { resetIdle } from "discourse/lib/desktop-notifications";
|
import { resetIdle } from "discourse/lib/desktop-notifications";
|
||||||
import ChatMessagesLoader from "discourse/plugins/chat/discourse/lib/chat-messages-loader";
|
import ChatMessagesLoader from "discourse/plugins/chat/discourse/lib/chat-messages-loader";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
import {
|
import {
|
||||||
FUTURE,
|
FUTURE,
|
||||||
PAST,
|
PAST,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Component from "@glimmer/component";
|
import Component from "@glimmer/component";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { clipboardCopyAsync } from "discourse/lib/utilities";
|
import { clipboardCopyAsync } from "discourse/lib/utilities";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
import { isTesting } from "discourse-common/config/environment";
|
import { isTesting } from "discourse-common/config/environment";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
|
@ -2,7 +2,7 @@ import Component from "@glimmer/component";
|
|||||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import ChatMessagesManager from "discourse/plugins/chat/discourse/lib/chat-messages-manager";
|
import ChatMessagesManager from "discourse/plugins/chat/discourse/lib/chat-messages-manager";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default class ChatStyleguideChatMessage extends Component {
|
export default class ChatStyleguideChatMessage extends Component {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import { bind } from "discourse-common/utils/decorators";
|
import { bind } from "discourse-common/utils/decorators";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwnerWithFallback } from "discourse-common/lib/get-owner";
|
||||||
import { MENTION_KEYWORDS } from "discourse/plugins/chat/discourse/components/chat-message";
|
import { MENTION_KEYWORDS } from "discourse/plugins/chat/discourse/components/chat-message";
|
||||||
import { clearChatComposerButtons } from "discourse/plugins/chat/discourse/lib/chat-composer-buttons";
|
import { clearChatComposerButtons } from "discourse/plugins/chat/discourse/lib/chat-composer-buttons";
|
||||||
import ChannelHashtagType from "discourse/plugins/chat/discourse/lib/hashtag-types/channel";
|
import ChannelHashtagType from "discourse/plugins/chat/discourse/lib/hashtag-types/channel";
|
||||||
@ -121,7 +121,9 @@ export default {
|
|||||||
// we want to decorate the chat quote dates regardless
|
// we want to decorate the chat quote dates regardless
|
||||||
// of whether the current user has chat enabled
|
// of whether the current user has chat enabled
|
||||||
api.decorateCookedElement((elem) => {
|
api.decorateCookedElement((elem) => {
|
||||||
const currentUser = getOwner(this).lookup("service:current-user");
|
const currentUser = getOwnerWithFallback(this).lookup(
|
||||||
|
"service:current-user"
|
||||||
|
);
|
||||||
const currentUserTimezone = currentUser?.user_option?.timezone;
|
const currentUserTimezone = currentUser?.user_option?.timezone;
|
||||||
const chatTranscriptElements =
|
const chatTranscriptElements =
|
||||||
elem.querySelectorAll(".chat-transcript");
|
elem.querySelectorAll(".chat-transcript");
|
||||||
|
@ -5,7 +5,7 @@ import { tracked } from "@glimmer/tracking";
|
|||||||
import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel";
|
import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel";
|
||||||
import ChatThreadsManager from "discourse/plugins/chat/discourse/lib/chat-threads-manager";
|
import ChatThreadsManager from "discourse/plugins/chat/discourse/lib/chat-threads-manager";
|
||||||
import ChatMessagesManager from "discourse/plugins/chat/discourse/lib/chat-messages-manager";
|
import ChatMessagesManager from "discourse/plugins/chat/discourse/lib/chat-messages-manager";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwnerWithFallback } from "discourse-common/lib/get-owner";
|
||||||
import guid from "pretty-text/guid";
|
import guid from "pretty-text/guid";
|
||||||
import ChatDirectMessage from "discourse/plugins/chat/discourse/models/chat-direct-message";
|
import ChatDirectMessage from "discourse/plugins/chat/discourse/models/chat-direct-message";
|
||||||
import ChatChannelArchive from "discourse/plugins/chat/discourse/models/chat-channel-archive";
|
import ChatChannelArchive from "discourse/plugins/chat/discourse/models/chat-channel-archive";
|
||||||
@ -70,8 +70,8 @@ export default class ChatChannel {
|
|||||||
@tracked tracking;
|
@tracked tracking;
|
||||||
@tracked threadingEnabled = false;
|
@tracked threadingEnabled = false;
|
||||||
|
|
||||||
threadsManager = new ChatThreadsManager(getOwner(this));
|
threadsManager = new ChatThreadsManager(getOwnerWithFallback(this));
|
||||||
messagesManager = new ChatMessagesManager(getOwner(this));
|
messagesManager = new ChatMessagesManager(getOwnerWithFallback(this));
|
||||||
|
|
||||||
@tracked _currentUserMembership;
|
@tracked _currentUserMembership;
|
||||||
@tracked _lastMessage;
|
@tracked _lastMessage;
|
||||||
@ -101,7 +101,7 @@ export default class ChatChannel {
|
|||||||
this.archive = ChatChannelArchive.create(args);
|
this.archive = ChatChannelArchive.create(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tracking = new ChatTrackingState(getOwner(this));
|
this.tracking = new ChatTrackingState(getOwnerWithFallback(this));
|
||||||
this.lastMessage = args.last_message;
|
this.lastMessage = args.last_message;
|
||||||
this.meta = args.meta;
|
this.meta = args.meta;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import Bookmark from "discourse/models/bookmark";
|
|||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import { generateCookFunction, parseMentions } from "discourse/lib/text";
|
import { generateCookFunction, parseMentions } from "discourse/lib/text";
|
||||||
import transformAutolinks from "discourse/plugins/chat/discourse/lib/transform-auto-links";
|
import transformAutolinks from "discourse/plugins/chat/discourse/lib/transform-auto-links";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwnerWithFallback } from "discourse-common/lib/get-owner";
|
||||||
import discourseLater from "discourse-common/lib/later";
|
import discourseLater from "discourse-common/lib/later";
|
||||||
|
|
||||||
export default class ChatMessage {
|
export default class ChatMessage {
|
||||||
@ -329,7 +329,7 @@ export default class ChatMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get #markdownOptions() {
|
get #markdownOptions() {
|
||||||
const site = getOwner(this).lookup("service:site");
|
const site = getOwnerWithFallback(this).lookup("service:site");
|
||||||
return {
|
return {
|
||||||
featuresOverride:
|
featuresOverride:
|
||||||
site.markdown_additional_options?.chat?.limited_pretty_text_features,
|
site.markdown_additional_options?.chat?.limited_pretty_text_features,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwnerWithFallback } from "discourse-common/lib/get-owner";
|
||||||
import ChatMessagesManager from "discourse/plugins/chat/discourse/lib/chat-messages-manager";
|
import ChatMessagesManager from "discourse/plugins/chat/discourse/lib/chat-messages-manager";
|
||||||
import { escapeExpression } from "discourse/lib/utilities";
|
import { escapeExpression } from "discourse/lib/utilities";
|
||||||
import { tracked } from "@glimmer/tracking";
|
import { tracked } from "@glimmer/tracking";
|
||||||
@ -33,7 +33,7 @@ export default class ChatThread {
|
|||||||
@tracked currentUserMembership = null;
|
@tracked currentUserMembership = null;
|
||||||
@tracked preview = null;
|
@tracked preview = null;
|
||||||
|
|
||||||
messagesManager = new ChatMessagesManager(getOwner(this));
|
messagesManager = new ChatMessagesManager(getOwnerWithFallback(this));
|
||||||
|
|
||||||
constructor(channel, args = {}) {
|
constructor(channel, args = {}) {
|
||||||
this.id = args.id;
|
this.id = args.id;
|
||||||
@ -55,7 +55,7 @@ export default class ChatThread {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tracking = new ChatTrackingState(getOwner(this));
|
this.tracking = new ChatTrackingState(getOwnerWithFallback(this));
|
||||||
this.preview = ChatThreadPreview.create(args.preview);
|
this.preview = ChatThreadPreview.create(args.preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import Service, { inject as service } from "@ember/service";
|
|||||||
import discourseDebounce from "discourse-common/lib/debounce";
|
import discourseDebounce from "discourse-common/lib/debounce";
|
||||||
import { cancel } from "@ember/runloop";
|
import { cancel } from "@ember/runloop";
|
||||||
import ChatTrackingState from "discourse/plugins/chat/discourse/models/chat-tracking-state";
|
import ChatTrackingState from "discourse/plugins/chat/discourse/models/chat-tracking-state";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This service is used to provide a global interface to tracking individual
|
* This service is used to provide a global interface to tracking individual
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import { module, test } from "qunit";
|
import { module, test } from "qunit";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
|
import { setupTest } from "ember-qunit";
|
||||||
|
|
||||||
module("Discourse Chat | Unit | chat-emoji-reaction-store", function (hooks) {
|
module("Discourse Chat | Unit | chat-emoji-reaction-store", function (hooks) {
|
||||||
|
setupTest(hooks);
|
||||||
|
|
||||||
hooks.beforeEach(function () {
|
hooks.beforeEach(function () {
|
||||||
this.siteSettings = getOwner(this).lookup("service:site-settings");
|
this.siteSettings = getOwner(this).lookup("service:site-settings");
|
||||||
this.chatEmojiReactionStore = getOwner(this).lookup(
|
this.chatEmojiReactionStore = getOwner(this).lookup(
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
import { module, test } from "qunit";
|
import { module, test } from "qunit";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
import { ORIGINS } from "discourse/plugins/chat/discourse/services/chat-channel-info-route-origin-manager";
|
import { ORIGINS } from "discourse/plugins/chat/discourse/services/chat-channel-info-route-origin-manager";
|
||||||
|
import { setupTest } from "ember-qunit";
|
||||||
|
|
||||||
module(
|
module(
|
||||||
"Discourse Chat | Unit | Service | chat-channel-info-route-origin-manager",
|
"Discourse Chat | Unit | Service | chat-channel-info-route-origin-manager",
|
||||||
function (hooks) {
|
function (hooks) {
|
||||||
|
setupTest(hooks);
|
||||||
|
|
||||||
hooks.beforeEach(function () {
|
hooks.beforeEach(function () {
|
||||||
this.manager = getOwner(this).lookup(
|
this.manager = getOwner(this).lookup(
|
||||||
"service:chat-channel-info-route-origin-manager"
|
"service:chat-channel-info-route-origin-manager"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { module, test } from "qunit";
|
import { module, test } from "qunit";
|
||||||
import { setupTest } from "ember-qunit";
|
import { setupTest } from "ember-qunit";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||||
|
|
||||||
module(
|
module(
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import { module, test } from "qunit";
|
import { module, test } from "qunit";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
|
import { setupTest } from "ember-qunit";
|
||||||
|
|
||||||
module("Discourse Chat | Unit | Service | chat-drawer-size", function (hooks) {
|
module("Discourse Chat | Unit | Service | chat-drawer-size", function (hooks) {
|
||||||
|
setupTest(hooks);
|
||||||
|
|
||||||
hooks.beforeEach(function () {
|
hooks.beforeEach(function () {
|
||||||
this.subject = getOwner(this).lookup("service:chat-drawer-size");
|
this.subject = getOwner(this).lookup("service:chat-drawer-size");
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { module, test } from "qunit";
|
import { module, test } from "qunit";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
import pretender from "discourse/tests/helpers/create-pretender";
|
import pretender from "discourse/tests/helpers/create-pretender";
|
||||||
import { settled } from "@ember/test-helpers";
|
import { settled } from "@ember/test-helpers";
|
||||||
|
import { setupTest } from "ember-qunit";
|
||||||
|
|
||||||
function emojisReponse() {
|
function emojisReponse() {
|
||||||
return { favorites: [{ name: "sad" }] };
|
return { favorites: [{ name: "sad" }] };
|
||||||
@ -10,6 +11,8 @@ function emojisReponse() {
|
|||||||
module(
|
module(
|
||||||
"Discourse Chat | Unit | Service | chat-emoji-picker-manager",
|
"Discourse Chat | Unit | Service | chat-emoji-picker-manager",
|
||||||
function (hooks) {
|
function (hooks) {
|
||||||
|
setupTest(hooks);
|
||||||
|
|
||||||
hooks.beforeEach(function () {
|
hooks.beforeEach(function () {
|
||||||
pretender.get("/chat/emojis.json", () => {
|
pretender.get("/chat/emojis.json", () => {
|
||||||
return [200, {}, emojisReponse()];
|
return [200, {}, emojisReponse()];
|
||||||
|
@ -2,7 +2,7 @@ import { module, test } from "qunit";
|
|||||||
import { setupTest } from "ember-qunit";
|
import { setupTest } from "ember-qunit";
|
||||||
import Site from "discourse/models/site";
|
import Site from "discourse/models/site";
|
||||||
import sinon from "sinon";
|
import sinon from "sinon";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
import {
|
import {
|
||||||
addChatDrawerStateCallback,
|
addChatDrawerStateCallback,
|
||||||
resetChatDrawerStateCallbacks,
|
resetChatDrawerStateCallbacks,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { setupTest } from "ember-qunit";
|
import { setupTest } from "ember-qunit";
|
||||||
import { module, test } from "qunit";
|
import { module, test } from "qunit";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "@ember/application";
|
||||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
import ChatMessageInteractor, {
|
import ChatMessageInteractor, {
|
||||||
|
Reference in New Issue
Block a user