Skip to content

Commit be2f4de

Browse files
committed
commit to be deleted
1 parent 87aba69 commit be2f4de

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

src/modals/templates/add-contact.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { __ } from 'i18n';
2+
import { api } from '@converse/headless/core.js';
3+
import { html } from "lit";
4+
import { modal_header_close_button } from "plugins/modal/templates/buttons.js"
5+
import { getServerList } from "../../plugins/rosterview/utils"
6+
7+
8+
export default (el) => {
9+
const i18n_add = __('Add');
10+
const i18n_contact_placeholder = __('[email protected]');
11+
const i18n_error_message = __('Please enter a valid XMPP address');
12+
const i18n_group = __('Group');
13+
const i18n_new_contact = __('Add a Contact');
14+
const i18n_nickname = __('Name');
15+
const i18n_xmpp_address = __('XMPP Address');
16+
return html`
17+
<div class="modal-dialog" role="document">
18+
<div class="modal-content">
19+
<div class="modal-header">
20+
<h5 class="modal-title" id="addContactModalLabel">${i18n_new_contact}</h5>
21+
${modal_header_close_button}
22+
</div>
23+
<form class="converse-form add-xmpp-contact" @submit=${ev => el.addContactFromForm(ev)}>
24+
<div class="modal-body">
25+
<span class="modal-alert"></span>
26+
<div class="form-group add-xmpp-contact__jid">
27+
<label class="clearfix" for="jid">${i18n_xmpp_address}:</label>
28+
<div class="suggestion-box suggestion-box__jid">
29+
<ul class="suggestion-box__results suggestion-box__results--below" hidden=""></ul>
30+
<converse-autocomplete name="jid" .getAutoCompleteList="${getServerList}"
31+
placeholder="${i18n_contact_placeholder}"/>
32+
<span class="suggestion-box__additions visually-hidden" role="status" aria-live="assertive" aria-relevant="additions"></span>
33+
</div>
34+
</div>
35+
36+
<div class="form-group add-xmpp-contact__name">
37+
<label class="clearfix" for="name">${i18n_nickname}:</label>
38+
<div class="suggestion-box suggestion-box__name">
39+
<ul class="suggestion-box__results suggestion-box__results--above" hidden=""></ul>
40+
<input type="text" name="name" value="${el.model.get('nickname') || ''}"
41+
class="form-control suggestion-box__input"/>
42+
<span class="suggestion-box__additions visually-hidden" role="status" aria-live="assertive" aria-relevant="additions"></span>
43+
</div>
44+
</div>
45+
46+
<div class="form-group add-xmpp-contact__group">
47+
<label class="clearfix" for="name">${i18n_group}:</label>
48+
<!--<converse-autocomplete .getAutoCompleteList="${() => el.getGroupsAutoCompleteList()}" name="group"/>-->
49+
</div>
50+
51+
<div class="form-group"><div class="invalid-feedback">${i18n_error_message}</div></div>
52+
<button type="submit" class="btn btn-primary">${i18n_add}</button>
53+
</div>
54+
</form>
55+
</div>
56+
</div>
57+
`;
58+
}

src/plugins/rosterview/modals/add-contact.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,23 @@ export default class AddContactModal extends BaseModal {
2727
}
2828

2929
afterRender () {
30+
<<<<<<< HEAD:src/plugins/rosterview/modals/add-contact.js
3031
if (typeof api.settings.get('xhr_user_search_url') === 'string') {
3132
this.initXHRAutoComplete();
3233
} else {
3334
this.initJIDAutoComplete();
3435
}
3536
}
37+
=======
38+
const jid_input = this.el.querySelector('input[name="jid"]');
39+
this.el.addEventListener('shown.bs.modal', () => jid_input.focus(), false);
40+
},
41+
42+
getGroupsAutoCompleteList () {
43+
return ['apple', 'pear', 'banana'];
44+
// return [...new Set(_converse.roster.map(i => i.get('gruop')).filter(i => i))];
45+
},
46+
>>>>>>> a8e66ff20 (commit to be deleted):src/modals/add-contact.js
3647

