Commit ec2bda33 authored by JC Brand's avatar JC Brand

Refactor XMPPStatus.

- Remove undocumented and unused event `update-status-ui`
- Remove xhr_custom_status and xhr_custom_status_url options
- Use default value
- Remove unnecessary getter and setter
parent ad01ab30
# Changelog # Changelog
## 4.0.0 (Unreleased)
* Removed the `xhr_custom_status` and `xhr_custom_status_url` configuration
settings. If you relied on these settings, you can instead listen for the
[statusMessageChanged](https://conversejs.org/docs/html/events.html#contactstatusmessagechanged)
event and make the XMLHttpRequest yourself.
## 3.3.4 (Unreleased) ## 3.3.4 (Unreleased)
- Avoid `eval` (via `_.template` from lodash). - Avoid `eval` (via `_.template` from lodash).
......
...@@ -1526,32 +1526,6 @@ An example from `the embedded room demo <https://conversejs.org/demo/embedded.ht ...@@ -1526,32 +1526,6 @@ An example from `the embedded room demo <https://conversejs.org/demo/embedded.ht
}); });
xhr_custom_status
-----------------
* Default: ``false``
.. note::
XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous JavaScript and XML).
This option will let converse.js make an AJAX POST with your changed custom chat status to a
remote server.
xhr_custom_status_url
---------------------
.. note::
XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous JavaScript and XML).
* Default: Empty string
Used only in conjunction with ``xhr_custom_status``.
This is the URL to which the AJAX POST request to set the user's custom status
message will be made.
The message itself is sent in the request under the key ``msg``.
xhr_user_search xhr_user_search
--------------- ---------------
......
...@@ -329,9 +329,7 @@ ...@@ -329,9 +329,7 @@
synchronize_availability: true, synchronize_availability: true,
view_mode: 'overlayed', // Choices are 'overlayed', 'fullscreen', 'mobile' view_mode: 'overlayed', // Choices are 'overlayed', 'fullscreen', 'mobile'
websocket_url: undefined, websocket_url: undefined,
whitelisted_plugins: [], whitelisted_plugins: []
xhr_custom_status: false,
xhr_custom_status_url: '',
}; };
_.assignIn(this, this.default_settings); _.assignIn(this, this.default_settings);
// Allow only whitelisted configuration attributes to be overwritten // Allow only whitelisted configuration attributes to be overwritten
...@@ -401,7 +399,7 @@ ...@@ -401,7 +399,7 @@
_converse.auto_changed_status = false; _converse.auto_changed_status = false;
// XXX: we should really remember the original state here, and // XXX: we should really remember the original state here, and
// then set it back to that... // then set it back to that...
_converse.xmppstatus.setStatus(_converse.default_state); _converse.xmppstatus.set('status', _converse.default_state);
} }
}; };
...@@ -414,7 +412,7 @@ ...@@ -414,7 +412,7 @@
// This can happen when the connection reconnects. // This can happen when the connection reconnects.
return; return;
} }
const stat = _converse.xmppstatus.getStatus(); const stat = _converse.xmppstatus.get('status');
_converse.idle_seconds++; _converse.idle_seconds++;
if (_converse.csi_waiting_time > 0 && if (_converse.csi_waiting_time > 0 &&
_converse.idle_seconds > _converse.csi_waiting_time && _converse.idle_seconds > _converse.csi_waiting_time &&
...@@ -425,12 +423,12 @@ ...@@ -425,12 +423,12 @@
_converse.idle_seconds > _converse.auto_away && _converse.idle_seconds > _converse.auto_away &&
stat !== 'away' && stat !== 'xa' && stat !== 'dnd') { stat !== 'away' && stat !== 'xa' && stat !== 'dnd') {
_converse.auto_changed_status = true; _converse.auto_changed_status = true;
_converse.xmppstatus.setStatus('away'); _converse.xmppstatus.set('status', 'away');
} else if (_converse.auto_xa > 0 && } else if (_converse.auto_xa > 0 &&
_converse.idle_seconds > _converse.auto_xa && _converse.idle_seconds > _converse.auto_xa &&
stat !== 'xa' && stat !== 'dnd') { stat !== 'xa' && stat !== 'dnd') {
_converse.auto_changed_status = true; _converse.auto_changed_status = true;
_converse.xmppstatus.setStatus('xa'); _converse.xmppstatus.set('status', 'xa');
} }
}; };
...@@ -1482,18 +1480,21 @@ ...@@ -1482,18 +1480,21 @@
this.connfeedback = new this.ConnectionFeedback(); this.connfeedback = new this.ConnectionFeedback();
this.XMPPStatus = Backbone.Model.extend({ this.XMPPStatus = Backbone.Model.extend({
defaults: {
"status": _converse.default_state
},
initialize () { initialize () {
this.set({ this.on('change:status', (item) => {
'status' : this.getStatus() const status = this.get('status');
this.sendPresence(status);
_converse.emit('statusChanged', status);
}); });
this.on('change', (item) => {
if (_.has(item.changed, 'status')) { this.on('change:status_message', () => {
_converse.emit('statusChanged', this.get('status')); const status_message = this.get('status_message');
} this.sendPresence(this.get('status'), status_message);
if (_.has(item.changed, 'status_message')) { _converse.emit('statusMessageChanged', status_message);
_converse.emit('statusMessageChanged', this.get('status_message'));
}
}); });
}, },
...@@ -1529,30 +1530,6 @@ ...@@ -1529,30 +1530,6 @@
sendPresence (type, status_message) { sendPresence (type, status_message) {
_converse.connection.send(this.constructPresence(type, status_message)); _converse.connection.send(this.constructPresence(type, status_message));
},
setStatus (value) {
this.sendPresence(value);
this.save({'status': value});
},
getStatus () {
return this.get('status') || _converse.default_state;
},
setStatusMessage (status_message) {
this.sendPresence(this.getStatus(), status_message);
this.save({'status_message': status_message});
if (this.xhr_custom_status) {
const xhr = new XMLHttpRequest();
xhr.open('POST', this.xhr_custom_status_url, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
xhr.send({'msg': status_message});
}
const prev_status = this.get('status_message');
if (prev_status === status_message) {
this.trigger("update-status-ui", this);
}
} }
}); });
......
...@@ -40,6 +40,9 @@ ...@@ -40,6 +40,9 @@
_converse.ChatStatusModal = Backbone.VDOMView.extend({ _converse.ChatStatusModal = Backbone.VDOMView.extend({
id: "modal-status-change", id: "modal-status-change",
events: {
"submit.set-xmpp-status .logout": "onFormSubmitted"
},
initialize () { initialize () {
this.render().insertIntoDOM(); this.render().insertIntoDOM();
...@@ -72,14 +75,19 @@ ...@@ -72,14 +75,19 @@
'modal_title': __('Change chat status'), 'modal_title': __('Change chat status'),
'placeholder_status_message': __('Personal status message') 'placeholder_status_message': __('Personal status message')
})); }));
},
onFormSubmitted (ev) {
ev.preventDefault();
debugger;
this.model.save('status_message', ev.target.querySelector('input').value);
} }
}); });
_converse.XMPPStatusView = Backbone.VDOMView.extend({ _converse.XMPPStatusView = Backbone.VDOMView.extend({
tagName: "div", tagName: "div",
events: { events: {
"click a.change-status": "renderStatusChangeForm", "click a.change-status": this.status_modal.show.bind(this.status_modal),
"submit": "setStatusMessage",
"click .dropdown dd ul li a": "setStatus", "click .dropdown dd ul li a": "setStatus",
"click .logout": "logOut" "click .logout": "logOut"
}, },
...@@ -103,15 +111,6 @@ ...@@ -103,15 +111,6 @@
})); }));
}, },
renderStatusChangeForm (ev) {
this.status_modal.show();
},
setStatusMessage (ev) {
ev.preventDefault();
this.model.setStatusMessage(ev.target.querySelector('input').value);
},
logOut (ev) { logOut (ev) {
ev.preventDefault(); ev.preventDefault();
const result = confirm(__("Are you sure you want to log out?")); const result = confirm(__("Are you sure you want to log out?"));
...@@ -123,7 +122,7 @@ ...@@ -123,7 +122,7 @@
setStatus (ev) { setStatus (ev) {
ev.preventDefault(); ev.preventDefault();
const value = ev.target.getAttribute('data-value'); const value = ev.target.getAttribute('data-value');
this.model.setStatus(value); this.model.set('status', value);
}, },
getPrettyStatus (stat) { getPrettyStatus (stat) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment