Fix #61 - Add list of blocked users to the UI; clean up failed push notifications API
Try to fix Travis CI setupmaster
parent
77e13c2bc9
commit
920ba5fc4e
@ -0,0 +1,82 @@ |
||||
import api, { getLinks } from '../api' |
||||
import { fetchRelationships } from './accounts'; |
||||
|
||||
export const BLOCKS_FETCH_REQUEST = 'BLOCKS_FETCH_REQUEST'; |
||||
export const BLOCKS_FETCH_SUCCESS = 'BLOCKS_FETCH_SUCCESS'; |
||||
export const BLOCKS_FETCH_FAIL = 'BLOCKS_FETCH_FAIL'; |
||||
|
||||
export const BLOCKS_EXPAND_REQUEST = 'BLOCKS_EXPAND_REQUEST'; |
||||
export const BLOCKS_EXPAND_SUCCESS = 'BLOCKS_EXPAND_SUCCESS'; |
||||
export const BLOCKS_EXPAND_FAIL = 'BLOCKS_EXPAND_FAIL'; |
||||
|
||||
export function fetchBlocks() { |
||||
return (dispatch, getState) => { |
||||
dispatch(fetchBlocksRequest()); |
||||
|
||||
api(getState).get('/api/v1/blocks').then(response => { |
||||
const next = getLinks(response).refs.find(link => link.rel === 'next'); |
||||
dispatch(fetchBlocksSuccess(response.data, next ? next.uri : null)); |
||||
dispatch(fetchRelationships(response.data.map(item => item.id))); |
||||
}).catch(error => dispatch(fetchBlocksFail(error))); |
||||
}; |
||||
}; |
||||
|
||||
export function fetchBlocksRequest() { |
||||
return { |
||||
type: BLOCKS_FETCH_REQUEST |
||||
}; |
||||
}; |
||||
|
||||
export function fetchBlocksSuccess(accounts, next) { |
||||
return { |
||||
type: BLOCKS_FETCH_SUCCESS, |
||||
accounts, |
||||
next |
||||
}; |
||||
}; |
||||
|
||||
export function fetchBlocksFail(error) { |
||||
return { |
||||
type: BLOCKS_FETCH_FAIL, |
||||
error |
||||
}; |
||||
}; |
||||
|
||||
export function expandBlocks() { |
||||
return (dispatch, getState) => { |
||||
const url = getState().getIn(['user_lists', 'blocks', 'next']); |
||||
|
||||
if (url === null) { |
||||
return; |
||||
} |
||||
|
||||
dispatch(expandBlocksRequest()); |
||||
|
||||
api(getState).get(url).then(response => { |
||||
const next = getLinks(response).refs.find(link => link.rel === 'next'); |
||||
dispatch(expandBlocksSuccess(response.data, next ? next.uri : null)); |
||||
dispatch(fetchRelationships(response.data.map(item => item.id))); |
||||
}).catch(error => dispatch(expandBlocksFail(error))); |
||||
}; |
||||
}; |
||||
|
||||
export function expandBlocksRequest() { |
||||
return { |
||||
type: BLOCKS_EXPAND_REQUEST |
||||
}; |
||||
}; |
||||
|
||||
export function expandBlocksSuccess(accounts, next) { |
||||
return { |
||||
type: BLOCKS_EXPAND_SUCCESS, |
||||
accounts, |
||||
next |
||||
}; |
||||
}; |
||||
|
||||
export function expandBlocksFail(error) { |
||||
return { |
||||
type: BLOCKS_EXPAND_FAIL, |
||||
error |
||||
}; |
||||
}; |
@ -0,0 +1,68 @@ |
||||
import { connect } from 'react-redux'; |
||||
import PureRenderMixin from 'react-addons-pure-render-mixin'; |
||||
import ImmutablePropTypes from 'react-immutable-proptypes'; |
||||
import LoadingIndicator from '../../components/loading_indicator'; |
||||
import { ScrollContainer } from 'react-router-scroll'; |
||||
import Column from '../ui/components/column'; |
||||
import ColumnBackButtonSlim from '../../components/column_back_button_slim'; |
||||
import AccountContainer from '../../containers/account_container'; |
||||
import { fetchBlocks, expandBlocks } from '../../actions/blocks'; |
||||
import { defineMessages, injectIntl } from 'react-intl'; |
||||
|
||||
const messages = defineMessages({ |
||||
heading: { id: 'column.blocks', defaultMessage: 'Blocked' } |
||||
}); |
||||
|
||||
const mapStateToProps = state => ({ |
||||
accountIds: state.getIn(['user_lists', 'blocks', 'items']) |
||||
}); |
||||
|
||||
const Blocks = React.createClass({ |
||||
propTypes: { |
||||
params: React.PropTypes.object.isRequired, |
||||
dispatch: React.PropTypes.func.isRequired, |
||||
accountIds: ImmutablePropTypes.list, |
||||
intl: React.PropTypes.object.isRequired |
||||
}, |
||||
|
||||
mixins: [PureRenderMixin], |
||||
|
||||
componentWillMount () { |
||||
this.props.dispatch(fetchBlocks()); |
||||
}, |
||||
|
||||
handleScroll (e) { |
||||
const { scrollTop, scrollHeight, clientHeight } = e.target; |
||||
|
||||
if (scrollTop === scrollHeight - clientHeight) { |
||||
this.props.dispatch(expandBlocks()); |
||||
} |
||||
}, |
||||
|
||||
render () { |
||||
const { intl, accountIds } = this.props; |
||||
|
||||
if (!accountIds) { |
||||
return ( |
||||
<Column> |
||||
<LoadingIndicator /> |
||||
</Column> |
||||
); |
||||
} |
||||
|
||||
return ( |
||||
<Column icon='users' heading={intl.formatMessage(messages.heading)}> |
||||
<ColumnBackButtonSlim /> |
||||
<ScrollContainer scrollKey='blocks'> |
||||
<div className='scrollable' onScroll={this.handleScroll}> |
||||
{accountIds.map(id => |
||||
<AccountContainer key={id} id={id} /> |
||||
)} |
||||
</div> |
||||
</ScrollContainer> |
||||
</Column> |
||||
); |
||||
} |
||||
}); |
||||
|
||||
export default connect(mapStateToProps)(injectIntl(Blocks)); |
@ -1,7 +0,0 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class Device < ApplicationRecord |
||||
belongs_to :account |
||||
|
||||
validates :account, :registration_id, presence: true |
||||
end |
@ -1,28 +0,0 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class SendPushNotificationService < BaseService |
||||
def call(notification) |
||||
return if ENV['FCM_API_KEY'].blank? |
||||
|
||||
devices = Device.where(account: notification.account).pluck(:registration_id) |
||||
fcm = FCM.new(ENV['FCM_API_KEY']) |
||||
|
||||
response = fcm.send(devices, data: { notification_id: notification.id }, collapse_key: :notifications, priority: :high) |
||||
handle_response(response) |
||||
end |
||||
|
||||
private |
||||
|
||||
def handle_response(response) |
||||
update_canonical_ids(response[:canonical_ids]) if response[:canonical_ids] |
||||
remove_bad_ids(response[:not_registered_ids]) if response[:not_registered_ids] |
||||
end |
||||
|
||||
def update_canonical_ids(ids) |
||||
ids.each { |pair| Device.find_by(registration_id: pair[:old]).update(registration_id: pair[:new]) } |
||||
end |
||||
|
||||
def remove_bad_ids(bad_ids) |
||||
Device.where(registration_id: bad_ids).delete_all unless bad_ids.empty? |
||||
end |
||||
end |
@ -0,0 +1,5 @@ |
||||
class RemoveDevices < ActiveRecord::Migration[5.0] |
||||
def change |
||||
drop_table :devices |
||||
end |
||||
end |
@ -1,3 +0,0 @@ |
||||
Fabricator(:device) do |
||||
registration_id "12345678" |
||||
end |
@ -1,5 +0,0 @@ |
||||
require 'rails_helper' |
||||
|
||||
RSpec.describe Device, type: :model do |
||||
|
||||
end |
Loading…
Reference in new issue