3748
initJIDAutoComplete () {
3849
if (!api.settings.get('autocomplete_add_contact')) {

src/plugins/rosterview/utils.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
<<<<<<< HEAD
12
import log from "@converse/headless/log";
23
import { __ } from 'i18n';
34
import { _converse, api } from "@converse/headless/core";
5+
=======
6+
import { _converse, api, converse } from "@converse/headless/core";
7+
>>>>>>> a8e66ff20 (commit to be deleted)
48

59
export function removeContact (contact) {
610
contact.removeFromRoster(
@@ -112,3 +116,29 @@ export function populateContactsMap (contacts_map, contact) {
112116
}
113117
return contacts_map;
114118
}
119+
120+
let final_list = [];
121+
let timestamp = null;
122+
123+
async function getServerList() {
124+
const responseA = await fetch('https://data.xmpp.net/providers/v1/providers-A.json');
125+
const dataA = await responseA.json();
126+
const popular_mucsA = dataA.items.map(item => item.jid);
127+
const responseB = await fetch('https://data.xmpp.net/providers/v1/providers-B.json');
128+
const dataB = await responseB.json();
129+
const popular_mucsB = dataB.items.map(item => item.jid);
130+
const responseC = await fetch('https://data.xmpp.net/providers/v1/providers-C.json');
131+
const dataC = await responseC.json();
132+
const popular_mucsC = dataC.items.map(item => item.jid);
133+
const response = [...popular_mucsA, ...popular_mucsB, ...popular_mucsC];
134+
console.log(response)
135+
final_list = [...new Set(response)];
136+
}
137+
138+
export async function getXMPPList() {
139+
if (!timestamp || converse.env.dayjs().isAfter(timestamp, 'day')) {
140+
await getServerList();
141+
timestamp = (new Date()).toISOString();
142+
}
143+
return final_list;
144+
}

src/shared/autocomplete/component.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ export default class AutoCompleteComponent extends CustomElement {
4848
'getAutoCompleteList': { type: Function },
4949
'list': { type: Array },
5050
'auto_evaluate': { type: Boolean },
51+
<<<<<<< HEAD
5152
'auto_first': { type: Boolean },
53+
=======
54+
'dataMap': { type: Function },
55+
'auto_first': { type: Boolean }, // Should the first element be automatically selected?
56+
>>>>>>> a8e66ff20 (commit to be deleted)
5257
'filter': { type: String },
5358
'include_triggers': { type: String },
5459
'min_chars': { type: Number },
@@ -65,7 +70,12 @@ export default class AutoCompleteComponent extends CustomElement {
6570
this.auto_evaluate = true;
6671
this.auto_first = false;
6772
this.filter = 'contains';
73+
<<<<<<< HEAD
6874
this.include_triggers = '';
75+
=======
76+
this.dataMap = a => a; // Function that maps user provided input to a suggestion value
77+
this.include_triggers = ''; // Space separated chars which should be included in the returned value
78+
>>>>>>> a8e66ff20 (commit to be deleted)
6979
this.match_current_word = false; // Match only the current word, otherwise all input is matched
7080
this.max_items = 10;
7181
this.min_chars = 1;
@@ -105,7 +115,12 @@ export default class AutoCompleteComponent extends CustomElement {
105115
'auto_first': this.auto_first,
106116
'filter': this.filter == 'contains' ? FILTER_CONTAINS : FILTER_STARTSWITH,
107117
'include_triggers': [],
118+
<<<<<<< HEAD
108119
'list': this.list ?? ((q) => this.getAutoCompleteList(q)),
120+
=======
121+
'list': () => this.getAutoCompleteList(),
122+
'data': (a) => this.dataMap(a),
123+
>>>>>>> a8e66ff20 (commit to be deleted)
109124
'match_current_word': true,
110125
'max_items': this.max_items,
111126
'min_chars': this.min_chars,

0 commit comments

Comments
 (0)