forked from treehouse/mastodon
Add support for links to statuses in announcements to be opened in web UI (#13212)
* Add support for links to public statuses in announcements to be opened in WebUI * Please CodeClimatesignup-info-prompt
parent
5e4b649655
commit
aa67036b41
|
@ -95,6 +95,10 @@ class Content extends ImmutablePureComponent {
|
|||
} else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) {
|
||||
link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false);
|
||||
} else {
|
||||
let status = this.props.announcement.get('statuses').find(item => link.href === item.get('url'));
|
||||
if (status) {
|
||||
link.addEventListener('click', this.onStatusClick.bind(this, status), false);
|
||||
}
|
||||
link.setAttribute('title', link.href);
|
||||
link.classList.add('unhandled-link');
|
||||
}
|
||||
|
@ -120,6 +124,13 @@ class Content extends ImmutablePureComponent {
|
|||
}
|
||||
}
|
||||
|
||||
onStatusClick = (status, e) => {
|
||||
if (this.context.router && e.button === 0 && !(e.ctrlKey || e.metaKey)) {
|
||||
e.preventDefault();
|
||||
this.context.router.history.push(`/statuses/${status.get('id')}`);
|
||||
}
|
||||
}
|
||||
|
||||
handleEmojiMouseEnter = ({ target }) => {
|
||||
target.src = target.getAttribute('data-original');
|
||||
}
|
||||
|
|
|
@ -48,6 +48,10 @@ class Announcement < ApplicationRecord
|
|||
@mentions ||= Account.from_text(text)
|
||||
end
|
||||
|
||||
def statuses
|
||||
@statuses ||= Status.from_text(text)
|
||||
end
|
||||
|
||||
def tags
|
||||
@tags ||= Tag.find_or_create_by_names(Extractor.extract_hashtags(text))
|
||||
end
|
||||
|
|
|
@ -369,6 +369,21 @@ class Status < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def from_text(text)
|
||||
return [] if text.blank?
|
||||
|
||||
text.scan(FetchLinkCardService::URL_PATTERN).map(&:first).uniq.map do |url|
|
||||
status = begin
|
||||
if TagManager.instance.local_url?(url)
|
||||
ActivityPub::TagManager.instance.uri_to_resource(url, Status)
|
||||
else
|
||||
Status.find_by(uri: url) || Status.find_by(url: url)
|
||||
end
|
||||
end
|
||||
status&.distributable? ? status : nil
|
||||
end.compact
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def timeline_scope(local_only = false)
|
||||
|
|
|
@ -7,6 +7,7 @@ class REST::AnnouncementSerializer < ActiveModel::Serializer
|
|||
attribute :read, if: :current_user?
|
||||
|
||||
has_many :mentions
|
||||
has_many :statuses
|
||||
has_many :tags, serializer: REST::StatusSerializer::TagSerializer
|
||||
has_many :emojis, serializer: REST::CustomEmojiSerializer
|
||||
has_many :reactions, serializer: REST::ReactionSerializer
|
||||
|
@ -46,4 +47,16 @@ class REST::AnnouncementSerializer < ActiveModel::Serializer
|
|||
object.pretty_acct
|
||||
end
|
||||
end
|
||||
|
||||
class StatusSerializer < ActiveModel::Serializer
|
||||
attributes :id, :url
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
end
|
||||
|
||||
def url
|
||||
ActivityPub::TagManager.instance.url_for(object)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue