[FIX] Fetch rooms date (#662)
This commit is contained in:
parent
8c1b57eb26
commit
6106c40557
|
@ -1,17 +1,8 @@
|
||||||
import database from '../realm';
|
export default function(updatedSince) {
|
||||||
|
|
||||||
const lastMessage = () => {
|
|
||||||
const message = database
|
|
||||||
.objects('subscriptions')
|
|
||||||
.sorted('roomUpdatedAt', true)[0];
|
|
||||||
return message && new Date(message.roomUpdatedAt).toISOString();
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function() {
|
|
||||||
const updatedSince = lastMessage();
|
|
||||||
// subscriptions.get: Since RC 0.60.0
|
// subscriptions.get: Since RC 0.60.0
|
||||||
// rooms.get: Since RC 0.62.0
|
// rooms.get: Since RC 0.62.0
|
||||||
if (updatedSince) {
|
if (updatedSince) {
|
||||||
|
updatedSince = updatedSince.toISOString();
|
||||||
return Promise.all([this.sdk.get('subscriptions.get', { updatedSince }), this.sdk.get('rooms.get', { updatedSince })]);
|
return Promise.all([this.sdk.get('subscriptions.get', { updatedSince }), this.sdk.get('rooms.get', { updatedSince })]);
|
||||||
}
|
}
|
||||||
return Promise.all([this.sdk.get('subscriptions.get'), this.sdk.get('rooms.get')]);
|
return Promise.all([this.sdk.get('subscriptions.get'), this.sdk.get('rooms.get')]);
|
||||||
|
|
|
@ -10,7 +10,8 @@ const serversSchema = {
|
||||||
properties: {
|
properties: {
|
||||||
id: 'string',
|
id: 'string',
|
||||||
name: { type: 'string', optional: true },
|
name: { type: 'string', optional: true },
|
||||||
iconURL: { type: 'string', optional: true }
|
iconURL: { type: 'string', optional: true },
|
||||||
|
roomsUpdatedAt: { type: 'date', optional: true }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,7 +23,6 @@ const settingsSchema = {
|
||||||
valueAsString: { type: 'string', optional: true },
|
valueAsString: { type: 'string', optional: true },
|
||||||
valueAsBoolean: { type: 'bool', optional: true },
|
valueAsBoolean: { type: 'bool', optional: true },
|
||||||
valueAsNumber: { type: 'int', optional: true },
|
valueAsNumber: { type: 'int', optional: true },
|
||||||
|
|
||||||
_updatedAt: { type: 'date', optional: true }
|
_updatedAt: { type: 'date', optional: true }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -308,7 +308,7 @@ class DB {
|
||||||
schema: [
|
schema: [
|
||||||
serversSchema
|
serversSchema
|
||||||
],
|
],
|
||||||
deleteRealmIfMigrationNeeded: true
|
schemaVersion: 1
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ class DB {
|
||||||
return this.databases.activeDB = new Realm({
|
return this.databases.activeDB = new Realm({
|
||||||
path: `${ path }.realm`,
|
path: `${ path }.realm`,
|
||||||
schema,
|
schema,
|
||||||
deleteRealmIfMigrationNeeded: true
|
schemaVersion: 1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,34 @@
|
||||||
import { put, takeLatest } from 'redux-saga/effects';
|
import {
|
||||||
|
put, takeLatest, select
|
||||||
|
} from 'redux-saga/effects';
|
||||||
|
|
||||||
import * as types from '../actions/actionsTypes';
|
import * as types from '../actions/actionsTypes';
|
||||||
import { roomsSuccess, roomsFailure } from '../actions/rooms';
|
import { roomsSuccess, roomsFailure } from '../actions/rooms';
|
||||||
import RocketChat from '../lib/rocketchat';
|
|
||||||
import database from '../lib/realm';
|
import database from '../lib/realm';
|
||||||
import log from '../utils/log';
|
import log from '../utils/log';
|
||||||
import mergeSubscriptionsRooms from '../lib/methods/helpers/mergeSubscriptionsRooms';
|
import mergeSubscriptionsRooms from '../lib/methods/helpers/mergeSubscriptionsRooms';
|
||||||
|
import RocketChat from '../lib/rocketchat';
|
||||||
|
|
||||||
const handleRoomsRequest = function* handleRoomsRequest() {
|
const handleRoomsRequest = function* handleRoomsRequest() {
|
||||||
try {
|
try {
|
||||||
const [subscriptionsResult, roomsResult] = yield RocketChat.getRooms();
|
const newRoomsUpdatedAt = new Date();
|
||||||
|
const server = yield select(state => state.server.server);
|
||||||
|
const [serverRecord] = database.databases.serversDB.objects('servers').filtered('id = $0', server);
|
||||||
|
const { roomsUpdatedAt } = serverRecord;
|
||||||
|
const [subscriptionsResult, roomsResult] = yield RocketChat.getRooms(roomsUpdatedAt);
|
||||||
const { subscriptions } = mergeSubscriptionsRooms(subscriptionsResult, roomsResult);
|
const { subscriptions } = mergeSubscriptionsRooms(subscriptionsResult, roomsResult);
|
||||||
|
|
||||||
database.write(() => {
|
database.write(() => {
|
||||||
subscriptions.forEach(subscription => database.create('subscriptions', subscription, true));
|
subscriptions.forEach(subscription => database.create('subscriptions', subscription, true));
|
||||||
});
|
});
|
||||||
|
database.databases.serversDB.write(() => {
|
||||||
|
try {
|
||||||
|
database.databases.serversDB.create('servers', { id: server, roomsUpdatedAt: newRoomsUpdatedAt }, true);
|
||||||
|
} catch (e) {
|
||||||
|
log('handleRoomsRequest update roomsUpdatedAt', e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
yield put(roomsSuccess());
|
yield put(roomsSuccess());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
yield put(roomsFailure(e));
|
yield put(roomsFailure(e));
|
||||||
|
|
Loading…
Reference in New Issue