parent
d3acc17fc1
commit
c81182c9cf
|
@ -89,8 +89,10 @@ export default class MessageActions extends React.Component {
|
|||
this.options = ['Cancel'];
|
||||
this.CANCEL_INDEX = 0;
|
||||
// Reply
|
||||
this.options.push('Reply');
|
||||
this.REPLY_INDEX = this.options.length - 1;
|
||||
if (!this.isRoomReadOnly()) {
|
||||
this.options.push('Reply');
|
||||
this.REPLY_INDEX = this.options.length - 1;
|
||||
}
|
||||
// Edit
|
||||
if (this.allowEdit(nextProps)) {
|
||||
this.options.push('Edit');
|
||||
|
@ -103,8 +105,10 @@ export default class MessageActions extends React.Component {
|
|||
this.options.push('Copy Message');
|
||||
this.COPY_INDEX = this.options.length - 1;
|
||||
// Quote
|
||||
this.options.push('Quote');
|
||||
this.QUOTE_INDEX = this.options.length - 1;
|
||||
if (!this.isRoomReadOnly()) {
|
||||
this.options.push('Quote');
|
||||
this.QUOTE_INDEX = this.options.length - 1;
|
||||
}
|
||||
// Star
|
||||
if (this.props.Message_AllowStarring) {
|
||||
this.options.push(actionMessage.starred ? 'Unstar' : 'Star');
|
||||
|
@ -165,7 +169,12 @@ export default class MessageActions extends React.Component {
|
|||
|
||||
isOwn = props => props.actionMessage.u && props.actionMessage.u._id === props.user.id;
|
||||
|
||||
isRoomReadOnly = () => this.props.room.ro;
|
||||
|
||||
allowEdit = (props) => {
|
||||
if (this.isRoomReadOnly()) {
|
||||
return false;
|
||||
}
|
||||
const editOwn = this.isOwn(props);
|
||||
const { Message_AllowEditing: isEditAllowed } = this.props;
|
||||
if (!(this.hasEditPermission || (isEditAllowed && editOwn))) {
|
||||
|
@ -187,6 +196,9 @@ export default class MessageActions extends React.Component {
|
|||
}
|
||||
|
||||
allowDelete = (props) => {
|
||||
if (this.isRoomReadOnly()) {
|
||||
return false;
|
||||
}
|
||||
const deleteOwn = this.isOwn(props);
|
||||
const { Message_AllowDeleting: isDeleteAllowed } = this.props;
|
||||
if (!(this.hasDeletePermission || (isDeleteAllowed && deleteOwn) || this.hasForceDeletePermission)) {
|
||||
|
|
|
@ -79,7 +79,8 @@ const subscriptionSchema = {
|
|||
userMentions: { type: 'int', optional: true },
|
||||
// userMentions: 0,
|
||||
// groupMentions: 0,
|
||||
roomUpdatedAt: { type: 'date', optional: true }
|
||||
roomUpdatedAt: { type: 'date', optional: true },
|
||||
ro: { type: 'bool', optional: true }
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -127,6 +127,7 @@ const RocketChat = {
|
|||
const sub = database.objects('subscriptions').filtered('rid == $0', data._id)[0];
|
||||
database.write(() => {
|
||||
sub.roomUpdatedAt = data._updatedAt;
|
||||
sub.ro = data.ro;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -424,6 +425,7 @@ const RocketChat = {
|
|||
const room = rooms.find(({ _id }) => _id === subscription.rid);
|
||||
if (room) {
|
||||
subscription.roomUpdatedAt = room._updatedAt;
|
||||
subscription.ro = room.ro;
|
||||
}
|
||||
if (subscription.roles) {
|
||||
subscription.roles = subscription.roles.map(role => ({ value: role }));
|
||||
|
|
|
@ -73,11 +73,12 @@ export default class RoomView extends React.Component {
|
|||
.filtered('rid = $0', this.rid)
|
||||
.sorted('ts', true);
|
||||
const rowIds = this.data.map((row, index) => index);
|
||||
[this.room] = database.objects('subscriptions').filtered('rid = $0', this.rid);
|
||||
this.rooms = database.objects('subscriptions').filtered('rid = $0', this.rid);
|
||||
this.state = {
|
||||
dataSource: ds.cloneWithRows(this.data, rowIds),
|
||||
loaded: true,
|
||||
joined: typeof props.rid === 'undefined'
|
||||
joined: typeof props.rid === 'undefined',
|
||||
readOnly: false
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -85,6 +86,7 @@ export default class RoomView extends React.Component {
|
|||
this.props.navigation.setParams({
|
||||
title: this.name
|
||||
});
|
||||
this.updateRoom();
|
||||
this.props.openRoom({ rid: this.rid, name: this.name, ls: this.room.ls });
|
||||
if (this.room.alert || this.room.unread || this.room.userMentions) {
|
||||
this.props.setLastOpen(this.room.ls);
|
||||
|
@ -92,6 +94,7 @@ export default class RoomView extends React.Component {
|
|||
this.props.setLastOpen(null);
|
||||
}
|
||||
this.data.addListener(this.updateState);
|
||||
this.rooms.addListener(this.updateRoom);
|
||||
}
|
||||
shouldComponentUpdate(nextProps, nextState) {
|
||||
return !(equal(this.props, nextProps) && equal(this.state, nextState));
|
||||
|
@ -134,6 +137,11 @@ export default class RoomView extends React.Component {
|
|||
});
|
||||
}, 50);
|
||||
|
||||
updateRoom = () => {
|
||||
[this.room] = this.rooms;
|
||||
this.setState({ readOnly: this.room.ro });
|
||||
}
|
||||
|
||||
sendMessage = message => RocketChat.sendMessage(this.rid, message).then(() => {
|
||||
this.props.setLastOpen(null);
|
||||
});
|
||||
|
@ -167,6 +175,13 @@ export default class RoomView extends React.Component {
|
|||
</View>
|
||||
);
|
||||
}
|
||||
if (this.state.readOnly) {
|
||||
return (
|
||||
<View style={styles.readOnly}>
|
||||
<Text>This room is read only</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
return <MessageBox ref={box => (this.box = box)} onSubmit={this.sendMessage} rid={this.rid} />;
|
||||
};
|
||||
|
||||
|
|
|
@ -30,5 +30,8 @@ export default StyleSheet.create({
|
|||
textAlign: 'center',
|
||||
padding: 5,
|
||||
color: '#ccc'
|
||||
},
|
||||
readOnly: {
|
||||
padding: 10
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue