Permalink action
This commit is contained in:
parent
ff97888aa9
commit
b5067d3526
|
@ -39,7 +39,10 @@ export const MESSAGES = createRequestTypes('MESSAGES', [
|
|||
'EDIT_FAILURE',
|
||||
'STAR_REQUEST',
|
||||
'STAR_SUCCESS',
|
||||
'STAR_FAILURE'
|
||||
'STAR_FAILURE',
|
||||
'PERMALINK_REQUEST',
|
||||
'PERMALINK_SUCCESS',
|
||||
'PERMALINK_FAILURE'
|
||||
]);
|
||||
export const CREATE_CHANNEL = createRequestTypes('CREATE_CHANNEL', [
|
||||
...defaultTypes,
|
||||
|
|
|
@ -84,3 +84,24 @@ export function starFailure() {
|
|||
type: types.MESSAGES.STAR_FAILURE
|
||||
};
|
||||
}
|
||||
|
||||
export function permalinkRequest(message) {
|
||||
return {
|
||||
type: types.MESSAGES.PERMALINK_REQUEST,
|
||||
message
|
||||
};
|
||||
}
|
||||
|
||||
export function permalinkSuccess(permalink) {
|
||||
return {
|
||||
type: types.MESSAGES.PERMALINK_SUCCESS,
|
||||
permalink
|
||||
};
|
||||
}
|
||||
|
||||
export function permalinkFailure(err) {
|
||||
return {
|
||||
type: types.MESSAGES.PERMALINK_FAILURE,
|
||||
err
|
||||
};
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import { connect } from 'react-redux';
|
|||
import Card from './Card';
|
||||
import User from './User';
|
||||
import Avatar from '../Avatar';
|
||||
import { deleteRequest, editInit, starRequest } from '../../actions/messages';
|
||||
import { deleteRequest, editInit, starRequest, permalinkRequest } from '../../actions/messages';
|
||||
|
||||
const title = 'Message actions';
|
||||
const options = ['Cancel', 'Reply', 'Edit', 'Permalink', 'Copy', 'Quote', 'Star Message', 'Delete'];
|
||||
|
@ -38,11 +38,13 @@ const styles = StyleSheet.create({
|
|||
});
|
||||
|
||||
@connect(state => ({
|
||||
message: state.messages.message
|
||||
message: state.messages.message,
|
||||
permalink: state.messages.permalink
|
||||
}), dispatch => ({
|
||||
deleteRequest: message => dispatch(deleteRequest(message)),
|
||||
editInit: message => dispatch(editInit(message)),
|
||||
starRequest: message => dispatch(starRequest(message))
|
||||
starRequest: message => dispatch(starRequest(message)),
|
||||
permalinkRequest: message => dispatch(permalinkRequest(message))
|
||||
}))
|
||||
export default class Message extends React.Component {
|
||||
static propTypes = {
|
||||
|
@ -52,15 +54,28 @@ export default class Message extends React.Component {
|
|||
deleteRequest: PropTypes.func.isRequired,
|
||||
editInit: PropTypes.func.isRequired,
|
||||
starRequest: PropTypes.func.isRequired,
|
||||
message: PropTypes.object
|
||||
permalinkRequest: PropTypes.func.isRequired,
|
||||
message: PropTypes.object,
|
||||
permalink: PropTypes.string
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { copyPermalink: false };
|
||||
this.handleActionPress = this.handleActionPress.bind(this);
|
||||
this.showActions = this.showActions.bind(this);
|
||||
}
|
||||
|
||||
async componentWillReceiveProps(props) {
|
||||
if (props.permalink) {
|
||||
if (this.state.copyPermalink) {
|
||||
this.setState({ copyPermalink: false });
|
||||
await Clipboard.setString(props.permalink);
|
||||
Alert.alert('Permalink copied to clipboard!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isDeleted() {
|
||||
return !this.props.item.msg;
|
||||
}
|
||||
|
@ -103,18 +118,25 @@ export default class Message extends React.Component {
|
|||
|
||||
handleCopy = async() => {
|
||||
await Clipboard.setString(this.props.item.msg);
|
||||
Alert.alert('Copied to Clipboard!');
|
||||
Alert.alert('Copied to clipboard!');
|
||||
}
|
||||
|
||||
handleStar() {
|
||||
this.props.starRequest(this.props.item);
|
||||
}
|
||||
|
||||
handlePermalink() {
|
||||
this.setState({ copyPermalink: true });
|
||||
this.props.permalinkRequest(this.props.item);
|
||||
}
|
||||
|
||||
handleActionPress = (actionIndex) => {
|
||||
if (actionIndex === 7) {
|
||||
this.handleDelete();
|
||||
} else if (actionIndex === 2) {
|
||||
this.handleEdit();
|
||||
} else if (actionIndex === 3) {
|
||||
this.handlePermalink();
|
||||
} else if (actionIndex === 4) {
|
||||
this.handleCopy();
|
||||
} else if (actionIndex === 6) {
|
||||
|
|
|
@ -464,6 +464,32 @@ const RocketChat = {
|
|||
},
|
||||
starMessage(message) {
|
||||
return call('starMessage', message);
|
||||
},
|
||||
getPermalink(message) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const result = realm.objects('subscriptions').filtered('rid = $0', message.rid);
|
||||
|
||||
if (result.length === 0) {
|
||||
return reject(new Error('Room not found'));
|
||||
}
|
||||
|
||||
const room = result[0];
|
||||
let roomType;
|
||||
switch (room.t) {
|
||||
case 'p':
|
||||
roomType = 'group';
|
||||
break;
|
||||
case 'c':
|
||||
roomType = 'channel';
|
||||
break;
|
||||
case 'd':
|
||||
roomType = 'direct';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return resolve(`${ room._server.id }/${ roomType }/${ room.name }?msg=${ message._id }`);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@ const initialState = {
|
|||
isFetching: false,
|
||||
failure: false,
|
||||
message: {},
|
||||
editing: false
|
||||
editing: false,
|
||||
permalink: ''
|
||||
};
|
||||
|
||||
export default function messages(state = initialState, action) {
|
||||
|
@ -38,6 +39,11 @@ export default function messages(state = initialState, action) {
|
|||
message: {},
|
||||
editing: false
|
||||
};
|
||||
case types.MESSAGES.PERMALINK_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
permalink: action.permalink
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -8,13 +8,16 @@ import {
|
|||
editSuccess,
|
||||
editFailure,
|
||||
starSuccess,
|
||||
starFailure
|
||||
starFailure,
|
||||
permalinkSuccess,
|
||||
permalinkFailure
|
||||
} from '../actions/messages';
|
||||
import RocketChat from '../lib/rocketchat';
|
||||
|
||||
const deleteMessage = message => RocketChat.deleteMessage(message);
|
||||
const editMessage = message => RocketChat.editMessage(message);
|
||||
const starMessage = message => RocketChat.starMessage(message);
|
||||
const getPermalink = message => RocketChat.getPermalink(message);
|
||||
|
||||
const get = function* get({ rid }) {
|
||||
const auth = yield select(state => state.login.isAuthenticated);
|
||||
|
@ -58,10 +61,20 @@ const handleStarRequest = function* handleStarRequest({ message }) {
|
|||
}
|
||||
};
|
||||
|
||||
const handlePermalinkRequest = function* handlePermalinkRequest({ message }) {
|
||||
try {
|
||||
const permalink = yield call(getPermalink, message);
|
||||
yield put(permalinkSuccess(permalink));
|
||||
} catch (error) {
|
||||
yield put(permalinkFailure(error));
|
||||
}
|
||||
};
|
||||
|
||||
const root = function* root() {
|
||||
yield takeLatest(MESSAGES.REQUEST, get);
|
||||
yield takeLatest(MESSAGES.DELETE_REQUEST, handleDeleteRequest);
|
||||
yield takeLatest(MESSAGES.EDIT_REQUEST, handleEditRequest);
|
||||
yield takeLatest(MESSAGES.STAR_REQUEST, handleStarRequest);
|
||||
yield takeLatest(MESSAGES.PERMALINK_REQUEST, handlePermalinkRequest);
|
||||
};
|
||||
export default root;
|
||||
|
|
Loading…
Reference in New Issue