Skip to content

Commit

Permalink
Remove webdav stream
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Dec 19, 2019
1 parent 211aee9 commit 0f7c87c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 42 deletions.
6 changes: 3 additions & 3 deletions app/webdav/client/addWebdavAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Template.addWebdavAccount.events({
return;
}
instance.loading.set(true);
Meteor.call('addWebdavAccount', formData, function(error, response) {
Meteor.call('addWebdavAccount', formData, function(error, success) {
modal.close();
instance.loading.set(false);
if (error) {
return toastr.error(t(error.error));
}
if (!response.success) {
return toastr.error(t(response.message));
if (!success) {
return toastr.error(t('Error'));
}
toastr.success(t('webdav-account-saved'));
});
Expand Down
20 changes: 10 additions & 10 deletions app/webdav/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ Meteor.startup(() => {
return;
}
c.stop();
import('./startup/messageBoxActions');
import('./startup/initCollection');
import('./actionButton');
import('./addWebdavAccount.html');
import('./addWebdavAccount');
import('./webdavFilePicker.html');
import('./webdavFilePicker.css');
import('./webdavFilePicker');
import('./selectWebdavAccount.html');
import('./selectWebdavAccount');
import('./startup/messageBoxActions');
import('./startup/sync');
import('./actionButton');
import('./addWebdavAccount.html');
import('./addWebdavAccount');
import('./webdavFilePicker.html');
import('./webdavFilePicker.css');
import('./webdavFilePicker');
import('./selectWebdavAccount.html');
import('./selectWebdavAccount');
});
});
3 changes: 0 additions & 3 deletions app/webdav/client/lib/streamer.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ import { Tracker } from 'meteor/tracker';

import { APIClient } from '../../../utils/client';
import { WebdavAccounts } from '../../../models/client';
import { webdavStreamer } from '../lib/streamer';
import { Notifications } from '../../../notifications/client';

const events = {
changed: (account) => WebdavAccounts.upsert({ _id: account._id }, account),
removed: ({ _id }) => WebdavAccounts.remove({ _id }),
};

Tracker.autorun(async () => {
if (Meteor.userId()) {
const { accounts } = await APIClient.v1.get('webdav.getMyAccounts');
accounts.forEach((account) => WebdavAccounts.insert(account));
}
webdavStreamer.on('webdavAccounts', (account) => {
const events = {
changed: () => {
delete account.type;
WebdavAccounts.upsert({ _id: account._id }, account);
},
removed: () => WebdavAccounts.remove({ _id: account._id }),
};
events[account.type]();
});
Notifications.onUser('webdav', ({ type, account }) => events[type](account));
});
9 changes: 0 additions & 9 deletions app/webdav/server/lib/webdavStreamer.js

This file was deleted.

10 changes: 7 additions & 3 deletions app/webdav/server/methods/addWebdavAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Match, check } from 'meteor/check';
import { settings } from '../../../settings';
import { WebdavAccounts } from '../../../models';
import { WebdavClientAdapter } from '../lib/webdavClientAdapter';
import { webdavStreamer } from '../lib/webdavStreamer';
import { Notifications } from '../../../notifications/server';

Meteor.methods({
async addWebdavAccount(formData) {
Expand Down Expand Up @@ -50,9 +50,9 @@ Meteor.methods({

await client.stat('/');
WebdavAccounts.insert(accountData);
webdavStreamer.emit('webdavAccounts', {
Notifications.notifyUser(userId, 'webdav', {
type: 'changed',
...accountData,
account: accountData,
});
} catch (error) {
throw new Meteor.Error('could-not-access-webdav', { method: 'addWebdavAccount' });
Expand Down Expand Up @@ -96,6 +96,10 @@ Meteor.methods({
}, {
$set: accountData,
});
Notifications.notifyUser(userId, 'webdav', {
type: 'changed',
account: accountData,
});
} catch (error) {
throw new Meteor.Error('could-not-access-webdav', { method: 'addWebdavAccount' });
}
Expand Down
8 changes: 5 additions & 3 deletions app/webdav/server/methods/removeWebdavAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';

import { WebdavAccounts } from '../../../models';
import { webdavStreamer } from '../lib/webdavStreamer';
import { Notifications } from '../../../notifications/server';

Meteor.methods({
removeWebdavAccount(accountId) {
Expand All @@ -14,10 +14,12 @@ Meteor.methods({

const removed = WebdavAccounts.removeByUserAndId(accountId, Meteor.userId());
if (removed) {
webdavStreamer.emit('webdavAccounts', {
Notifications.notifyUser(Meteor.userId(), 'webdav', {
type: 'removed',
_id: accountId,
account: { _id: accountId },
});
}

return removed;
},
});

0 comments on commit 0f7c87c

Please sign in to comment.