[FIX] Join Room (#1769)
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
9220f9e9e4
commit
5c974990ba
|
@ -1,10 +1,12 @@
|
||||||
import {
|
import {
|
||||||
select, put, call, take, takeLatest
|
select, put, call, take, takeLatest
|
||||||
} from 'redux-saga/effects';
|
} from 'redux-saga/effects';
|
||||||
|
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
|
||||||
|
|
||||||
import { CREATE_CHANNEL, LOGIN } from '../actions/actionsTypes';
|
import { CREATE_CHANNEL, LOGIN } from '../actions/actionsTypes';
|
||||||
import { createChannelSuccess, createChannelFailure } from '../actions/createChannel';
|
import { createChannelSuccess, createChannelFailure } from '../actions/createChannel';
|
||||||
import RocketChat from '../lib/rocketchat';
|
import RocketChat from '../lib/rocketchat';
|
||||||
|
import database from '../lib/database';
|
||||||
|
|
||||||
const create = function* create(data) {
|
const create = function* create(data) {
|
||||||
return yield RocketChat.createChannel(data);
|
return yield RocketChat.createChannel(data);
|
||||||
|
@ -16,8 +18,22 @@ const handleRequest = function* handleRequest({ data }) {
|
||||||
if (!auth) {
|
if (!auth) {
|
||||||
yield take(LOGIN.SUCCESS);
|
yield take(LOGIN.SUCCESS);
|
||||||
}
|
}
|
||||||
const result = yield call(create, data);
|
const sub = yield call(create, data);
|
||||||
yield put(createChannelSuccess(result));
|
|
||||||
|
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) {
|
} catch (err) {
|
||||||
yield put(createChannelFailure(err));
|
yield put(createChannelFailure(err));
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,8 +372,9 @@ class RoomView extends React.Component {
|
||||||
if (this.t !== 'd') {
|
if (this.t !== 'd') {
|
||||||
console.log('Room not found');
|
console.log('Room not found');
|
||||||
this.internalSetState({ joined: false });
|
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
|
// So we retry just to make sure we have the right content
|
||||||
this.retryFindCount = this.retryFindCount + 1 || 1;
|
this.retryFindCount = this.retryFindCount + 1 || 1;
|
||||||
if (this.retryFindCount <= 3) {
|
if (this.retryFindCount <= 3) {
|
||||||
|
|
Loading…
Reference in New Issue