Skip to content

Commit a8e66ff

Browse files
committed
commit to be deleted
1 parent 1ad6de2 commit a8e66ff

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

src/modals/add-contact.js

-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ const AddContactModal = BootstrapModal.extend({
2323
},
2424

2525
afterRender () {
26-
if (typeof api.settings.get('xhr_user_search_url') === 'string') {
27-
this.initXHRAutoComplete();
28-
} else {
29-
this.initJIDAutoComplete();
30-
}
3126
const jid_input = this.el.querySelector('input[name="jid"]');
3227
this.el.addEventListener('shown.bs.modal', () => jid_input.focus(), false);
3328
},

src/modals/templates/add-contact.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { __ } from 'i18n';
22
import { api } from '@converse/headless/core.js';
33
import { html } from "lit";
44
import { modal_header_close_button } from "plugins/modal/templates/buttons.js"
5+
import { getServerList } from "../../plugins/rosterview/utils"
56

67

78
export default (el) => {
@@ -26,9 +27,7 @@ export default (el) => {
2627
<label class="clearfix" for="jid">${i18n_xmpp_address}:</label>
2728
<div class="suggestion-box suggestion-box__jid">
2829
<ul class="suggestion-box__results suggestion-box__results--below" hidden=""></ul>
29-
<input type="text" name="jid" ?required=${(!api.settings.get('xhr_user_search_url'))}
30-
value="${el.model.get('jid') || ''}"
31-
class="form-control suggestion-box__input"
30+
<converse-autocomplete name="jid" .getAutoCompleteList="${getServerList}"
3231
placeholder="${i18n_contact_placeholder}"/>
3332
<span class="suggestion-box__additions visually-hidden" role="status" aria-live="assertive" aria-relevant="additions"></span>
3433
</div>
@@ -46,7 +45,7 @@ export default (el) => {
4645
4746
<div class="form-group add-xmpp-contact__group">
4847
<label class="clearfix" for="name">${i18n_group}:</label>
49-
<converse-autocomplete .getAutoCompleteList="${() => el.getGroupsAutoCompleteList()}" name="group"/>
48+
<!--<converse-autocomplete .getAutoCompleteList="${() => el.getGroupsAutoCompleteList()}" name="group"/>-->
5049
</div>
5150
5251
<div class="form-group"><div class="invalid-feedback">${i18n_error_message}</div></div>

src/plugins/rosterview/utils.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { _converse, api } from "@converse/headless/core";
1+
import { _converse, api, converse } from "@converse/headless/core";
22

33

44
export function highlightRosterItem (chatbox) {
@@ -98,3 +98,29 @@ export function populateContactsMap (contacts_map, contact) {
9898
}
9999
return contacts_map;
100100
}
101+
102+
let final_list = [];
103+
let timestamp = null;
104+
105+
async function getServerList() {
106+
const responseA = await fetch('https://data.xmpp.net/providers/v1/providers-A.json');
107+
const dataA = await responseA.json();
108+
const popular_mucsA = dataA.items.map(item => item.jid);
109+
const responseB = await fetch('https://data.xmpp.net/providers/v1/providers-B.json');
110+
const dataB = await responseB.json();
111+
const popular_mucsB = dataB.items.map(item => item.jid);
112+
const responseC = await fetch('https://data.xmpp.net/providers/v1/providers-C.json');
113+
const dataC = await responseC.json();
114+
const popular_mucsC = dataC.items.map(item => item.jid);
115+
const response = [...popular_mucsA, ...popular_mucsB, ...popular_mucsC];
116+
console.log(response)
117+
final_list = [...new Set(response)];
118+
}
119+
120+
export async function getXMPPList() {
121+
if (!timestamp || converse.env.dayjs().isAfter(timestamp, 'day')) {
122+
await getServerList();
123+
timestamp = (new Date()).toISOString();
124+
}
125+
return final_list;
126+
}

src/shared/autocomplete/component.js

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default class AutoCompleteComponent extends CustomElement {
99
return {
1010
'getAutoCompleteList': { type: Function },
1111
'auto_evaluate': { type: Boolean },
12+
'dataMap': { type: Function },
1213
'auto_first': { type: Boolean }, // Should the first element be automatically selected?
1314
'filter': { type: String },
1415
'include_triggers': { type: String },
@@ -24,6 +25,7 @@ export default class AutoCompleteComponent extends CustomElement {
2425
this.auto_evaluate = true; // Should evaluation happen automatically without any particular key as trigger?
2526
this.auto_first = false; // Should the first element be automatically selected?
2627
this.filter = 'contains';
28+
this.dataMap = a => a; // Function that maps user provided input to a suggestion value
2729
this.include_triggers = ''; // Space separated chars which should be included in the returned value
2830
this.match_current_word = false; // Match only the current word, otherwise all input is matched
2931
this.max_items = 10;
@@ -62,6 +64,7 @@ export default class AutoCompleteComponent extends CustomElement {
6264
'filter': this.filter == 'contains' ? FILTER_CONTAINS : FILTER_STARTSWITH,
6365
'include_triggers': [],
6466
'list': () => this.getAutoCompleteList(),
67+
'data': (a) => this.dataMap(a),
6568
'match_current_word': true,
6669
'max_items': this.max_items,
6770
'min_chars': this.min_chars

0 commit comments

Comments
 (0)