[FIX] Delete room error (#485)

This commit is contained in:
Diego Mello 2018-10-16 17:30:04 -03:00 committed by GitHub
parent bb8649cac4
commit 44fcb327cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 16 deletions

View File

@ -50,9 +50,8 @@ export default class RoomActionsView extends LoggedView {
super('RoomActionsView', props); super('RoomActionsView', props);
const { rid } = props; const { rid } = props;
this.rooms = database.objects('subscriptions').filtered('rid = $0', rid); this.rooms = database.objects('subscriptions').filtered('rid = $0', rid);
[this.room] = this.rooms;
this.state = { this.state = {
room: this.room, room: this.rooms[0] || {},
onlineMembers: [], onlineMembers: [],
allMembers: [], allMembers: [],
member: {} member: {}
@ -90,11 +89,9 @@ export default class RoomActionsView extends LoggedView {
} }
get canAddUser() { get canAddUser() {
const { const { allMembers, room } = this.state;
rid, t
} = this.room;
const { allMembers } = this.state;
const { username } = this.props; const { username } = this.props;
const { rid, t } = room;
// TODO: same test joined // TODO: same test joined
const userInRoom = !!allMembers.find(m => m.username === username); const userInRoom = !!allMembers.find(m => m.username === username);
@ -126,10 +123,10 @@ export default class RoomActionsView extends LoggedView {
} }
get sections() { get sections() {
const { onlineMembers, room } = this.state;
const { const {
rid, t, blocker, notifications rid, t, blocker, notifications
} = this.room; } = room;
const { onlineMembers } = this.state;
const sections = [{ const sections = [{
data: [{ data: [{
@ -325,7 +322,7 @@ export default class RoomActionsView extends LoggedView {
} }
updateRoom = () => { updateRoom = () => {
this.setState({ room: this.room }); this.setState({ room: this.rooms[0] || {} });
} }
toggleBlockUser = async() => { toggleBlockUser = async() => {

View File

@ -52,7 +52,7 @@ export default class RoomInfoEditView extends LoggedView {
this.rooms = database.objects('subscriptions').filtered('rid = $0', rid); this.rooms = database.objects('subscriptions').filtered('rid = $0', rid);
this.permissions = {}; this.permissions = {};
this.state = { this.state = {
room: {}, room: this.rooms[0] || {},
name: '', name: '',
description: '', description: '',
topic: '', topic: '',
@ -67,8 +67,8 @@ export default class RoomInfoEditView extends LoggedView {
} }
async componentDidMount() { componentDidMount() {
await this.updateRoom(); this.updateRoom();
this.init(); this.init();
this.rooms.addListener(this.updateRoom); this.rooms.addListener(this.updateRoom);
const { room } = this.state; const { room } = this.state;
@ -79,9 +79,8 @@ export default class RoomInfoEditView extends LoggedView {
this.rooms.removeAllListeners(); this.rooms.removeAllListeners();
} }
updateRoom = async() => { updateRoom = () => {
const [room] = this.rooms; this.setState({ room: this.rooms[0] || {} });
await this.setState({ room });
} }
init = () => { init = () => {

View File

@ -223,7 +223,7 @@ export default class RoomView extends LoggedView {
if (this.rooms.length > 0) { if (this.rooms.length > 0) {
const { room: prevRoom } = this.state; const { room: prevRoom } = this.state;
const room = JSON.parse(JSON.stringify(this.rooms[0])); const room = JSON.parse(JSON.stringify(this.rooms[0] || {}));
this.setState({ room }); this.setState({ room });
if (!prevRoom.rid) { if (!prevRoom.rid) {