commit
70ab6624f5
@ -0,0 +1,37 @@ |
|||||||
|
import api from '../api'; |
||||||
|
|
||||||
|
export const SUGGESTIONS_FETCH_REQUEST = 'SUGGESTIONS_FETCH_REQUEST'; |
||||||
|
export const SUGGESTIONS_FETCH_SUCCESS = 'SUGGESTIONS_FETCH_SUCCESS'; |
||||||
|
export const SUGGESTIONS_FETCH_FAIL = 'SUGGESTIONS_FETCH_FAIL'; |
||||||
|
|
||||||
|
export function fetchSuggestions() { |
||||||
|
return (dispatch, getState) => { |
||||||
|
dispatch(fetchSuggestionsRequest()); |
||||||
|
|
||||||
|
api(getState).get('/api/v1/accounts/suggestions').then(response => { |
||||||
|
dispatch(fetchSuggestionsSuccess(response.data)); |
||||||
|
}).catch(error => { |
||||||
|
dispatch(fetchSuggestionsFail(error)); |
||||||
|
}); |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
export function fetchSuggestionsRequest() { |
||||||
|
return { |
||||||
|
type: SUGGESTIONS_FETCH_REQUEST |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
export function fetchSuggestionsSuccess(suggestions) { |
||||||
|
return { |
||||||
|
type: SUGGESTIONS_FETCH_SUCCESS, |
||||||
|
suggestions: suggestions |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
export function fetchSuggestionsFail(error) { |
||||||
|
return { |
||||||
|
type: SUGGESTIONS_FETCH_FAIL, |
||||||
|
error: error |
||||||
|
}; |
||||||
|
}; |
@ -0,0 +1,76 @@ |
|||||||
|
import PureRenderMixin from 'react-addons-pure-render-mixin'; |
||||||
|
import ImmutablePropTypes from 'react-immutable-proptypes'; |
||||||
|
import Avatar from '../../../components/avatar'; |
||||||
|
import DisplayName from '../../../components/display_name'; |
||||||
|
import { Link } from 'react-router'; |
||||||
|
|
||||||
|
const outerStyle = { |
||||||
|
marginBottom: '10px', |
||||||
|
borderTop: '1px solid #616b86' |
||||||
|
}; |
||||||
|
|
||||||
|
const headerStyle = { |
||||||
|
fontSize: '14px', |
||||||
|
fontWeight: '500', |
||||||
|
display: 'block', |
||||||
|
padding: '10px', |
||||||
|
color: '#9baec8', |
||||||
|
background: '#454b5e', |
||||||
|
width: '120px', |
||||||
|
marginTop: '-18px' |
||||||
|
}; |
||||||
|
|
||||||
|
const itemStyle = { |
||||||
|
display: 'block', |
||||||
|
padding: '10px', |
||||||
|
color: '#9baec8', |
||||||
|
overflow: 'hidden', |
||||||
|
textDecoration: 'none' |
||||||
|
}; |
||||||
|
|
||||||
|
const displayNameStyle = { |
||||||
|
display: 'block', |
||||||
|
fontWeight: '500' |
||||||
|
}; |
||||||
|
|
||||||
|
const acctStyle = { |
||||||
|
display: 'block' |
||||||
|
}; |
||||||
|
|
||||||
|
const SuggestionsBox = React.createClass({ |
||||||
|
|
||||||
|
propTypes: { |
||||||
|
accounts: ImmutablePropTypes.list.isRequired |
||||||
|
}, |
||||||
|
|
||||||
|
mixins: [PureRenderMixin], |
||||||
|
|
||||||
|
render () { |
||||||
|
const accounts = this.props.accounts.take(2); |
||||||
|
|
||||||
|
return ( |
||||||
|
<div style={outerStyle}> |
||||||
|
<strong style={headerStyle}>Who to follow</strong> |
||||||
|
|
||||||
|
{accounts.map(account => { |
||||||
|
let displayName = account.get('display_name'); |
||||||
|
|
||||||
|
if (displayName.length === 0) { |
||||||
|
displayName = account.get('username'); |
||||||
|
} |
||||||
|
|
||||||
|
return ( |
||||||
|
<Link key={account.get('id')} style={itemStyle} to={`/accounts/${account.get('id')}`}> |
||||||
|
<div style={{ float: 'left', marginRight: '10px' }}><Avatar src={account.get('avatar')} size={36} /></div> |
||||||
|
<strong style={displayNameStyle}>{displayName}</strong> |
||||||
|
<span style={acctStyle}>{account.get('acct')}</span> |
||||||
|
</Link> |
||||||
|
) |
||||||
|
})} |
||||||
|
</div> |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
export default SuggestionsBox; |
@ -0,0 +1,9 @@ |
|||||||
|
import { connect } from 'react-redux'; |
||||||
|
import { getSuggestions } from '../../../selectors'; |
||||||
|
import SuggestionsBox from '../components/suggestions_box'; |
||||||
|
|
||||||
|
const mapStateToProps = (state) => ({ |
||||||
|
accounts: getSuggestions(state) |
||||||
|
}); |
||||||
|
|
||||||
|
export default connect(mapStateToProps)(SuggestionsBox); |
@ -0,0 +1,10 @@ |
|||||||
|
class FollowSuggestion |
||||||
|
def self.get(for_account_id) |
||||||
|
neo = Neography::Rest.new |
||||||
|
account_ids = neo.execute_query('START a=node:account_index(Account={id}) MATCH (a)-[:follows]->(b)-[:follows]->(c) WHERE a <> c AND NOT (a)-[:follows]->(c) RETURN DISTINCT c.account_id', id: for_account_id) |
||||||
|
Account.where(id: account_ids['data'].first) unless account_ids.empty? |
||||||
|
rescue Neography::NeographyError, Excon::Error::Socket => e |
||||||
|
Rails.logger.error e |
||||||
|
[] |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,2 @@ |
|||||||
|
collection @accounts |
||||||
|
extends('api/v1/accounts/show') |
@ -0,0 +1,5 @@ |
|||||||
|
Neography.configure do |config| |
||||||
|
config.protocol = "http" |
||||||
|
config.server = ENV['NEO4J_HOST'] || 'localhost' |
||||||
|
config.port = ENV['NEO4J_PORT'] || 7474 |
||||||
|
end |
@ -1,2 +1,2 @@ |
|||||||
web_app = Doorkeeper::Application.new(name: 'Web', superapp: true, redirect_uri: Doorkeeper.configuration.native_redirect_uri) |
web_app = Doorkeeper::Application.new(name: 'Web', superapp: true, redirect_uri: Doorkeeper.configuration.native_redirect_uri) |
||||||
web_app.save(validate: false) |
web_app.save! |
||||||
|
Loading…
Reference in new issue