Skip to content

Commit

Permalink
ES6: migrated "search" (#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Herdmann authored Apr 18, 2017
1 parent 8d42b37 commit 2ac8e1a
Show file tree
Hide file tree
Showing 14 changed files with 341 additions and 285 deletions.
1 change: 0 additions & 1 deletion app/script/event/WebApp.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ z.event.WebApp =
UPDATED: 'wire.webapp.properties.updated'
SEARCH:
HIDE: 'wire.webapp.search.hide'
ONBOARDING: 'wire.webapp.search.onboarding'
SHOW: 'wire.webapp.people-picker.show'
BADGE:
HIDE: 'wire.webapp.search.badge.hide'
Expand Down
2 changes: 1 addition & 1 deletion app/script/media/MediaError.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ z.media.MediaError = class MediaError extends Error {
this.name = this.constructor.name;
this.media_type = media_type;
this.stack = (new Error()).stack;
this.type = type || z.media.MediaError.prototype.TYPE.UNKNOWN;
this.type = type || z.media.MediaError.TYPE.UNKNOWN;

switch (this.type) {
case z.media.MediaError.TYPE.MEDIA_STREAM_DEVICE:
Expand Down
10 changes: 5 additions & 5 deletions app/script/media/MediaStreamHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,10 @@ z.media.MediaStreamHandler = class MediaStreamHandler {
*/
request_media_stream(media_type, media_stream_constraints) {
if (!this.media_repository.devices_handler.has_microphone()) {
return Promise.reject(new z.media.MediaError(z.media.MediaError.prototype.TYPE.MEDIA_STREAM_DEVICE, z.media.MediaType.VIDEO));
return Promise.reject(new z.media.MediaError(z.media.MediaError.TYPE.MEDIA_STREAM_DEVICE, z.media.MediaType.VIDEO));
}
if (!this.media_repository.devices_handler.has_camera() && (media_type === z.media.MediaType.VIDEO)) {
return Promise.reject(new z.media.MediaError(z.media.MediaError.prototype.TYPE.MEDIA_STREAM_DEVICE, z.media.MediaType.VIDEO));
return Promise.reject(new z.media.MediaError(z.media.MediaError.TYPE.MEDIA_STREAM_DEVICE, z.media.MediaType.VIDEO));
}

this.logger.info(`Requesting MediaStream access for '${media_type}'`, media_stream_constraints);
Expand All @@ -352,13 +352,13 @@ z.media.MediaStreamHandler = class MediaStreamHandler {
this.logger.warn(`MediaStream request failed: ${error.name} ${error.message}`);
this._clear_permission_request_hint(media_type);
if (z.calling.rtc.MediaStreamErrorTypes.DEVICE.includes(error.name)) {
throw new z.media.MediaError(z.media.MediaError.prototype.TYPE.MEDIA_STREAM_DEVICE, media_type);
throw new z.media.MediaError(z.media.MediaError.TYPE.MEDIA_STREAM_DEVICE, media_type);
}
if (z.calling.rtc.MediaStreamErrorTypes.MISC.includes(error.name)) {
throw new z.media.MediaError(z.media.MediaError.prototype.TYPE.MEDIA_STREAM_MISC, media_type);
throw new z.media.MediaError(z.media.MediaError.TYPE.MEDIA_STREAM_MISC, media_type);
}
if (z.calling.rtc.MediaStreamErrorTypes.PERMISSION.includes(error.name)) {
throw new z.media.MediaError(z.media.MediaError.prototype.TYPE.MEDIA_STREAM_PERMISSION, media_type);
throw new z.media.MediaError(z.media.MediaError.TYPE.MEDIA_STREAM_PERMISSION, media_type);
}
throw error;
});
Expand Down
43 changes: 0 additions & 43 deletions app/script/search/FullTextSearch.coffee

This file was deleted.

52 changes: 52 additions & 0 deletions app/script/search/FullTextSearch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Wire
* Copyright (C) 2017 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

'use strict';

window.z = window.z || {};
window.z.search = z.search || {};

z.search.FullTextSearch = (function() {

const _get_search_regex = function(query) {
const delimiter = ' ';
const flags = 'gumi';
const regex = query
.trim()
.split(delimiter)
.map((word) => `(${z.util.escape_regex(word)})`)
.join('(?:.*)');

return new RegExp(regex, flags);
};

const _search = function(text, query = '') {
query = query.trim();

if (query.length > 0) {
return _get_search_regex(query).test(text);
}
return false;
};

return {
get_search_regex: _get_search_regex,
search: _search,
};
})();
25 changes: 0 additions & 25 deletions app/script/search/SearchMode.coffee

This file was deleted.

29 changes: 29 additions & 0 deletions app/script/search/SearchMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Wire
* Copyright (C) 2017 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

'use strict';

window.z = window.z || {};
window.z.search = z.search || {};

// Enum of different search modes.
z.search.SEARCH_MODE = {
CONTACTS: 'contacts',
ON_BOARDING: 'onboarding',
};
119 changes: 0 additions & 119 deletions app/script/search/SearchRepository.coffee

This file was deleted.

Loading

0 comments on commit 2ac8e1a

Please sign in to comment.