diff --git a/app/views/RoomActionsView/index.js b/app/views/RoomActionsView/index.js index e7febc598..7b7a43cb2 100644 --- a/app/views/RoomActionsView/index.js +++ b/app/views/RoomActionsView/index.js @@ -50,9 +50,8 @@ export default class RoomActionsView extends LoggedView { super('RoomActionsView', props); const { rid } = props; this.rooms = database.objects('subscriptions').filtered('rid = $0', rid); - [this.room] = this.rooms; this.state = { - room: this.room, + room: this.rooms[0] || {}, onlineMembers: [], allMembers: [], member: {} @@ -90,11 +89,9 @@ export default class RoomActionsView extends LoggedView { } get canAddUser() { - const { - rid, t - } = this.room; - const { allMembers } = this.state; + const { allMembers, room } = this.state; const { username } = this.props; + const { rid, t } = room; // TODO: same test joined const userInRoom = !!allMembers.find(m => m.username === username); @@ -126,10 +123,10 @@ export default class RoomActionsView extends LoggedView { } get sections() { + const { onlineMembers, room } = this.state; const { rid, t, blocker, notifications - } = this.room; - const { onlineMembers } = this.state; + } = room; const sections = [{ data: [{ @@ -325,7 +322,7 @@ export default class RoomActionsView extends LoggedView { } updateRoom = () => { - this.setState({ room: this.room }); + this.setState({ room: this.rooms[0] || {} }); } toggleBlockUser = async() => { diff --git a/app/views/RoomInfoEditView/index.js b/app/views/RoomInfoEditView/index.js index 8728c270f..f572c1e8c 100644 --- a/app/views/RoomInfoEditView/index.js +++ b/app/views/RoomInfoEditView/index.js @@ -52,7 +52,7 @@ export default class RoomInfoEditView extends LoggedView { this.rooms = database.objects('subscriptions').filtered('rid = $0', rid); this.permissions = {}; this.state = { - room: {}, + room: this.rooms[0] || {}, name: '', description: '', topic: '', @@ -67,8 +67,8 @@ export default class RoomInfoEditView extends LoggedView { } - async componentDidMount() { - await this.updateRoom(); + componentDidMount() { + this.updateRoom(); this.init(); this.rooms.addListener(this.updateRoom); const { room } = this.state; @@ -79,9 +79,8 @@ export default class RoomInfoEditView extends LoggedView { this.rooms.removeAllListeners(); } - updateRoom = async() => { - const [room] = this.rooms; - await this.setState({ room }); + updateRoom = () => { + this.setState({ room: this.rooms[0] || {} }); } init = () => { diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index 3de09327a..882b5af14 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -223,7 +223,7 @@ export default class RoomView extends LoggedView { if (this.rooms.length > 0) { 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 }); if (!prevRoom.rid) {