1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-18 09:22:18 +03:00

room, user, ddg autocomplete providers (wip)

This commit is contained in:
Aviral Dasgupta
2016-06-12 17:02:46 +05:30
parent 0df201c483
commit 4bc8ec3e6d
9 changed files with 163 additions and 19 deletions

View File

@ -0,0 +1,35 @@
import AutocompleteProvider from './AutocompleteProvider';
import Q from 'q';
import 'whatwg-fetch';
const DDG_REGEX = /\/ddg\w+(.+)$/;
const REFERER = 'vector';
export default class DuckDuckGoProvider extends AutocompleteProvider {
static getQueryUri(query: String) {
return `http://api.duckduckgo.com/?q=${encodeURIComponent(query)}&format=json&t=${encodeURIComponent(REFERER)}`;
}
getCompletions(query: String) {
if(!query)
return Q.when([]);
let promise = Q.defer();
fetch(DuckDuckGoProvider.getQueryUri(query), {
method: 'GET'
}).then(response => {
let results = response.Results.map(result => {
return {
title: result.Text,
description: result.Result
};
});
promise.resolve(results);
});
return promise;
}
getName() {
return 'Results from DuckDuckGo';
}
}