aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/src/services/ShareSearch.js
blob: eff209aad2b77b453839a7d8abba07986620b1b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
 * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

export default class ShareSearch {

	_state

	constructor() {
		// init empty state
		this._state = {}

		// init default values
		this._state.results = []
		console.debug('OCA.Sharing.ShareSearch initialized')
	}

	/**
	 * Get the state
	 *
	 * @readonly
	 * @memberof ShareSearch
	 * @return {object} the data state
	 */
	get state() {
		return this._state
	}

	/**
	 * Register a new result
	 * Mostly used by the guests app.
	 * We should consider deprecation and add results via php ?
	 *
	 * @param {object} result entry to append
	 * @param {string} [result.user] entry user
	 * @param {string} result.displayName entry first line
	 * @param {string} [result.desc] entry second line
	 * @param {string} [result.icon] entry icon
	 * @param {Function} result.handler function to run on entry selection
	 * @param {Function} [result.condition] condition to add entry or not
	 * @return {boolean}
	 */
	addNewResult(result) {
		if (result.displayName.trim() !== ''
			&& typeof result.handler === 'function') {
			this._state.results.push(result)
			return true
		}
		console.error('Invalid search result provided', result)
		return false
	}

}