getrooms just get updated rooms
This commit is contained in:
parent
441016330b
commit
d4d031e2e7
|
@ -347,23 +347,31 @@ const RocketChat = {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getRooms() {
|
async getRooms() {
|
||||||
return Promise.all([call('subscriptions/get'), call('rooms/get')]).then(([subscriptions, rooms]) => {
|
const { server, login } = reduxStore.getState();
|
||||||
const { server, login } = reduxStore.getState();
|
let lastMessage = realm
|
||||||
const data = subscriptions.map((subscription) => {
|
.objects('subscriptions')
|
||||||
subscription._updatedAt = (rooms.find(room => room._id === subscription.rid) || {})._updatedAt;
|
.filtered('_server.id = $0', server.server)
|
||||||
subscription._server = { id: server.server };
|
.sorted('_updatedAt', true)[0];
|
||||||
return subscription;
|
lastMessage = lastMessage && new Date(lastMessage._updatedAt);
|
||||||
});
|
let [subscriptions, rooms] = await Promise.all([call('subscriptions/get', lastMessage), call('rooms/get', lastMessage)]);
|
||||||
|
|
||||||
realm.write(() => {
|
if (lastMessage) {
|
||||||
data.forEach((subscription) => {
|
subscriptions = subscriptions.update;
|
||||||
realm.create('subscriptions', subscription, true);
|
rooms = rooms.update;
|
||||||
});
|
}
|
||||||
});
|
const data = subscriptions.map((subscription) => {
|
||||||
Meteor.subscribe('stream-notify-user', `${ login.user.id }/subscriptions-changed`, false);
|
subscription._updatedAt = (rooms.find(room => room._id === subscription.rid) || subscription)._updatedAt;
|
||||||
return data;
|
subscription._server = { id: server.server };
|
||||||
|
return subscription;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
realm.write(() => {
|
||||||
|
data.forEach(subscription =>
|
||||||
|
realm.create('subscriptions', subscription, true));
|
||||||
|
});
|
||||||
|
Meteor.subscribe('stream-notify-user', `${ login.user.id }/subscriptions-changed`, false);
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
logout({ server }) {
|
logout({ server }) {
|
||||||
Meteor.logout();
|
Meteor.logout();
|
||||||
|
|
Loading…
Reference in New Issue