mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Previously if you linked to a chat thread inline, our oneboxer did not have special handling for this, so the link would end up with the text "Chat #channel-name" which is not ideal for a thread. This commit makes it so the thread onebox is in the format "Thread title - #channel-name" if the thread title exists, otherwise we show "Thread in #channel-name"
53 lines
1.4 KiB
Ruby
53 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Chat
|
|
class InlineOneboxHandler
|
|
def self.handle(url, route)
|
|
if route[:message_id].present?
|
|
message = Chat::Message.find_by(id: route[:message_id])
|
|
return if !message
|
|
|
|
chat_channel = message.chat_channel
|
|
user = message.user
|
|
return if !chat_channel || !user
|
|
|
|
title =
|
|
I18n.t(
|
|
"chat.onebox.inline_to_message",
|
|
message_id: message.id,
|
|
chat_channel: chat_channel.name,
|
|
username: user.username,
|
|
)
|
|
else
|
|
chat_channel = Chat::Channel.find_by(id: route[:channel_id])
|
|
return if !chat_channel
|
|
|
|
if route[:thread_id].present?
|
|
thread = Chat::Thread.find_by(id: route[:thread_id])
|
|
return if !thread
|
|
|
|
title =
|
|
if thread.title.present?
|
|
I18n.t(
|
|
"chat.onebox.inline_to_thread",
|
|
chat_channel: chat_channel.name,
|
|
thread_title: thread.title,
|
|
)
|
|
else
|
|
I18n.t("chat.onebox.inline_to_thread_no_title", chat_channel: chat_channel.name)
|
|
end
|
|
else
|
|
title =
|
|
if chat_channel.name.present?
|
|
I18n.t("chat.onebox.inline_to_channel", chat_channel: chat_channel.name)
|
|
end
|
|
end
|
|
end
|
|
|
|
return if !Guardian.new.can_preview_chat_channel?(chat_channel)
|
|
|
|
{ url: url, title: title }
|
|
end
|
|
end
|
|
end
|