* Add support for links to public statuses in announcements to be opened in WebUI
* Please CodeClimate
} 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');
}
}
}
+ 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');
}
@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
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)
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
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