From 5c974990bac46e3217a33286f18a57cfa4316860 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Fri, 21 Feb 2020 12:59:13 -0300 Subject: [PATCH] [FIX] Join Room (#1769) Co-authored-by: Diego Mello --- app/sagas/createChannel.js | 20 ++++++++++++++++++-- app/views/RoomView/index.js | 5 +++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/sagas/createChannel.js b/app/sagas/createChannel.js index 7768aa22b..7047505de 100644 --- a/app/sagas/createChannel.js +++ b/app/sagas/createChannel.js @@ -1,10 +1,12 @@ import { select, put, call, take, takeLatest } from 'redux-saga/effects'; +import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import { CREATE_CHANNEL, LOGIN } from '../actions/actionsTypes'; import { createChannelSuccess, createChannelFailure } from '../actions/createChannel'; import RocketChat from '../lib/rocketchat'; +import database from '../lib/database'; const create = function* create(data) { return yield RocketChat.createChannel(data); @@ -16,8 +18,22 @@ const handleRequest = function* handleRequest({ data }) { if (!auth) { yield take(LOGIN.SUCCESS); } - const result = yield call(create, data); - yield put(createChannelSuccess(result)); + const sub = yield call(create, data); + + try { + const db = database.active; + const subCollection = db.collections.get('subscriptions'); + yield db.action(async() => { + await subCollection.create((s) => { + s._raw = sanitizedRaw({ id: sub.rid }, subCollection.schema); + Object.assign(s, sub); + }); + }); + } catch { + // do nothing + } + + yield put(createChannelSuccess(sub)); } catch (err) { yield put(createChannelFailure(err)); } diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index fb08d61ff..f211dbb96 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -372,8 +372,9 @@ class RoomView extends React.Component { if (this.t !== 'd') { console.log('Room not found'); this.internalSetState({ joined: false }); - } else if (this.rid) { - // We navigate to RoomView before the DM is inserted to the local db + } + if (this.rid) { + // We navigate to RoomView before the Room is inserted to the local db // So we retry just to make sure we have the right content this.retryFindCount = this.retryFindCount + 1 || 1; if (this.retryFindCount <= 3) {