Commit a9e940c3 authored by James Calfee's avatar James Calfee
Browse files

Convert follow api calls to steem-js. #1119

parent 3ec1088b
......@@ -386,7 +386,7 @@ const Comment = connect(
const {content} = ownProps
const username = state.user.getIn(['current', 'username'])
const ignore_list = username ? state.global.getIn(['follow', 'get_following', username, 'ignore_result']) : null
const ignore_list = username ? state.global.getIn(['follow', 'getFollowingAsync', username, 'ignore_result']) : null
return {
...ownProps,
......
......@@ -228,7 +228,7 @@ export default connect(
const current = state.user.get('current')
const username = current ? current.get('username') : state.offchain.get('account')
const content = state.global.get('content');
const ignore_result = state.global.getIn(['follow', 'get_following', username, 'ignore_result']);
const ignore_result = state.global.getIn(['follow', 'getFollowingAsync', username, 'ignore_result']);
return {...props, username, content, ignore_result, pathname};
},
dispatch => ({
......
......@@ -112,9 +112,9 @@ module.exports = connect(
follower = current_user ? current_user.get('username') : null
}
const {following} = ownProps;
const f = state.global.getIn(['follow', 'get_following', follower], emptyMap);
const loading = f.get('blog_loading', false) || f.get('ignore_loading', false);
const {following} = ownProps
const f = state.global.getIn(['follow', 'getFollowingAsync', follower], emptyMap)
const loading = f.get('blog_loading', false) || f.get('ignore_loading', false)
const followingWhat =
f.get('blog_result', emptySet).contains(following) ? 'blog' :
f.get('ignore_result', emptySet).contains(following) ? 'ignore' :
......
......@@ -132,7 +132,7 @@ class Settings extends React.Component {
const {profile_image, name, about, location, website} = this.state
const {follow, account, isOwnAccount} = this.props
const following = follow && follow.getIn(['get_following', account.name]);
const following = follow && follow.getIn(['getFollowingAsync', account.name]);
const ignores = isOwnAccount && following && following.get('ignore_result')
return <div className="Settings">
......
......@@ -195,7 +195,7 @@ export default connect(state => {
const current_user = state.user.get('current')
let ignoring
if(current_user) {
const key = ['follow', 'get_following', current_user.get('username'), 'ignore_result']
const key = ['follow', 'getFollowingAsync', current_user.get('username'), 'ignore_result']
ignoring = state.global.getIn(key, emptySet)
}
return {
......
......@@ -47,12 +47,12 @@ export default class UserProfile extends React.Component {
const account = np.routeParams.accountname.toLowerCase();
if (follow) {
followersLoading = follow.getIn(['get_followers', account, 'blog_loading'], false);
followingLoading = follow.getIn(['get_following', account, 'blog_loading'], false);
followersLoading = follow.getIn(['getFollowersAsync', account, 'blog_loading'], false);
followingLoading = follow.getIn(['getFollowingAsync', account, 'blog_loading'], false);
}
if (np.follow) {
npFollowersLoading = np.follow.getIn(['get_followers', account, 'blog_loading'], false);
npFollowingLoading = np.follow.getIn(['get_following', account, 'blog_loading'], false);
npFollowersLoading = np.follow.getIn(['getFollowersAsync', account, 'blog_loading'], false);
npFollowingLoading = np.follow.getIn(['getFollowingAsync', account, 'blog_loading'], false);
}
return (
......@@ -121,8 +121,8 @@ export default class UserProfile extends React.Component {
} else {
return <div><center>{translate('unknown_account')}</center></div>
}
const followers = follow && follow.getIn(['get_followers', accountname]);
const following = follow && follow.getIn(['get_following', accountname]);
const followers = follow && follow.getIn(['getFollowersAsync', accountname]);
const following = follow && follow.getIn(['getFollowingAsync', accountname]);
// instantiate following items
let totalCounts = this.props.follow_count;
......
......@@ -42,10 +42,11 @@ export default function reducer(state = defaultState, action) {
const loadingBlacklist = [
'get_dynamic_global_properties',
'get_api_by_name',
'get_followers',
'get_following'
'getFollowersAsync',
'getFollowingAsync'
];
const loadingIgnored = loadingBlacklist.indexOf(action.payload.method) !== -1;
console.log('loadingBlacklist', loadingIgnored, action.payload.method)
if (action.payload.event === 'BEGIN') {
res = state.mergeDeep({
loading: loadingIgnored ? state.get('loading') : true, // reuse current loading state if the method is blacklisted
......
......@@ -28,8 +28,8 @@ export function* fetchState(location_change_action) {
if(m && m.length === 2) {
const username = m[1]
yield fork(fetchFollowCount, username)
yield fork(loadFollows, "get_followers", username, 'blog')
yield fork(loadFollows, "get_following", username, 'blog')
yield fork(loadFollows, "getFollowersAsync", username, 'blog')
yield fork(loadFollows, "getFollowingAsync", username, 'blog')
}
// `ignore_fetch` case should only trigger on initial page load. No need to call
......
import {fromJS, Map, Set} from 'immutable'
import {call, put, select} from 'redux-saga/effects';
import {Apis} from 'shared/api_client';
import {api} from 'steem';
/**
This loadFollows both 'blog' and 'ignore'
......@@ -8,7 +8,7 @@ import {Apis} from 'shared/api_client';
//fetch for follow/following count
export function* fetchFollowCount(account) {
const counts = yield call(Apis.follow, 'get_follow_count', account)
const counts = yield call([api, api.getFollowCountAsync], account)
yield put({
type: 'global/UPDATE',
payload: {
......@@ -46,8 +46,8 @@ export function* loadFollows(method, account, type, force = false) {
}
function* loadFollowsLoop(method, account, type, start = '', limit = 100) {
if(method === "get_followers") limit = 1000;
const res = fromJS(yield Apis.follow(method, account, start, type, limit));
if(method === "getFollowersAsync") limit = 1000;
const res = fromJS(yield api[method](account, start, type, limit));
// console.log('res.toJS()', res.toJS())
let cnt = 0
......@@ -62,7 +62,7 @@ function* loadFollowsLoop(method, account, type, start = '', limit = 100) {
cnt += 1;
const whatList = value.get('what')
const accountNameKey = method === "get_following" ? "following" : "follower";
const accountNameKey = method === "getFollowingAsync" ? "following" : "follower";
const accountName = lastAccountName = value.get(accountNameKey)
whatList.forEach((what) => {
//currently this is always true: what === type
......
......@@ -98,7 +98,7 @@ function* preBroadcast_custom_json({operation}) {
if(json[0] === 'follow') {
const {follower, following, what: [action]} = json[1]
yield put(g.actions.update({
key: ['follow', 'get_following', follower],
key: ['follow', 'getFollowingAsync', follower],
notSet: Map(),
updater: m => {
//m = m.asMutable()
......@@ -430,7 +430,7 @@ function* error_custom_json({operation: {id, required_posting_auths}}) {
if(id === 'follow') {
const follower = required_posting_auths[0]
yield put(g.actions.update({
key: ['follow', 'get_following', follower, 'loading'],
key: ['follow', 'getFollowingAsync', follower, 'loading'],
updater: () => null
}))
}
......
......@@ -95,8 +95,8 @@ function* usernamePasswordLogin(action) {
const current = yield select(state => state.user.get('current'))
if(current) {
const username = current.get('username')
yield fork(loadFollows, "get_following", username, 'blog')
yield fork(loadFollows, "get_following", username, 'ignore')
yield fork(loadFollows, "getFollowingAsync", username, 'blog')
yield fork(loadFollows, "getFollowingAsync", username, 'ignore')
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment