|
@@ -8,17 +8,16 @@ import { isIdle, getIdleSeconds } from './utils.js';
|
|
const { Strophe, $pres } = converse.env;
|
|
const { Strophe, $pres } = converse.env;
|
|
|
|
|
|
export default class XMPPStatus extends ColorAwareModel(Model) {
|
|
export default class XMPPStatus extends ColorAwareModel(Model) {
|
|
-
|
|
|
|
- constructor(attributes, options) {
|
|
|
|
|
|
+ constructor(attributes, options) {
|
|
super(attributes, options);
|
|
super(attributes, options);
|
|
this.vcard = null;
|
|
this.vcard = null;
|
|
}
|
|
}
|
|
|
|
|
|
- defaults () {
|
|
|
|
- return { "status": api.settings.get("default_state") }
|
|
|
|
|
|
+ defaults() {
|
|
|
|
+ return { 'status': api.settings.get('default_state') };
|
|
}
|
|
}
|
|
|
|
|
|
- getStatus () {
|
|
|
|
|
|
+ getStatus() {
|
|
return this.get('status');
|
|
return this.get('status');
|
|
}
|
|
}
|
|
|
|
|
|
@@ -34,20 +33,20 @@ export default class XMPPStatus extends ColorAwareModel(Model) {
|
|
return super.get(attr);
|
|
return super.get(attr);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * @param {string|Object} key
|
|
|
|
- * @param {string|Object} [val]
|
|
|
|
- * @param {Object} [options]
|
|
|
|
- */
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param {string|Object} key
|
|
|
|
+ * @param {string|Object} [val]
|
|
|
|
+ * @param {Object} [options]
|
|
|
|
+ */
|
|
set(key, val, options) {
|
|
set(key, val, options) {
|
|
if (key === 'jid' || key === 'nickname') {
|
|
if (key === 'jid' || key === 'nickname') {
|
|
- throw new Error('Readonly property')
|
|
|
|
|
|
+ throw new Error('Readonly property');
|
|
}
|
|
}
|
|
return super.set(key, val, options);
|
|
return super.set(key, val, options);
|
|
}
|
|
}
|
|
|
|
|
|
- initialize () {
|
|
|
|
- this.on('change', item => {
|
|
|
|
|
|
+ initialize() {
|
|
|
|
+ this.on('change', (item) => {
|
|
if (!(item.changed instanceof Object)) {
|
|
if (!(item.changed instanceof Object)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -57,15 +56,15 @@ export default class XMPPStatus extends ColorAwareModel(Model) {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- getDisplayName () {
|
|
|
|
|
|
+ getDisplayName() {
|
|
return this.getFullname() || this.getNickname() || this.get('jid');
|
|
return this.getFullname() || this.getNickname() || this.get('jid');
|
|
}
|
|
}
|
|
|
|
|
|
- getNickname () {
|
|
|
|
|
|
+ getNickname() {
|
|
return api.settings.get('nickname');
|
|
return api.settings.get('nickname');
|
|
}
|
|
}
|
|
|
|
|
|
- getFullname () {
|
|
|
|
|
|
+ getFullname() {
|
|
return ''; // Gets overridden in converse-vcard
|
|
return ''; // Gets overridden in converse-vcard
|
|
}
|
|
}
|
|
|
|
|
|
@@ -74,8 +73,8 @@ export default class XMPPStatus extends ColorAwareModel(Model) {
|
|
* @param {string} [to] - The JID to which this presence should be sent
|
|
* @param {string} [to] - The JID to which this presence should be sent
|
|
* @param {string} [status_message]
|
|
* @param {string} [status_message]
|
|
*/
|
|
*/
|
|
- async constructPresence (type, to=null, status_message) {
|
|
|
|
- type = typeof type === 'string' ? type : (this.get('status') || api.settings.get("default_state"));
|
|
|
|
|
|
+ async constructPresence(type, to = null, status_message) {
|
|
|
|
+ type = typeof type === 'string' ? type : this.get('status') || api.settings.get('default_state');
|
|
status_message = typeof status_message === 'string' ? status_message : this.get('status_message');
|
|
status_message = typeof status_message === 'string' ? status_message : this.get('status_message');
|
|
|
|
|
|
let presence;
|
|
let presence;
|
|
@@ -84,30 +83,31 @@ export default class XMPPStatus extends ColorAwareModel(Model) {
|
|
presence = $pres({ to, type });
|
|
presence = $pres({ to, type });
|
|
const { xmppstatus } = _converse.state;
|
|
const { xmppstatus } = _converse.state;
|
|
const nick = xmppstatus.getNickname();
|
|
const nick = xmppstatus.getNickname();
|
|
- if (nick) presence.c('nick', {'xmlns': Strophe.NS.NICK}).t(nick).up();
|
|
|
|
-
|
|
|
|
- } else if ((type === 'unavailable') ||
|
|
|
|
- (type === 'probe') ||
|
|
|
|
- (type === 'error') ||
|
|
|
|
- (type === 'unsubscribe') ||
|
|
|
|
- (type === 'unsubscribed') ||
|
|
|
|
- (type === 'subscribed')) {
|
|
|
|
|
|
+ if (nick) presence.c('nick', { 'xmlns': Strophe.NS.NICK }).t(nick).up();
|
|
|
|
+ } else if (
|
|
|
|
+ type === 'unavailable' ||
|
|
|
|
+ type === 'probe' ||
|
|
|
|
+ type === 'error' ||
|
|
|
|
+ type === 'unsubscribe' ||
|
|
|
|
+ type === 'unsubscribed' ||
|
|
|
|
+ type === 'subscribed'
|
|
|
|
+ ) {
|
|
presence = $pres({ to, type });
|
|
presence = $pres({ to, type });
|
|
-
|
|
|
|
} else if (type === 'offline') {
|
|
} else if (type === 'offline') {
|
|
presence = $pres({ to, type: 'unavailable' });
|
|
presence = $pres({ to, type: 'unavailable' });
|
|
-
|
|
|
|
} else if (type === 'online') {
|
|
} else if (type === 'online') {
|
|
presence = $pres({ to });
|
|
presence = $pres({ to });
|
|
-
|
|
|
|
} else {
|
|
} else {
|
|
presence = $pres({ to }).c('show').t(type).up();
|
|
presence = $pres({ to }).c('show').t(type).up();
|
|
}
|
|
}
|
|
|
|
|
|
if (status_message) presence.c('status').t(status_message).up();
|
|
if (status_message) presence.c('status').t(status_message).up();
|
|
|
|
|
|
- const priority = api.settings.get("priority");
|
|
|
|
- presence.c('priority').t(Number.isNaN(Number(priority)) ? 0 : priority).up();
|
|
|
|
|
|
+ const priority = api.settings.get('priority');
|
|
|
|
+ presence
|
|
|
|
+ .c('priority')
|
|
|
|
+ .t(Number.isNaN(Number(priority)) ? 0 : priority)
|
|
|
|
+ .up();
|
|
|
|
|
|
if (isIdle()) {
|
|
if (isIdle()) {
|
|
const idle_since = new Date();
|
|
const idle_since = new Date();
|