Skip to content

Commit 34dd28f

Browse files
committed
added a toggling button in the centre of the chat-header
1 parent 82aa37a commit 34dd28f

File tree

7 files changed

+46
-17
lines changed

7 files changed

+46
-17
lines changed

src/plugins/chatview/styles/chat-head.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
flex-wrap: nowrap;
6565
padding: 0;
6666
}
67+
68+
.chatbox-call-status {
69+
width: 80%;
70+
}
6771

6872
a, a:visited, a:hover, a:not([href]):not([tabindex]) {
6973
&.chatbox-btn {

src/plugins/chatview/templates/chat-head.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ export default (o) => {
4141
<div class="chatbox-title__text" title="${o.jid}">
4242
${ (o.type !== _converse.HEADLINES_TYPE) ? html`<a class="user show-msg-author-modal" @click=${o.showUserDetailsModal}>${ display_name }</a>` : display_name }
4343
</div>
44-
</div>
45-
<div>
46-
<converse-chat-header-call-notification></converse-chat-header-call-notification>
44+
<converse-call-notification class="d-flex flex-row-reverse justify-content-center chatbox-call-status" jid=${o.model.get('jid')}></converse-call-notification>
4745
</div>
4846
<div class="chatbox-title__buttons row no-gutters">
4947
${ until(tpl_dropdown_btns(), '') }
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
import { CustomElement } from 'shared/components/element.js';
22
import { _converse, api } from "@converse/headless/core";
3-
import { JINGLE_CALL_STATUS } from "./constants.js";
43
import tpl_header_button from "./templates/header-button.js";
4+
import { JINGLE_CALL_STATUS } from "./constants.js";
55

6-
export default class ChatHeaderCallNotification extends CustomElement {
6+
export default class CallNotification extends CustomElement {
77

8+
static get properties() {
9+
return {
10+
'jid': { type: String },
11+
}
12+
}
13+
814
initialize() {
915
this.model = _converse.chatboxes.get(this.jid);
10-
this.listenTo(this.model, 'change:jingle_status', this.requestUpdate);
16+
this.listenTo(this.model, 'change:jingle_status', () => this.requestUpdate());
1117
}
1218

1319
render() {
1420
return tpl_header_button(this);
1521
}
1622

17-
toggleJingleCallStatus() {
23+
endCall() {
1824
const jingle_status = this.model.get('jingle_status');
1925
if ( jingle_status === JINGLE_CALL_STATUS.PENDING || jingle_status === JINGLE_CALL_STATUS.ACTIVE) {
2026
this.model.save('jingle_status', JINGLE_CALL_STATUS.ENDED);
2127
return;
2228
}
23-
if (!jingle_status || jingle_status === JINGLE_CALL_STATUS.ENDED) {
24-
this.model.save('jingle_status', JINGLE_CALL_STATUS.PENDING);
25-
return;
26-
}
2729
}
2830
}
2931

30-
api.elements.define('converse-chat-header-call-notification', ChatHeaderCallNotification);
32+
api.elements.define('converse-call-notification', CallNotification);

src/plugins/jingle/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { _converse, converse } from '@converse/headless/core.js';
88
import 'plugins/modal/index.js';
9+
import "./chat-header-notification.js";
910
import './toolbar-button.js';
1011
import { html } from "lit";
1112

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
import { html } from 'lit';
2+
import { __ } from 'i18n';
23
import { JINGLE_CALL_STATUS } from '../constants';
34

5+
const tpl_active_call = (o) => {
6+
const button = __('Call Inititated');
7+
return html`
8+
<div>
9+
<span><button @click=${ o.endCall }>${ button }</button></span>
10+
</div>
11+
`;
12+
}
13+
14+
// ${(jingle_status === JINGLE_CALL_STATUS.ACTIVE) ? html`${tpl_active_call(el)}` : html`` }
415
export default (el) => {
16+
const jingle_status = el.model.get('jingle_status');
517
return html`
618
<div>
7-
${ (el.model.get('jingle_status')) === JINGLE_CALL_STATUS.PENDING ? html`<span class="badge bg-secondary">Calling...</span>` : html``}
19+
${(jingle_status === JINGLE_CALL_STATUS.PENDING) ? html`Calling...` : '' }
20+
</div>
21+
<div>
22+
${(jingle_status === JINGLE_CALL_STATUS.PENDING) ? tpl_active_call(el) : '' }
23+
${(jingle_status === JINGLE_CALL_STATUS.ENDED) ? html`Call Ended` : '' }
824
</div>
925
`;
1026
}

src/plugins/jingle/templates/toolbar-button.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@ import { JINGLE_CALL_STATUS } from '../constants';
55
export default (el) => {
66
const call_color = '--chat-toolbar-btn-color';
77
const end_call_color = '--chat-toolbar-btn-close-color';
8-
const i18n_start_call = __('Start a call');
98
const jingle_status = el.model.get('jingle_status');
9+
let button_color, i18n_start_call;
10+
if (jingle_status === JINGLE_CALL_STATUS.PENDING || jingle_status === JINGLE_CALL_STATUS.ACTIVE) {
11+
button_color = end_call_color;
12+
i18n_start_call = __('Stop the call');
13+
}
14+
else {
15+
button_color = call_color;
16+
i18n_start_call = __('Start a call');
17+
}
1018
return html`
11-
<button class="toggle-call" @click=${el.toggleJingleCallStatus()} title="${i18n_start_call}">
12-
<converse-icon id="temp" color="var(${( jingle_status ||jingle_status === JINGLE_CALL_STATUS.PENDING || jingle_status === JINGLE_CALL_STATUS.ACTIVE ) ? end_call_color : call_color })" class="fa fa-phone" size="1em"></converse-icon>
19+
<button class="toggle-call" @click=${el.toggleJingleCallStatus} title="${i18n_start_call}">
20+
<converse-icon id="temp" color="var(${ button_color })" class="fa fa-phone" size="1em"></converse-icon>
1321
</button>`
1422
}

src/plugins/jingle/toolbar-button.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default class JingleToolbarButton extends CustomElement {
1313

1414
initialize() {
1515
this.model = _converse.chatboxes.get(this.jid);
16-
this.listenTo(this.model, 'change:jingle_status', this.requestUpdate);
16+
this.listenTo(this.model, 'change:jingle_status', () => this.requestUpdate());
1717
}
1818

1919
render() {

0 commit comments

Comments
 (0)