amazing room subscriptions

This commit is contained in:
Guilherme Gazzo 2017-11-20 22:52:48 -02:00
parent 80c019a973
commit da4ecdc3b2
1 changed files with 28 additions and 7 deletions

View File

@ -62,24 +62,44 @@ const RocketChat = {
Meteor.ddp.on('connected', async() => { Meteor.ddp.on('connected', async() => {
Meteor.ddp.on('changed', (ddbMessage) => { Meteor.ddp.on('changed', (ddbMessage) => {
const server = { id: reduxStore.getState().server.server };
if (ddbMessage.collection === 'stream-room-messages') { if (ddbMessage.collection === 'stream-room-messages') {
realm.write(() => { realm.write(() => {
const message = ddbMessage.fields.args[0]; const message = ddbMessage.fields.args[0];
message.temp = false; message.temp = false;
message._server = { id: reduxStore.getState().server.server }; message._server = server;
realm.create('messages', message, true); realm.create('messages', message, true);
}); });
} }
if (ddbMessage.collection === 'stream-notify-user') { if (ddbMessage.collection === 'stream-notify-user') {
realm.write(() => { const [type, data] = ddbMessage.fields.args;
const data = ddbMessage.fields.args[1]; const [, ev] = ddbMessage.fields.eventName.split('/');
data._server = { id: reduxStore.getState().server.server }; if (/subscriptions/.test(ev)) {
realm.create('subscriptions', data, true); switch (type) {
}); case 'inserted':
data._server = server;
realm.write(() => {
realm.create('subscriptions', data, true);
});
break;
case 'updated':
delete data._updatedAt;
realm.write(() => {
realm.create('subscriptions', data, true);
});
break;
default:
}
}
if (/rooms/.test(ev) && type === 'updated') {
const sub = realm.objects('subscriptions').filtered('rid == $0', data._id)[0];
realm.write(() => {
sub._updatedAt = data._updatedAt;
});
}
} }
}); });
RocketChat.getSettings(); RocketChat.getSettings();
}); });
}) })
@ -371,6 +391,7 @@ const RocketChat = {
realm.create('subscriptions', subscription, true)); realm.create('subscriptions', subscription, true));
}); });
Meteor.subscribe('stream-notify-user', `${ login.user.id }/subscriptions-changed`, false); Meteor.subscribe('stream-notify-user', `${ login.user.id }/subscriptions-changed`, false);
Meteor.subscribe('stream-notify-user', `${ login.user.id }/rooms-changed`, false);
return data; return data;
}, },
logout({ server }) { logout({ server }) {