Refactor chat close
methods
- Remove the shared base-class method. - Trigger `chatBoxClosed` on the model - Send CSN from the model, not the view
This commit is contained in:
parent
1598640c80
commit
0756af2b30
|
@ -37,8 +37,8 @@ Removed events:
|
|||
* `rosterGroupsFetched`
|
||||
* `messageSend` (use `sendMessage` instead)
|
||||
|
||||
The `chatBoxMaximized` and `chatBoxMinimized` events now have the `model` as
|
||||
payload and not the `view` since it might not be exist at that time.
|
||||
The `chatBoxClosed`, `chatBoxMaximized` and `chatBoxMinimized` events now have the `model` as
|
||||
payload and not the `view`.
|
||||
|
||||
## 7.0.5 (Unreleased)
|
||||
|
||||
|
|
|
@ -250,6 +250,12 @@ const ChatBox = ModelWithContact.extend({
|
|||
},
|
||||
|
||||
async close () {
|
||||
if (api.connection.connected()) {
|
||||
// Immediately sending the chat state, because the
|
||||
// model is going to be destroyed afterwards.
|
||||
this.setChatState(_converse.INACTIVE);
|
||||
this.sendChatState();
|
||||
}
|
||||
try {
|
||||
await new Promise((success, reject) => {
|
||||
return this.destroy({success, 'error': (m, e) => reject(e)})
|
||||
|
@ -261,6 +267,13 @@ const ChatBox = ModelWithContact.extend({
|
|||
await this.clearMessages();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Triggered once a chatbox has been closed.
|
||||
* @event _converse#chatBoxClosed
|
||||
* @type {_converse.ChatBox | _converse.ChatRoom}
|
||||
* @example _converse.api.listen.on('chatBoxClosed', chat => { ... });
|
||||
*/
|
||||
api.trigger('chatBoxClosed', this);
|
||||
},
|
||||
|
||||
announceReconnection () {
|
||||
|
@ -268,7 +281,7 @@ const ChatBox = ModelWithContact.extend({
|
|||
* Triggered whenever a `_converse.ChatBox` instance has reconnected after an outage
|
||||
* @event _converse#onChatReconnected
|
||||
* @type {_converse.ChatBox | _converse.ChatRoom}
|
||||
* @example _converse.api.listen.on('onChatReconnected', chatbox => { ... });
|
||||
* @example _converse.api.listen.on('onChatReconnected', chat => { ... });
|
||||
*/
|
||||
api.trigger('chatReconnected', this);
|
||||
},
|
||||
|
|
|
@ -133,11 +133,17 @@ export default class ChatView extends BaseChatView {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes this chat
|
||||
* @private
|
||||
* @method _converse.ChatBoxView#close
|
||||
*/
|
||||
close (ev) {
|
||||
ev?.preventDefault?.();
|
||||
if (_converse.router.history.getFragment() === 'converse/chat?jid=' + this.model.get('jid')) {
|
||||
_converse.router.navigate('');
|
||||
}
|
||||
return super.close(ev);
|
||||
return this.model.close(ev);
|
||||
}
|
||||
|
||||
afterShown () {
|
||||
|
|
|
@ -67,10 +67,11 @@ export default class MUCView extends BaseChatView {
|
|||
* @method _converse.ChatRoomView#close
|
||||
*/
|
||||
close (ev) {
|
||||
ev?.preventDefault?.();
|
||||
if (_converse.router.history.getFragment() === 'converse/room?jid=' + this.model.get('jid')) {
|
||||
_converse.router.navigate('');
|
||||
}
|
||||
return super.close(ev);
|
||||
return this.model.close(ev);
|
||||
}
|
||||
|
||||
async destroy () {
|
||||
|
|
|
@ -50,24 +50,6 @@ export default class BaseChatView extends ElementView {
|
|||
this.afterShown();
|
||||
}
|
||||
|
||||
async close (ev) {
|
||||
ev?.preventDefault?.();
|
||||
if (api.connection.connected()) {
|
||||
// Immediately sending the chat state, because the
|
||||
// model is going to be destroyed afterwards.
|
||||
this.model.setChatState(_converse.INACTIVE);
|
||||
this.model.sendChatState();
|
||||
}
|
||||
await this.model.close(ev);
|
||||
/**
|
||||
* Triggered once a chatbox has been closed.
|
||||
* @event _converse#chatBoxClosed
|
||||
* @type { _converse.ChatBoxView | _converse.ChatRoomView }
|
||||
* @example _converse.api.listen.on('chatBoxClosed', view => { ... });
|
||||
*/
|
||||
api.trigger('chatBoxClosed', this);
|
||||
}
|
||||
|
||||
emitBlurred (ev) {
|
||||
if (this.contains(document.activeElement) || this.contains(ev.relatedTarget)) {
|
||||
// Something else in this chatbox is still focused
|
||||
|
|
Loading…
Reference in New Issue
Block a user