Skip to content

Commit 8a832a5

Browse files
committed
Allow the user to choose one of multiple pubsub services
- Use bootstrap's collapse feature to show/hide entity features
1 parent 148de37 commit 8a832a5

File tree

15 files changed

+109
-51
lines changed

15 files changed

+109
-51
lines changed

src/headless/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import './plugins/bosh/index.js'; // XEP-0206 BOSH
3030
import './plugins/caps/index.js'; // XEP-0115 Entity Capabilities
3131
export { ChatBox, Message, Messages } from './plugins/chat/index.js'; // RFC-6121 Instant messaging
3232
import './plugins/chatboxes/index.js';
33-
import './plugins/disco/index.js'; // XEP-0030 Service discovery
33+
export { DiscoEntity, DiscoEntities } from './plugins/disco/index.js'; // XEP-0030 Service discovery
3434
import './plugins/adhoc/index.js'; // XEP-0050 Ad Hoc Commands
3535
import './plugins/headlines/index.js'; // Support for headline messages
3636
export { Device, Devices, DeviceList, DeviceLists } from './plugins/omemo/index.js'; // Support for headline messages

src/headless/plugins/disco/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {
1919

2020
const { Strophe } = converse.env;
2121

22+
export { DiscoEntity, DiscoEntities };
23+
2224
/**
2325
* @typedef {Object} DiscoState
2426
* @property {Array} _identities

src/headless/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export { Collection, EventEmitter, Model } from "@converse/skeletor";
2121
export { Builder, Stanza } from "strophe.js";
2222
export { Bookmark, Bookmarks } from "./plugins/bookmarks/index.js";
2323
export { ChatBox, Message, Messages } from "./plugins/chat/index.js";
24+
export { DiscoEntity, DiscoEntities } from "./plugins/disco/index.js";
2425
export { Device, Devices, DeviceList, DeviceLists } from "./plugins/omemo/index.js";
2526
export { MUCMessage, MUCMessages, MUC, MUCOccupant, MUCOccupants } from "./plugins/muc/index.js";
2627
export { RosterContact, RosterContacts, RosterFilter, Presence, Presences } from "./plugins/roster/index.js";

src/headless/types/plugins/disco/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ export type DiscoState = {
22
_identities: any[];
33
_features: any[];
44
};
5+
import DiscoEntity from './entity.js';
6+
import DiscoEntities from './entities.js';
7+
export { DiscoEntity, DiscoEntities };
58
//# sourceMappingURL=index.d.ts.map

src/headless/types/plugins/pubsub/api.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ declare namespace _default {
3434
* @returns {Promise<void|Element>}
3535
*/
3636
function publish(jid: string, node: string, item: import("strophe.js").Builder | import("strophe.js").Stanza | (import("strophe.js").Builder | import("strophe.js").Stanza)[], options: import("./types").PubSubConfigOptions, strict_options?: boolean): Promise<void | Element>;
37+
/**
38+
* Creates a PubSub node at a given service
39+
* @param {string} jid - The PubSub service JID
40+
* @param {string} node - The node to create
41+
* @param {PubSubConfigOptions} [config] The configuration options
42+
* @returns {Promise<void>}
43+
*/
44+
function create(jid: string, node: string, config?: import("./types").PubSubConfigOptions): Promise<void>;
3745
/**
3846
* Subscribes the local user to a PubSub node.
3947
*

src/headless/types/shared/_converse.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class ConversePrivateGlobal extends ConversePrivateGlobal_base {
7979
*/
8080
state: any;
8181
initSession(): void;
82-
session: Model;
82+
session: any;
8383
/**
8484
* Translate the given string based on the current locale.
8585
* @method __

src/headless/types/shared/connection/index.d.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ declare const Connection_base: typeof import("strophe.js/src/types/connection").
55
* via BOSH or websocket inside a shared worker).
66
*/
77
export class Connection extends Connection_base {
8-
constructor(service: any, options: any);
8+
/**
9+
* @param {string} service - The BOSH or WebSocket service URL.
10+
* @param {import('strophe.js/src/types/connection').ConnectionOptions} options
11+
*/
12+
constructor(service: string, options: import("strophe.js/src/types/connection").ConnectionOptions);
913
send_initial_presence: boolean;
1014
debouncedReconnect: import("lodash").DebouncedFunc<() => Promise<any>>;
1115
/** @param {Element} body */
@@ -111,11 +115,6 @@ export class Connection extends Connection_base {
111115
* The MockConnection class is used during testing, to mock an XMPP connection.
112116
*/
113117
export class MockConnection extends Connection {
114-
/**
115-
* @param {string} service - The BOSH or WebSocket service URL.
116-
* @param {import('strophe.js/src/types/connection').ConnectionOptions} options - The configuration options
117-
*/
118-
constructor(service: string, options: import("strophe.js/src/types/connection").ConnectionOptions);
119118
sent_stanzas: any[];
120119
IQ_stanzas: any[];
121120
IQ_ids: any[];

src/plugins/roomslist/styles/roomsgroups.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
.conversejs {
2-
32
#chatrooms {
3+
.collapsed {
4+
height: 0 !important;
5+
overflow: hidden !important;
6+
padding: 0 !important;
7+
}
8+
49
.muc-domain-group-toggle {
510
margin: 0.75em 0 0.25em 0;
611
}

src/plugins/rosterview/styles/roster.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
.conversejs {
2-
32
#controlbox {
3+
.collapsed {
4+
height: 0 !important;
5+
overflow: hidden !important;
6+
padding: 0 !important;
7+
}
8+
49
.open-contacts-toggle, .open-contacts-toggle .fa {
510
color: var(--chat-color) !important;
611
&:hover {

src/plugins/todo/modals/add-todo-modal.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
import { _converse, api, converse, parsers } from '@converse/headless';
1+
import { default as Collapse } from 'bootstrap/js/src/collapse.js';
2+
import { _converse, api, converse, parsers, u } from '@converse/headless';
23
import BaseModal from 'plugins/modal/modal.js';
3-
import tplAddTodo from './templates/add-todo-modal.js';
44
import { __ } from 'i18n';
5+
import tplAddTodo from './templates/add-todo-modal.js';
56

67
const { Strophe } = converse.env;
78

89
export default class AddTodoModal extends BaseModal {
10+
static get properties() {
11+
return {
12+
...super.properties,
13+
_manual_jid: { state: true, type: Boolean },
14+
_entities: { state: true, type: Array },
15+
};
16+
}
17+
918
initialize() {
1019
super.initialize();
1120
this.requestUpdate();
@@ -18,6 +27,14 @@ export default class AddTodoModal extends BaseModal {
1827
);
1928
}
2029

30+
/**
31+
* @param {import('lit').PropertyValues} changed
32+
*/
33+
firstUpdated(changed) {
34+
super.firstUpdated(changed);
35+
this.collapse = new Collapse(/** @type {HTMLElement} */ (this));
36+
}
37+
2138
renderModal() {
2239
return tplAddTodo(this);
2340
}
@@ -36,19 +53,21 @@ export default class AddTodoModal extends BaseModal {
3653
const name = data.get('name');
3754
const jid = data.get('jid') ?? _converse.state.session.get('domain');
3855

39-
const service_jids = await api.disco.entities.find(Strophe.NS.PUBSUB, jid);
40-
if (service_jids.length === 0) {
56+
const entities = await api.disco.entities.find(Strophe.NS.PUBSUB, jid);
57+
if (entities.length === 0) {
4158
this.alert(__('Could not find a PubSub service to host your todo list'), 'danger');
42-
this.state.set({ manual_jid: true });
59+
this._manual_jid = true;
4360
return;
44-
} else if (service_jids.length > 1) {
61+
} else if (entities.length > 1) {
4562
this.alert(__('Found multiple possible PubSub services to host your todo list, please choose one.'));
46-
this.state.set({ services: service_jids, manual_jid: true });
63+
64+
this._entities = entities;
65+
this._manual_jid = true;
4766
return;
4867
}
4968

5069
try {
51-
await api.pubsub.create(service_jids[0].get('jid'), name);
70+
await api.pubsub.create(entities[0].get('jid'), u.getUniqueId(), { title: name });
5271
} catch (e) {
5372
const err = await parsers.parseErrorStanza(e);
5473
this.alert(__('Sorry, an error occurred: %s', err.message), 'danger');

0 commit comments

Comments
 (0)