mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 11:22:47 +08:00
DEV: Remove chat_channel_id from chat-live-pane details (#20302)
This is unnecessary indirection, we can just have the chat_channel_id in the message serializer and use that.
This commit is contained in:
parent
f19044af6a
commit
c65cdc0779
|
@ -14,13 +14,18 @@ class ChatMessageSerializer < ApplicationSerializer
|
||||||
:reactions,
|
:reactions,
|
||||||
:bookmark,
|
:bookmark,
|
||||||
:available_flags,
|
:available_flags,
|
||||||
:thread_id
|
:thread_id,
|
||||||
|
:chat_channel_id
|
||||||
|
|
||||||
has_one :user, serializer: BasicUserWithStatusSerializer, embed: :objects
|
has_one :user, serializer: BasicUserWithStatusSerializer, embed: :objects
|
||||||
has_one :chat_webhook_event, serializer: ChatWebhookEventSerializer, embed: :objects
|
has_one :chat_webhook_event, serializer: ChatWebhookEventSerializer, embed: :objects
|
||||||
has_one :in_reply_to, serializer: ChatInReplyToSerializer, embed: :objects
|
has_one :in_reply_to, serializer: ChatInReplyToSerializer, embed: :objects
|
||||||
has_many :uploads, serializer: UploadSerializer, embed: :objects
|
has_many :uploads, serializer: UploadSerializer, embed: :objects
|
||||||
|
|
||||||
|
def channel
|
||||||
|
@channel ||= @options.dig(:chat_channel) || object.chat_channel
|
||||||
|
end
|
||||||
|
|
||||||
def user
|
def user
|
||||||
object.user || DeletedChatUser.new
|
object.user || DeletedChatUser.new
|
||||||
end
|
end
|
||||||
|
@ -131,8 +136,6 @@ class ChatMessageSerializer < ApplicationSerializer
|
||||||
return [] if !scope.can_flag_chat_message?(object)
|
return [] if !scope.can_flag_chat_message?(object)
|
||||||
return [] if reviewable_id.present? && user_flag_status == ReviewableScore.statuses[:pending]
|
return [] if reviewable_id.present? && user_flag_status == ReviewableScore.statuses[:pending]
|
||||||
|
|
||||||
channel = @options.dig(:chat_channel) || object.chat_channel
|
|
||||||
|
|
||||||
PostActionType.flag_types.map do |sym, id|
|
PostActionType.flag_types.map do |sym, id|
|
||||||
next if channel.direct_message_channel? && %i[notify_moderators notify_user].include?(sym)
|
next if channel.direct_message_channel? && %i[notify_moderators notify_user].include?(sym)
|
||||||
|
|
||||||
|
|
|
@ -402,8 +402,6 @@ export default Component.extend({
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
messages: this._prepareMessages(messages),
|
messages: this._prepareMessages(messages),
|
||||||
details: {
|
details: {
|
||||||
chat_channel_id: this.chatChannel.id,
|
|
||||||
chatable_type: this.chatChannel.chatable_type,
|
|
||||||
can_delete_self: meta.can_delete_self,
|
can_delete_self: meta.can_delete_self,
|
||||||
can_delete_others: meta.can_delete_others,
|
can_delete_others: meta.can_delete_others,
|
||||||
can_flag: meta.can_flag,
|
can_flag: meta.can_flag,
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<span class="chat-message-info__date">
|
<span class="chat-message-info__date">
|
||||||
{{format-chat-date @message @details}}
|
{{format-chat-date @message}}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{{#if @message.bookmark}}
|
{{#if @message.bookmark}}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
<span class="chat-message-left-gutter__date">
|
<span class="chat-message-left-gutter__date">
|
||||||
{{format-chat-date @message @details "tiny"}}
|
{{format-chat-date @message "tiny"}}
|
||||||
</span>
|
</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if @message.bookmark}}
|
{{#if @message.bookmark}}
|
||||||
|
|
|
@ -115,14 +115,14 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if this.hideUserInfo}}
|
{{#if this.hideUserInfo}}
|
||||||
<ChatMessageLeftGutter @message={{@message}} @details={{@details}} />
|
<ChatMessageLeftGutter @message={{@message}} />
|
||||||
{{else}}
|
{{else}}
|
||||||
<ChatMessageAvatar @message={{@message}} />
|
<ChatMessageAvatar @message={{@message}} />
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<div class="chat-message-content">
|
<div class="chat-message-content">
|
||||||
{{#unless this.hideUserInfo}}
|
{{#unless this.hideUserInfo}}
|
||||||
<ChatMessageInfo @message={{@message}} @details={{@details}} />
|
<ChatMessageInfo @message={{@message}} />
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
||||||
<ChatMessageText
|
<ChatMessageText
|
||||||
|
|
|
@ -458,7 +458,7 @@ export default class ChatMessage extends Component {
|
||||||
inviteMentioned() {
|
inviteMentioned() {
|
||||||
const userIds = this.mentionWarning.without_membership.mapBy("id");
|
const userIds = this.mentionWarning.without_membership.mapBy("id");
|
||||||
|
|
||||||
ajax(`/chat/${this.args.details.chat_channel_id}/invite`, {
|
ajax(`/chat/${this.args.message.chat_channel_id}/invite`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
data: { user_ids: userIds, chat_message_id: this.args.message.id },
|
data: { user_ids: userIds, chat_message_id: this.args.message.id },
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
@ -607,7 +607,7 @@ export default class ChatMessage extends Component {
|
||||||
|
|
||||||
_publishReaction(emoji, reactAction) {
|
_publishReaction(emoji, reactAction) {
|
||||||
return ajax(
|
return ajax(
|
||||||
`/chat/${this.args.details.chat_channel_id}/react/${this.args.message.id}`,
|
`/chat/${this.args.message.chat_channel_id}/react/${this.args.message.id}`,
|
||||||
{
|
{
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
data: {
|
data: {
|
||||||
|
@ -686,7 +686,7 @@ export default class ChatMessage extends Component {
|
||||||
@action
|
@action
|
||||||
restore() {
|
restore() {
|
||||||
return ajax(
|
return ajax(
|
||||||
`/chat/${this.args.details.chat_channel_id}/restore/${this.args.message.id}`,
|
`/chat/${this.args.message.chat_channel_id}/restore/${this.args.message.id}`,
|
||||||
{
|
{
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
}
|
}
|
||||||
|
@ -730,7 +730,7 @@ export default class ChatMessage extends Component {
|
||||||
@action
|
@action
|
||||||
rebakeMessage() {
|
rebakeMessage() {
|
||||||
return ajax(
|
return ajax(
|
||||||
`/chat/${this.args.details.chat_channel_id}/${this.args.message.id}/rebake`,
|
`/chat/${this.args.message.chat_channel_id}/${this.args.message.id}/rebake`,
|
||||||
{
|
{
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
}
|
}
|
||||||
|
@ -740,7 +740,7 @@ export default class ChatMessage extends Component {
|
||||||
@action
|
@action
|
||||||
deleteMessage() {
|
deleteMessage() {
|
||||||
return ajax(
|
return ajax(
|
||||||
`/chat/${this.args.details.chat_channel_id}/${this.args.message.id}`,
|
`/chat/${this.args.message.chat_channel_id}/${this.args.message.id}`,
|
||||||
{
|
{
|
||||||
type: "DELETE",
|
type: "DELETE",
|
||||||
}
|
}
|
||||||
|
@ -775,7 +775,7 @@ export default class ChatMessage extends Component {
|
||||||
|
|
||||||
const { protocol, host } = window.location;
|
const { protocol, host } = window.location;
|
||||||
let url = getURL(
|
let url = getURL(
|
||||||
`/chat/c/-/${this.args.details.chat_channel_id}/${this.args.message.id}`
|
`/chat/c/-/${this.args.message.chat_channel_id}/${this.args.message.id}`
|
||||||
);
|
);
|
||||||
url = url.indexOf("/") === 0 ? protocol + "//" + host + url : url;
|
url = url.indexOf("/") === 0 ? protocol + "//" + host + url : url;
|
||||||
clipboardCopy(url);
|
clipboardCopy(url);
|
||||||
|
|
|
@ -4,22 +4,14 @@ import getURL from "discourse-common/lib/get-url";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
|
|
||||||
registerUnbound("format-chat-date", function (message, details, mode) {
|
registerUnbound("format-chat-date", function (message, mode) {
|
||||||
let currentUser = User.current();
|
const currentUser = User.current();
|
||||||
|
const tz = currentUser ? currentUser.user_option.timezone : moment.tz.guess();
|
||||||
|
const date = moment(new Date(message.created_at), tz);
|
||||||
|
const url = getURL(`/chat/c/-/${message.chat_channel_id}/${message.id}`);
|
||||||
|
const title = date.format(I18n.t("dates.long_with_year"));
|
||||||
|
|
||||||
let tz = currentUser ? currentUser.user_option.timezone : moment.tz.guess();
|
const display =
|
||||||
|
|
||||||
let date = moment(new Date(message.created_at), tz);
|
|
||||||
|
|
||||||
let url = "";
|
|
||||||
|
|
||||||
if (details) {
|
|
||||||
url = getURL(`/chat/c/-/${details.chat_channel_id}/${message.id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
let title = date.format(I18n.t("dates.long_with_year"));
|
|
||||||
|
|
||||||
let display =
|
|
||||||
mode === "tiny"
|
mode === "tiny"
|
||||||
? date.format(I18n.t("chat.dates.time_tiny"))
|
? date.format(I18n.t("chat.dates.time_tiny"))
|
||||||
: date.format(I18n.t("dates.time"));
|
: date.format(I18n.t("dates.time"));
|
||||||
|
|
|
@ -8,9 +8,8 @@ module("Discourse Chat | Unit | Helpers | format-chat-date", function (hooks) {
|
||||||
setupRenderingTest(hooks);
|
setupRenderingTest(hooks);
|
||||||
|
|
||||||
test("link to chat message", async function (assert) {
|
test("link to chat message", async function (assert) {
|
||||||
this.set("details", { chat_channel_id: 1 });
|
this.set("message", { id: 1, chat_channel_id: 1 });
|
||||||
this.set("message", { id: 1 });
|
await render(hbs`{{format-chat-date this.message}}`);
|
||||||
await render(hbs`{{format-chat-date this.message this.details}}`);
|
|
||||||
|
|
||||||
assert.equal(query(".chat-time").getAttribute("href"), "/chat/c/-/1/1");
|
assert.equal(query(".chat-time").getAttribute("href"), "/chat/c/-/1/1");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user