diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2019-03-06 17:55:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-06 17:55:18 +0300 |
commit | a9dd3439a936ed46f006c3ad9ad31b1a07b630c1 (patch) | |
tree | c89fa51fbf09f73fb6055849162a797b35494e35 /src | |
parent | aa2fdbca85218a6e1e142562b09180d7f3fb5298 (diff) | |
parent | d31df72df508604336e017c1edbd2689e74e7462 (diff) |
Merge pull request #1583 from nextcloud/lint/serivces
Apply lint:autofix on js services
Diffstat (limited to 'src')
-rw-r--r-- | src/service/AccountService.js | 4 | ||||
-rw-r--r-- | src/service/AttachmentService.js | 27 | ||||
-rw-r--r-- | src/service/AutocompleteService.js | 3 | ||||
-rw-r--r-- | src/service/AvatarService.js | 4 | ||||
-rw-r--r-- | src/service/DAVService.js | 48 | ||||
-rw-r--r-- | src/service/FolderService.js | 14 | ||||
-rw-r--r-- | src/service/MessageService.js | 128 | ||||
-rw-r--r-- | src/service/NotificationService.js | 38 | ||||
-rw-r--r-- | src/service/PreferenceService.js | 10 | ||||
-rw-r--r-- | src/service/aliasesservice.js | 37 |
10 files changed, 155 insertions, 158 deletions
diff --git a/src/service/AccountService.js b/src/service/AccountService.js index dcb424a13..e07d05b86 100644 --- a/src/service/AccountService.js +++ b/src/service/AccountService.js @@ -1,4 +1,4 @@ -import { generateUrl } from 'nextcloud-server/dist/router' +import {generateUrl} from 'nextcloud-server/dist/router' import HttpClient from 'nextcloud-axios' export const fixAccountId = original => { @@ -42,7 +42,7 @@ export const fetch = id => { export const deleteAccount = id => { const url = generateUrl('/apps/mail/api/accounts/{id}', { - id + id, }) return HttpClient.delete(url).then(resp => fixAccountId(resp.data)) diff --git a/src/service/AttachmentService.js b/src/service/AttachmentService.js index ba846b9f7..0a9f94caf 100644 --- a/src/service/AttachmentService.js +++ b/src/service/AttachmentService.js @@ -22,24 +22,27 @@ import Axios from 'nextcloud-axios' import {generateUrl} from 'nextcloud-server/dist/router' -export function saveAttachmentToFiles (accountId, folderId, messageId, attachmentId, directory) { - const url = generateUrl('apps/mail/api/accounts/{accountId}/folders/{folderId}/messages/{messageId}/attachment/{attachmentId}', { - accountId, - folderId, - messageId, - attachmentId, - }) +export function saveAttachmentToFiles(accountId, folderId, messageId, attachmentId, directory) { + const url = generateUrl( + 'apps/mail/api/accounts/{accountId}/folders/{folderId}/messages/{messageId}/attachment/{attachmentId}', + { + accountId, + folderId, + messageId, + attachmentId, + } + ) return Axios.post(url, { - targetPath: directory + targetPath: directory, }) } -export function saveAttachmentsToFiles (accountId, folderId, messageId, directory) { +export function saveAttachmentsToFiles(accountId, folderId, messageId, directory) { return saveAttachmentToFiles(accountId, folderId, messageId, 0, directory) } -export function downloadAttachment (url) { +export function downloadAttachment(url) { return Axios.get(url).then(res => res.data) } @@ -47,7 +50,7 @@ export const uploadLocalAttachment = file => { const url = generateUrl('/apps/mail/api/attachments') const data = new FormData() const opts = { - onUploadProgress: prog => console.log(prog, prog.loaded, prog.total) + onUploadProgress: prog => console.log(prog, prog.loaded, prog.total), } data.append('attachment', file) @@ -56,7 +59,7 @@ export const uploadLocalAttachment = file => { .then(({id}) => { return { file, - id + id, } }) } diff --git a/src/service/AutocompleteService.js b/src/service/AutocompleteService.js index ab825d4db..02312e120 100644 --- a/src/service/AutocompleteService.js +++ b/src/service/AutocompleteService.js @@ -27,6 +27,5 @@ export const findRecipient = term => { term, }) - return Axios.get(url) - .then(resp => resp.data) + return Axios.get(url).then(resp => resp.data) } diff --git a/src/service/AvatarService.js b/src/service/AvatarService.js index 61fdcda26..ca0acb1f4 100644 --- a/src/service/AvatarService.js +++ b/src/service/AvatarService.js @@ -30,7 +30,7 @@ export const fetchAvatarUrl = email => { } const url = generateUrl('/apps/mail/api/avatars/url/{email}', { - email + email, }) return Axios.get(url) @@ -38,7 +38,7 @@ export const fetchAvatarUrl = email => { .then(avatar => { if (avatar.isExternal) { return generateUrl('/apps/mail/api/avatars/image/{email}', { - email: email + email: email, }) } else { return avatar.url diff --git a/src/service/DAVService.js b/src/service/DAVService.js index cdcb882c4..2d137e336 100644 --- a/src/service/DAVService.js +++ b/src/service/DAVService.js @@ -21,13 +21,8 @@ import dav from 'davclient.js' import ical from 'ical.js' -import { - getCurrentUID, - getRequestToken -} from 'nextcloud-server/dist/auth' -import { - generateRemoteUrl -} from 'nextcloud-server/dist/router' +import {getCurrentUID, getRequestToken} from 'nextcloud-server/dist/auth' +import {generateRemoteUrl} from 'nextcloud-server/dist/router' const client = new dav.Client({ baseUrl: generateRemoteUrl('dav/calendars'), @@ -37,7 +32,7 @@ const client = new dav.Client({ 'http://apple.com/ns/ical/': 'aapl', 'http://owncloud.org/ns': 'oc', 'http://calendarserver.org/ns/': 'cs', - } + }, }) const props = [ '{DAV:}displayname', @@ -75,8 +70,7 @@ const getACLFromResponse = properties => { properties.canWrite = canWrite } - -const getCalendarData = (properties) => { +const getCalendarData = properties => { getACLFromResponse(properties) const data = { @@ -84,7 +78,7 @@ const getCalendarData = (properties) => { color: properties['{http://apple.com/ns/ical/}calendar-color'], order: properties['{http://apple.com/ns/ical/}calendar-order'], components: { - vevent: false + vevent: false, }, writable: properties.canWrite, } @@ -107,9 +101,11 @@ export const getUserCalendars = () => { var url = generateRemoteUrl('dav/calendars') + '/' + getCurrentUID().uid + '/' return getRequestToken() - .then(token => client.propFind(url, props, 1, { - requesttoken: token - })) + .then(token => + client.propFind(url, props, 1, { + requesttoken: token, + }) + ) .then(data => { const calendars = [] @@ -133,7 +129,9 @@ export const getUserCalendars = () => { const getRandomString = () => { let str = '' for (let i = 0; i < 7; i++) { - str += Math.random().toString(36).substring(7) + str += Math.random() + .toString(36) + .substring(7) } return str } @@ -146,7 +144,7 @@ const createICalElement = () => { return root } -const splitCalendar = (data) => { +const splitCalendar = data => { const timezones = [] const allObjects = {} const jCal = ical.parse(data) @@ -184,7 +182,7 @@ const splitCalendar = (data) => { return { name: components.getFirstPropertyValue('x-wr-calname'), color: components.getFirstPropertyValue('x-apple-calendar-color'), - split + split, } } @@ -202,12 +200,16 @@ export const importCalendarEvent = url => data => { components.forEach(componentName => { for (let componentId in file.split[componentName]) { const component = file.split[componentName][componentId] - promises.push(Promise.resolve($.ajax({ - url: url + getRandomString(), - method: 'PUT', - contentType: 'text/calendar; charset=utf-8', - data: component - }))) + promises.push( + Promise.resolve( + $.ajax({ + url: url + getRandomString(), + method: 'PUT', + contentType: 'text/calendar; charset=utf-8', + data: component, + }) + ) + ) } }) diff --git a/src/service/FolderService.js b/src/service/FolderService.js index fa5dca2f7..829bc3938 100644 --- a/src/service/FolderService.js +++ b/src/service/FolderService.js @@ -1,12 +1,12 @@ -import { generateUrl } from 'nextcloud-server/dist/router' +import {generateUrl} from 'nextcloud-server/dist/router' import HttpClient from 'nextcloud-axios' export function fetchAll(accountId) { - const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders', { - accountId - }) + const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders', { + accountId, + }) - // FIXME: this return format is weird and should be avoided - // TODO: respect `resp.data.delimiter` value - return HttpClient.get(url).then(resp => resp.data.folders) + // FIXME: this return format is weird and should be avoided + // TODO: respect `resp.data.delimiter` value + return HttpClient.get(url).then(resp => resp.data.folders) } diff --git a/src/service/MessageService.js b/src/service/MessageService.js index 71ed27b68..834fde6eb 100644 --- a/src/service/MessageService.js +++ b/src/service/MessageService.js @@ -1,94 +1,96 @@ -import { generateUrl } from 'nextcloud-server/dist/router' +import {generateUrl} from 'nextcloud-server/dist/router' import HttpClient from 'nextcloud-axios' import {parseErrorResponse} from '../http/ErrorResponseParser' export function fetchEnvelopes(accountId, folderId, query, cursor) { - const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders/{folderId}/messages', { - accountId, - folderId, - }) - const params = {} - - if (query) { - params.filter = query - } - if (cursor) { - params.cursor = cursor - } - - return HttpClient.get(url, { - params: params - }).then(resp => resp.data) + const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders/{folderId}/messages', { + accountId, + folderId, + }) + const params = {} + + if (query) { + params.filter = query + } + if (cursor) { + params.cursor = cursor + } + + return HttpClient.get(url, { + params: params, + }).then(resp => resp.data) } export function syncEnvelopes(accountId, folderId, syncToken, uids) { - const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders/{folderId}/sync', { - accountId, - folderId, - }) - - return HttpClient.get(url, { - params: { - syncToken, - uids, - } - }).then(resp => resp.data) + const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders/{folderId}/sync', { + accountId, + folderId, + }) + + return HttpClient.get(url, { + params: { + syncToken, + uids, + }, + }).then(resp => resp.data) } export function setEnvelopeFlag(accountId, folderId, id, flag, value) { - const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders/{folderId}/messages/{id}/flags', { - accountId, - folderId, - id - }) - - const flags = {} - flags[flag] = value - - return HttpClient.put(url, { - flags: flags - }).then(() => { flag: value }) + const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders/{folderId}/messages/{id}/flags', { + accountId, + folderId, + id, + }) + + const flags = {} + flags[flag] = value + + return HttpClient.put(url, { + flags: flags, + }).then(() => { + value + }) } export function fetchMessage(accountId, folderId, id) { - const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders/{folderId}/messages/{id}', { - accountId, - folderId, - id - }) - - return HttpClient.get(url) - .then(resp => resp.data) - .catch(err => { - if (err.response.status === 404) { - return undefined - } - return Promise.reject(parseErrorResponse(err.response)) - }) + const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders/{folderId}/messages/{id}', { + accountId, + folderId, + id, + }) + + return HttpClient.get(url) + .then(resp => resp.data) + .catch(err => { + if (err.response.status === 404) { + return undefined + } + return Promise.reject(parseErrorResponse(err.response)) + }) } export function saveDraft(accountId, data) { - const url = generateUrl('/apps/mail/api/accounts/{accountId}/draft', { - accountId, - }) + const url = generateUrl('/apps/mail/api/accounts/{accountId}/draft', { + accountId, + }) - return HttpClient.post(url, data).then(resp => resp.data) + return HttpClient.post(url, data).then(resp => resp.data) } export function sendMessage(accountId, data) { - const url = generateUrl('/apps/mail/api/accounts/{accountId}/send', { - accountId, - }) + const url = generateUrl('/apps/mail/api/accounts/{accountId}/send', { + accountId, + }) - return HttpClient.post(url, data).then(resp => resp.data) + return HttpClient.post(url, data).then(resp => resp.data) } export function deleteMessage(accountId, folderId, id) { const url = generateUrl('/apps/mail/api/accounts/{accountId}/folders/{folderId}/messages/{id}', { accountId, folderId, - id + id, }) return HttpClient.delete(url).then(resp => resp.data) diff --git a/src/service/NotificationService.js b/src/service/NotificationService.js index 6d874f163..0ddf9cf58 100644 --- a/src/service/NotificationService.js +++ b/src/service/NotificationService.js @@ -29,7 +29,7 @@ import {generateFilePath} from 'nextcloud-server/dist/router' * @return {Promise} */ const request = () => { - if (!("Notification" in window)) { + if (!('Notification' in window)) { console.info('browser does not support desktop notifications') return Promise.reject() } else if (Notification.permission === 'granted') { @@ -44,30 +44,24 @@ const request = () => { } const showNotification = (title, body, icon) => { - request() - .then(() => { - if (document.querySelector(':focus') !== null) { - console.debug('browser is active. notification request is ignored') - return - } - }) - - const notification = new Notification( - title, - { - body: body, - icon: icon + request().then(() => { + if (document.querySelector(':focus') !== null) { + console.debug('browser is active. notification request is ignored') + return } - ) + }) + + const notification = new Notification(title, { + body: body, + icon: icon, + }) notification.onclick = () => { window.focus() } } -const getNotificationBody = (messages) => { - const labels = messages - .filter(m => m.from.length > 0) - .map(m => m.from[0].label) +const getNotificationBody = messages => { + const labels = messages.filter(m => m.from.length > 0).map(m => m.from[0].label) let from = _.uniq(labels) if (from.length > 2) { from = from.slice(0, 2) @@ -78,16 +72,16 @@ const getNotificationBody = (messages) => { if (messages.length === 1) { return t('mail', '{from}\n{subject}', { from: from.join(), - subject: messages[0].subject + subject: messages[0].subject, }) } else { return n('mail', '%n new message \nfrom {from}', '%n new messages \nfrom {from}', messages.length, { - from: from.join() + from: from.join(), }) } } -export const showNewMessagesNotification = (messages) => { +export const showNewMessagesNotification = messages => { showNotification( t('mail', 'Nextcloud Mail'), getNotificationBody(messages), diff --git a/src/service/PreferenceService.js b/src/service/PreferenceService.js index 66a35f437..108e5a7da 100644 --- a/src/service/PreferenceService.js +++ b/src/service/PreferenceService.js @@ -25,22 +25,20 @@ import {generateUrl} from 'nextcloud-server/dist/router' export const savePreference = (key, value) => { const url = generateUrl('/apps/mail/api/preferences/{key}', { - key + key, }) const data = { key, value, } - return Axios.put(url, data) - .then(resp => resp.data) + return Axios.put(url, data).then(resp => resp.data) } export const getPreference = key => { const url = generateUrl('/apps/mail/api/preferences/{key}', { - key + key, }) - return Axios.get(url) - .then(resp => resp.data) + return Axios.get(url).then(resp => resp.data) } diff --git a/src/service/aliasesservice.js b/src/service/aliasesservice.js index f6376ff60..075e633ac 100644 --- a/src/service/aliasesservice.js +++ b/src/service/aliasesservice.js @@ -20,14 +20,14 @@ */ define(function(require) { - 'use strict'; + 'use strict' - var $ = require('jquery'); - var OC = require('OC'); - var Radio = require('radio'); + var $ = require('jquery') + var OC = require('OC') + var Radio = require('radio') - Radio.aliases.reply('save', saveAlias); - Radio.aliases.reply('delete', deleteAlias); + Radio.aliases.reply('save', saveAlias) + Radio.aliases.reply('delete', deleteAlias) /** * @param {Account} account @@ -36,17 +36,17 @@ define(function(require) { */ function saveAlias(account, alias) { var url = OC.generateUrl('/apps/mail/api/accounts/{id}/aliases', { - id: account.get('accountId') - }); + id: account.get('accountId'), + }) var data = { type: 'POST', data: { accountId: account.get('accountId'), alias: alias.alias, - aliasName: alias.name - } - }; - return Promise.resolve($.ajax(url, data)); + aliasName: alias.name, + }, + } + return Promise.resolve($.ajax(url, data)) } /** @@ -57,12 +57,11 @@ define(function(require) { function deleteAlias(account, aliasId) { var url = OC.generateUrl('/apps/mail/api/accounts/{id}/aliases/{aliasId}', { id: account.get('accountId'), - aliasId: aliasId - }); + aliasId: aliasId, + }) var data = { - type: 'DELETE' - }; - return Promise.resolve($.ajax(url, data)); + type: 'DELETE', + } + return Promise.resolve($.ajax(url, data)) } - -});
\ No newline at end of file +}) |