diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-03-22 19:56:38 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-03-22 19:56:38 +0100 |
commit | 08faeedff7838e339488cfcddf02d95241557ffb (patch) | |
tree | f7f2fd55bf288b5380732b03460750e2ba519ec1 | |
parent | 22e06a4077bef6317e72385a05052105f3804d68 (diff) | |
parent | d6ed2eb512f09600d7cd8150bb9b547442a9d68b (diff) |
Merge branch 'feature-omnisearch'
30 files changed, 292 insertions, 68 deletions
diff --git a/app/assets/javascripts/components/actions/search.jsx b/app/assets/javascripts/components/actions/search.jsx index ceb0e4a0c..e4af716ee 100644 --- a/app/assets/javascripts/components/actions/search.jsx +++ b/app/assets/javascripts/components/actions/search.jsx @@ -18,11 +18,13 @@ export function clearSearchSuggestions() { }; }; -export function readySearchSuggestions(value, accounts) { +export function readySearchSuggestions(value, { accounts, hashtags, statuses }) { return { type: SEARCH_SUGGESTIONS_READY, value, - accounts + accounts, + hashtags, + statuses }; }; @@ -32,7 +34,7 @@ export function fetchSearchSuggestions(value) { return; } - api(getState).get('/api/v1/accounts/search', { + api(getState).get('/api/v1/search', { params: { q: value, resolve: true, diff --git a/app/assets/javascripts/components/features/compose/components/autosuggest_account.jsx b/app/assets/javascripts/components/features/compose/components/autosuggest_account.jsx index 9ea7f190f..5591b45cf 100644 --- a/app/assets/javascripts/components/features/compose/components/autosuggest_account.jsx +++ b/app/assets/javascripts/components/features/compose/components/autosuggest_account.jsx @@ -1,11 +1,16 @@ import Avatar from '../../../components/avatar'; import DisplayName from '../../../components/display_name'; +import ImmutablePropTypes from 'react-immutable-proptypes'; const AutosuggestAccount = ({ account }) => ( - <div style={{ overflow: 'hidden' }}> + <div style={{ overflow: 'hidden' }} className='autosuggest-account'> <div style={{ float: 'left', marginRight: '5px' }}><Avatar src={account.get('avatar')} size={18} /></div> <DisplayName account={account} /> </div> ); +AutosuggestAccount.propTypes = { + account: ImmutablePropTypes.map.isRequired +}; + export default AutosuggestAccount; diff --git a/app/assets/javascripts/components/features/compose/components/autosuggest_status.jsx b/app/assets/javascripts/components/features/compose/components/autosuggest_status.jsx new file mode 100644 index 000000000..086488649 --- /dev/null +++ b/app/assets/javascripts/components/features/compose/components/autosuggest_status.jsx @@ -0,0 +1,15 @@ +import { FormattedMessage } from 'react-intl'; +import DisplayName from '../../../components/display_name'; +import ImmutablePropTypes from 'react-immutable-proptypes'; + +const AutosuggestStatus = ({ status }) => ( + <div style={{ overflow: 'hidden' }} className='autosuggest-status'> + <FormattedMessage id='search.status_by' defaultMessage='Status by {name}' values={{ name: <strong>@{status.getIn(['account', 'acct'])}</strong> }} /> + </div> +); + +AutosuggestStatus.propTypes = { + status: ImmutablePropTypes.map.isRequired +}; + +export default AutosuggestStatus; diff --git a/app/assets/javascripts/components/features/compose/components/search.jsx b/app/assets/javascripts/components/features/compose/components/search.jsx index c1f23939d..a0e8f82fb 100644 --- a/app/assets/javascripts/components/features/compose/components/search.jsx +++ b/app/assets/javascripts/components/features/compose/components/search.jsx @@ -2,6 +2,7 @@ import PureRenderMixin from 'react-addons-pure-render-mixin'; import ImmutablePropTypes from 'react-immutable-proptypes'; import Autosuggest from 'react-autosuggest'; import AutosuggestAccountContainer from '../containers/autosuggest_account_container'; +import AutosuggestStatusContainer from '../containers/autosuggest_status_container'; import { debounce } from 'react-decoration'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; @@ -14,8 +15,10 @@ const getSuggestionValue = suggestion => suggestion.value; const renderSuggestion = suggestion => { if (suggestion.type === 'account') { return <AutosuggestAccountContainer id={suggestion.id} />; + } else if (suggestion.type === 'hashtag') { + return <span>#{suggestion.id}</span>; } else { - return <span>#{suggestion.id}</span> + return <AutosuggestStatusContainer id={suggestion.id} />; } }; @@ -78,8 +81,10 @@ const Search = React.createClass({ onSuggestionSelected (_, { suggestion }) { if (suggestion.type === 'account') { this.context.router.push(`/accounts/${suggestion.id}`); - } else { + } else if(suggestion.type === 'hashtag') { this.context.router.push(`/timelines/tag/${suggestion.id}`); + } else { + this.context.router.push(`/statuses/${suggestion.id}`); } }, diff --git a/app/assets/javascripts/components/features/compose/containers/autosuggest_status_container.jsx b/app/assets/javascripts/components/features/compose/containers/autosuggest_status_container.jsx new file mode 100644 index 000000000..ef46eb09c --- /dev/null +++ b/app/assets/javascripts/components/features/compose/containers/autosuggest_status_container.jsx @@ -0,0 +1,15 @@ +import { connect } from 'react-redux'; +import AutosuggestStatus from '../components/autosuggest_status'; +import { makeGetStatus } from '../../../selectors'; + +const makeMapStateToProps = () => { + const getStatus = makeGetStatus(); + + const mapStateToProps = (state, { id }) => ({ + status: getStatus(state, id) + }); + + return mapStateToProps; +}; + +export default connect(makeMapStateToProps)(AutosuggestStatus); diff --git a/app/assets/javascripts/components/reducers/accounts.jsx b/app/assets/javascripts/components/reducers/accounts.jsx index f3938cee1..6ce41670d 100644 --- a/app/assets/javascripts/components/reducers/accounts.jsx +++ b/app/assets/javascripts/components/reducers/accounts.jsx @@ -90,7 +90,6 @@ export default function accounts(state = initialState, action) { case REBLOGS_FETCH_SUCCESS: case FAVOURITES_FETCH_SUCCESS: case COMPOSE_SUGGESTIONS_READY: - case SEARCH_SUGGESTIONS_READY: case FOLLOW_REQUESTS_FETCH_SUCCESS: case FOLLOW_REQUESTS_EXPAND_SUCCESS: case BLOCKS_FETCH_SUCCESS: @@ -98,6 +97,7 @@ export default function accounts(state = initialState, action) { return normalizeAccounts(state, action.accounts); case NOTIFICATIONS_REFRESH_SUCCESS: case NOTIFICATIONS_EXPAND_SUCCESS: + case SEARCH_SUGGESTIONS_READY: return normalizeAccountsFromStatuses(normalizeAccounts(state, action.accounts), action.statuses); case TIMELINE_REFRESH_SUCCESS: case TIMELINE_EXPAND_SUCCESS: diff --git a/app/assets/javascripts/components/reducers/search.jsx b/app/assets/javascripts/components/reducers/search.jsx index d835ef268..e95f9ed79 100644 --- a/app/assets/javascripts/components/reducers/search.jsx +++ b/app/assets/javascripts/components/reducers/search.jsx @@ -11,28 +11,51 @@ const initialState = Immutable.Map({ suggestions: [] }); -const normalizeSuggestions = (state, value, accounts) => { - let newSuggestions = [ - { +const normalizeSuggestions = (state, value, accounts, hashtags, statuses) => { + let newSuggestions = []; + + if (accounts.length > 0) { + newSuggestions.push({ title: 'account', items: accounts.map(item => ({ type: 'account', id: item.id, value: item.acct })) + }); + } + + if (value.indexOf('@') === -1 && value.indexOf(' ') === -1 || hashtags.length > 0) { + let hashtagItems = hashtags.map(item => ({ + type: 'hashtag', + id: item, + value: `#${item}` + })); + + if (value.indexOf('@') === -1 && value.indexOf(' ') === -1 && !value.startsWith('http://') && !value.startsWith('https://') && hashtags.indexOf(value) === -1) { + hashtagItems.unshift({ + type: 'hashtag', + id: value, + value: `#${value}` + }); } - ]; - if (value.indexOf('@') === -1 && value.indexOf(' ') === -1) { + if (hashtagItems.length > 0) { + newSuggestions.push({ + title: 'hashtag', + items: hashtagItems + }); + } + } + + if (statuses.length > 0) { newSuggestions.push({ - title: 'hashtag', - items: [ - { - type: 'hashtag', - id: value, - value: `#${value}` - } - ] + title: 'status', + items: statuses.map(item => ({ + type: 'status', + id: item.id, + value: item.id + })) }); } @@ -44,17 +67,17 @@ const normalizeSuggestions = (state, value, accounts) => { export default function search(state = initialState, action) { switch(action.type) { - case SEARCH_CHANGE: - return state.set('value', action.value); - case SEARCH_SUGGESTIONS_READY: - return normalizeSuggestions(state, action.value, action.accounts); - case SEARCH_RESET: - return state.withMutations(map => { - map.set('suggestions', []); - map.set('value', ''); - map.set('loaded_value', ''); - }); - default: - return state; + case SEARCH_CHANGE: + return state.set('value', action.value); + case SEARCH_SUGGESTIONS_READY: + return normalizeSuggestions(state, action.value, action.accounts, action.hashtags, action.statuses); + case SEARCH_RESET: + return state.withMutations(map => { + map.set('suggestions', []); + map.set('value', ''); + map.set('loaded_value', ''); + }); + default: + return state; } }; diff --git a/app/assets/javascripts/components/reducers/statuses.jsx b/app/assets/javascripts/components/reducers/statuses.jsx index ce791eab6..1669b8c65 100644 --- a/app/assets/javascripts/components/reducers/statuses.jsx +++ b/app/assets/javascripts/components/reducers/statuses.jsx @@ -32,6 +32,7 @@ import { FAVOURITED_STATUSES_FETCH_SUCCESS, FAVOURITED_STATUSES_EXPAND_SUCCESS } from '../actions/favourites'; +import { SEARCH_SUGGESTIONS_READY } from '../actions/search'; import Immutable from 'immutable'; const normalizeStatus = (state, status) => { @@ -108,6 +109,7 @@ export default function statuses(state = initialState, action) { case NOTIFICATIONS_EXPAND_SUCCESS: case FAVOURITED_STATUSES_FETCH_SUCCESS: case FAVOURITED_STATUSES_EXPAND_SUCCESS: + case SEARCH_SUGGESTIONS_READY: return normalizeStatuses(state, action.statuses); case TIMELINE_DELETE: return deleteStatus(state, action.id, action.references); diff --git a/app/assets/stylesheets/components.scss b/app/assets/stylesheets/components.scss index 4b1e86aca..057c61f91 100644 --- a/app/assets/stylesheets/components.scss +++ b/app/assets/stylesheets/components.scss @@ -1421,3 +1421,13 @@ button.active i.fa-retweet { } } } + +.autosuggest-status { + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + + strong { + font-weight: 500; + } +} diff --git a/app/controllers/api/v1/accounts_controller.rb b/app/controllers/api/v1/accounts_controller.rb index 51c948955..f07450eb0 100644 --- a/app/controllers/api/v1/accounts_controller.rb +++ b/app/controllers/api/v1/accounts_controller.rb @@ -115,7 +115,7 @@ class Api::V1::AccountsController < ApiController end def search - @accounts = SearchService.new.call(params[:q], limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:resolve] == 'true', current_account) + @accounts = AccountSearchService.new.call(params[:q], limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:resolve] == 'true', current_account) set_account_counters_maps(@accounts) unless @accounts.nil? diff --git a/app/controllers/api/v1/search_controller.rb b/app/controllers/api/v1/search_controller.rb new file mode 100644 index 000000000..6b1292458 --- /dev/null +++ b/app/controllers/api/v1/search_controller.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class Api::V1::SearchController < ApiController + respond_to :json + + def index + @search = OpenStruct.new(SearchService.new.call(params[:q], 5, params[:resolve] == 'true', current_account)) + end +end diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb new file mode 100644 index 000000000..696bb4f52 --- /dev/null +++ b/app/controllers/statuses_controller.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class StatusesController < ApplicationController + layout 'public' + + before_action :set_account + before_action :set_status + before_action :set_link_headers + before_action :check_account_suspension + + def show + @ancestors = @status.reply? ? cache_collection(@status.ancestors(current_account), Status) : [] + @descendants = cache_collection(@status.descendants(current_account), Status) + + render 'stream_entries/show' + end + + private + + def set_account + @account = Account.find_local!(params[:account_username]) + end + + def set_link_headers + response.headers['Link'] = LinkHeader.new([[account_stream_entry_url(@account, @status.stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]]]) + end + + def set_status + @status = @account.statuses.find(params[:id]) + @stream_entry = @status.stream_entry + @type = @stream_entry.activity_type.downcase + + raise ActiveRecord::RecordNotFound unless @status.permitted?(current_account) + end + + def check_account_suspension + gone if @account.suspended? + end +end diff --git a/app/lib/tag_manager.rb b/app/lib/tag_manager.rb index 9fef70fda..34c3edc4b 100644 --- a/app/lib/tag_manager.rb +++ b/app/lib/tag_manager.rb @@ -82,7 +82,9 @@ class TagManager case target.object_type when :person - account_url(target) + short_account_url(target) + when :note, :comment, :activity + short_account_status_url(target.account, target) else account_stream_entry_url(target.account, target.stream_entry) end diff --git a/app/models/account.rb b/app/models/account.rb index c0cd2ff64..6968607a2 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -222,8 +222,9 @@ SQL end def search_for(terms, limit = 10) + terms = Arel.sql(connection.quote(terms.gsub(/['?\\:]/, ' '))) textsearch = '(setweight(to_tsvector(\'simple\', accounts.display_name), \'A\') || setweight(to_tsvector(\'simple\', accounts.username), \'B\') || setweight(to_tsvector(\'simple\', coalesce(accounts.domain, \'\')), \'C\'))' - query = 'to_tsquery(\'simple\', \'\'\' \' || ? || \' \'\'\' || \':*\')' + query = 'to_tsquery(\'simple\', \'\'\' \' || ' + terms + ' || \' \'\'\' || \':*\')' sql = <<SQL SELECT @@ -235,12 +236,13 @@ SQL LIMIT ? SQL - Account.find_by_sql([sql, terms, terms, limit]) + Account.find_by_sql([sql, limit]) end def advanced_search_for(terms, account, limit = 10) + terms = Arel.sql(connection.quote(terms.gsub(/['?\\:]/, ' '))) textsearch = '(setweight(to_tsvector(\'simple\', accounts.display_name), \'A\') || setweight(to_tsvector(\'simple\', accounts.username), \'B\') || setweight(to_tsvector(\'simple\', coalesce(accounts.domain, \'\')), \'C\'))' - query = 'to_tsquery(\'simple\', \'\'\' \' || ? || \' \'\'\' || \':*\')' + query = 'to_tsquery(\'simple\', \'\'\' \' || ' + terms + ' || \' \'\'\' || \':*\')' sql = <<SQL SELECT @@ -254,7 +256,7 @@ SQL LIMIT ? SQL - Account.find_by_sql([sql, terms, account.id, account.id, terms, limit]) + Account.find_by_sql([sql, account.id, account.id, limit]) end def following_map(target_account_ids, account_id) diff --git a/app/models/tag.rb b/app/models/tag.rb index 0d2fe43b8..15625ca43 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -10,4 +10,24 @@ class Tag < ApplicationRecord def to_param name end + + class << self + def search_for(terms, limit = 5) + terms = Arel.sql(connection.quote(terms.gsub(/['?\\:]/, ' '))) + textsearch = 'to_tsvector(\'simple\', tags.name)' + query = 'to_tsquery(\'simple\', \'\'\' \' || ' + terms + ' || \' \'\'\' || \':*\')' + + sql = <<SQL + SELECT + tags.*, + ts_rank_cd(#{textsearch}, #{query}) AS rank + FROM tags + WHERE #{query} @@ #{textsearch} + ORDER BY rank DESC + LIMIT ? +SQL + + Tag.find_by_sql([sql, limit]) + end + end end diff --git a/app/services/account_search_service.rb b/app/services/account_search_service.rb new file mode 100644 index 000000000..f55439dcb --- /dev/null +++ b/app/services/account_search_service.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class AccountSearchService < BaseService + def call(query, limit, resolve = false, account = nil) + return [] if query.blank? || query.start_with?('#') + + username, domain = query.gsub(/\A@/, '').split('@') + domain = nil if TagManager.instance.local_domain?(domain) + + if domain.nil? + exact_match = Account.find_local(username) + results = account.nil? ? Account.search_for(username, limit) : Account.advanced_search_for(username, account, limit) + else + exact_match = Account.find_remote(username, domain) + results = account.nil? ? Account.search_for("#{username} #{domain}", limit) : Account.advanced_search_for("#{username} #{domain}", account, limit) + end + + results = [exact_match] + results.reject { |a| a.id == exact_match.id } if exact_match + + if resolve && !exact_match && !domain.nil? + results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")] + end + + results + end +end diff --git a/app/services/fetch_atom_service.rb b/app/services/fetch_atom_service.rb index f7e9c150a..c3dad1eb9 100644 --- a/app/services/fetch_atom_service.rb +++ b/app/services/fetch_atom_service.rb @@ -47,6 +47,6 @@ class FetchAtomService < BaseService end def http_client - HTTP.timeout(:per_operation, write: 20, connect: 20, read: 50).follow + HTTP.timeout(:per_operation, write: 10, connect: 10, read: 10).follow end end diff --git a/app/services/fetch_remote_account_service.rb b/app/services/fetch_remote_account_service.rb index baefa3a86..6a6a696d6 100644 --- a/app/services/fetch_remote_account_service.rb +++ b/app/services/fetch_remote_account_service.rb @@ -1,8 +1,13 @@ # frozen_string_literal: true class FetchRemoteAccountService < BaseService - def call(url) - atom_url, body = FetchAtomService.new.call(url) + def call(url, prefetched_body = nil) + if prefetched_body.nil? + atom_url, body = FetchAtomService.new.call(url) + else + atom_url = url + body = prefetched_body + end return nil if atom_url.nil? process_atom(atom_url, body) diff --git a/app/services/fetch_remote_resource_service.rb b/app/services/fetch_remote_resource_service.rb new file mode 100644 index 000000000..2185ceb20 --- /dev/null +++ b/app/services/fetch_remote_resource_service.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class FetchRemoteResourceService < BaseService + def call(url) + atom_url, body = FetchAtomService.new.call(url) + + return nil if atom_url.nil? + + xml = Nokogiri::XML(body) + xml.encoding = 'utf-8' + + if xml.root.name == 'feed' + FetchRemoteAccountService.new.call(atom_url, body) + elsif xml.root.name == 'entry' + FetchRemoteStatusService.new.call(atom_url, body) + end + end +end diff --git a/app/services/fetch_remote_status_service.rb b/app/services/fetch_remote_status_service.rb index 7063231e4..e2d185723 100644 --- a/app/services/fetch_remote_status_service.rb +++ b/app/services/fetch_remote_status_service.rb @@ -1,8 +1,13 @@ # frozen_string_literal: true class FetchRemoteStatusService < BaseService - def call(url) - atom_url, body = FetchAtomService.new.call(url) + def call(url, prefetched_body = nil) + if prefetched_body.nil? + atom_url, body = FetchAtomService.new.call(url) + else + atom_url = url + body = prefetched_body + end return nil if atom_url.nil? process_atom(atom_url, body) diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb index c74ff9e22..d5f7b4b3c 100644 --- a/app/services/process_interaction_service.rb +++ b/app/services/process_interaction_service.rb @@ -64,7 +64,7 @@ class ProcessInteractionService < BaseService end def mentions_account?(xml, account) - xml.xpath('/xmlns:entry/xmlns:link[@rel="mentioned"]', xmlns: TagManager::XMLNS).each { |mention_link| return true if mention_link.attribute('href').value == TagManager.instance.url_for(account) } + xml.xpath('/xmlns:entry/xmlns:link[@rel="mentioned"]', xmlns: TagManager::XMLNS).each { |mention_link| return true if [TagManager.instance.uri_for(account), TagManager.instance.url_for(account)].include?(mention_link.attribute('href').value) } false end diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 19fc16973..159c03713 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -2,23 +2,18 @@ class SearchService < BaseService def call(query, limit, resolve = false, account = nil) - return if query.blank? || query.start_with?('#') + return if query.blank? - username, domain = query.gsub(/\A@/, '').split('@') - domain = nil if TagManager.instance.local_domain?(domain) + results = { accounts: [], hashtags: [], statuses: [] } - if domain.nil? - exact_match = Account.find_local(username) - results = account.nil? ? Account.search_for(username, limit) : Account.advanced_search_for(username, account, limit) - else - exact_match = Account.find_remote(username, domain) - results = account.nil? ? Account.search_for("#{username} #{domain}", limit) : Account.advanced_search_for("#{username} #{domain}", account, limit) - end + if query =~ /\Ahttps?:\/\// + resource = FetchRemoteResourceService.new.call(query) - results = [exact_match] + results.reject { |a| a.id == exact_match.id } if exact_match - - if resolve && !exact_match && !domain.nil? - results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")] + results[:accounts] << resource if resource.is_a?(Account) + results[:statuses] << resource if resource.is_a?(Status) + else + results[:accounts] = AccountSearchService.new.call(query, limit, resolve, account) + results[:hashtags] = Tag.search_for(query.gsub(/\A#/, ''), limit) unless query.start_with?('@') end results diff --git a/app/views/accounts/_header.html.haml b/app/views/accounts/_header.html.haml index f575e855e..e35b08317 100644 --- a/app/views/accounts/_header.html.haml +++ b/app/views/accounts/_header.html.haml @@ -20,8 +20,8 @@ .account__header__content.p-note.emojify= Formatter.instance.simplified_format(@account) .details-counters - .counter{ class: active_nav_class(account_url(@account)) } - = link_to account_url(@account), class: 'u-url u-uid' do + .counter{ class: active_nav_class(short_account_url(@account)) } + = link_to short_account_url(@account), class: 'u-url u-uid' do %span.counter-label= t('accounts.posts') %span.counter-number= number_with_delimiter @account.statuses.count .counter{ class: active_nav_class(following_account_url(@account)) } diff --git a/app/views/api/v1/search/index.rabl b/app/views/api/v1/search/index.rabl new file mode 100644 index 000000000..8d1640f2d --- /dev/null +++ b/app/views/api/v1/search/index.rabl @@ -0,0 +1,13 @@ +object @search + +child :accounts, object_root: false do + extends 'api/v1/accounts/show' +end + +node(:hashtags) do |search| + search.hashtags.map(&:name) +end + +child :statuses, object_root: false do + extends 'api/v1/statuses/show' +end diff --git a/app/views/stream_entries/_status.html.haml b/app/views/stream_entries/_status.html.haml index f70e2c890..cdd0dde3b 100644 --- a/app/views/stream_entries/_status.html.haml +++ b/app/views/stream_entries/_status.html.haml @@ -4,7 +4,7 @@ - centered ||= include_threads && !is_predecessor && !is_successor - if status.reply? && include_threads - = render partial: 'status', collection: @ancestors, as: :status, locals: { is_predecessor: true } + = render partial: 'stream_entries/status', collection: @ancestors, as: :status, locals: { is_predecessor: true } .entry{ class: entry_classes(status, is_predecessor, is_successor, include_threads) } - if status.reblog? @@ -19,4 +19,4 @@ = render partial: centered ? 'stream_entries/detailed_status' : 'stream_entries/simple_status', locals: { status: proper_status(status) } - if include_threads - = render partial: 'status', collection: @descendants, as: :status, locals: { is_successor: true } + = render partial: 'stream_entries/status', collection: @descendants, as: :status, locals: { is_successor: true } diff --git a/app/views/stream_entries/show.html.haml b/app/views/stream_entries/show.html.haml index 7a1afdd96..c109ff4b8 100644 --- a/app/views/stream_entries/show.html.haml +++ b/app/views/stream_entries/show.html.haml @@ -24,4 +24,4 @@ = render partial: 'shared/landing_strip', locals: { account: @stream_entry.account } .activity-stream.activity-stream-headless - = render partial: @type, locals: { @type.to_sym => @stream_entry.activity, include_threads: true } + = render partial: "stream_entries/#{@type}", locals: { @type.to_sym => @stream_entry.activity, include_threads: true } diff --git a/config/routes.rb b/config/routes.rb index ea766e1b3..cf8364968 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,6 +24,8 @@ Rails.application.routes.draw do confirmations: 'auth/confirmations', } + get '/users/:username', to: redirect('/@%{username}'), constraints: { format: :html } + resources :accounts, path: 'users', only: [:show], param: :username do resources :stream_entries, path: 'updates', only: [:show] do member do @@ -43,6 +45,9 @@ Rails.application.routes.draw do end end + get '/@:username', to: 'accounts#show', as: :short_account + get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status + namespace :settings do resource :profile, only: [:show, :update] resource :preferences, only: [:show, :update] @@ -129,6 +134,8 @@ Rails.application.routes.draw do get '/timelines/public', to: 'timelines#public', as: :public_timeline get '/timelines/tag/:id', to: 'timelines#tag', as: :hashtag_timeline + get '/search', to: 'search#index', as: :search + resources :follows, only: [:create] resources :media, only: [:create] resources :apps, only: [:create] @@ -187,8 +194,5 @@ Rails.application.routes.draw do root 'home#index' - get '/:username', to: redirect('/users/%{username}') - get '/:username/:id', to: redirect('/users/%{username}/updates/%{id}') - match '*unmatched_route', via: :all, to: 'application#raise_not_found' end diff --git a/db/migrate/20170322162804_add_search_index_to_tags.rb b/db/migrate/20170322162804_add_search_index_to_tags.rb new file mode 100644 index 000000000..415dff9a0 --- /dev/null +++ b/db/migrate/20170322162804_add_search_index_to_tags.rb @@ -0,0 +1,9 @@ +class AddSearchIndexToTags < ActiveRecord::Migration[5.0] + def up + execute 'CREATE INDEX hashtag_search_index ON tags USING gin(to_tsvector(\'simple\', tags.name));' + end + + def down + remove_index :tags, name: :hashtag_search_index + end +end diff --git a/db/schema.rb b/db/schema.rb index 44b52c220..2457b523d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170322143850) do +ActiveRecord::Schema.define(version: 20170322162804) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -259,6 +259,7 @@ ActiveRecord::Schema.define(version: 20170322143850) do t.string "name", default: "", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index "to_tsvector('simple'::regconfig, (name)::text)", name: "hashtag_search_index", using: :gin t.index ["name"], name: "index_tags_on_name", unique: true, using: :btree end diff --git a/spec/controllers/api/salmon_controller_spec.rb b/spec/controllers/api/salmon_controller_spec.rb index 3d3a973d2..6897caeeb 100644 --- a/spec/controllers/api/salmon_controller_spec.rb +++ b/spec/controllers/api/salmon_controller_spec.rb @@ -6,7 +6,6 @@ RSpec.describe Api::SalmonController, type: :controller do let(:account) { Fabricate(:user, account: Fabricate(:account, username: 'catsrgr8')).account } before do - stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {}) stub_request(:get, "https://quitter.no/.well-known/host-meta").to_return(request_fixture('.host-meta.txt')) stub_request(:get, "https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no").to_return(request_fixture('webfinger.txt')) stub_request(:get, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt')) |