- Clear timer when a messages changes from epehemeral to non-ephemeral
- Set MUC occupant on `groupchat` message when `type` changes to `groupchat` (from `error`)
- Set roster contact on `chat` message when `type` changes to `chat` (from `error`)

Thanks @afriedmanGlacier
This commit is contained in:
JC Brand 2022-02-15 12:12:54 +01:00
parent a07bd7c817
commit b44e1c82f0
4 changed files with 29 additions and 23 deletions

View File

@ -5,9 +5,10 @@
- Updated translations: af, ar, es, eu, fr, gl, he, lt
- Increased stanza timeout from 10 to 20 seconds
- Replace various font icons with SVG icons
- Fix bug where MUC config wasn't persisted across page loads
- #1761: Add a new dark theme based on the [Dracula](https://draculatheme.com/) theme
- #2627: Spoiler toggles only after switching to another tab and back
- #2733: Fix OMEMO race condition related to automatic reconnection
- #2733: Fix OMEMO race condition related to automatic reconnection and SMACKS
- #2733: Wait for decrypted/parsed message before queuing to UI
- #2751: Media not rendered when Converse runs in a browser extension
- #2786: Fix webpack configuration not working on Windows OS

View File

@ -28,13 +28,14 @@ const MessageMixin = {
return;
}
this.initialized = getOpenPromise();
if (this.get('type') === 'chat') {
ModelWithContact.prototype.initialize.apply(this, arguments);
this.setRosterContact(Strophe.getBareJidFromJid(this.get('from')));
}
if (this.get('file')) {
this.on('change:put', this.uploadFile, this);
this.on('change:put', () => this.uploadFile());
}
// If `type` changes from `error` to `chat`, we want to set the contact. See #2733
this.on('change:type', () => this.setContact());
this.on('change:is_ephemeral', () => this.setTimerForEphemeralMessage());
await this.setContact();
this.setTimerForEphemeralMessage();
/**
* Triggered once a {@link _converse.Message} has been created and initialized.
@ -46,25 +47,25 @@ const MessageMixin = {
this.initialized.resolve();
},
setContact () {
if (this.get('type') === 'chat') {
ModelWithContact.prototype.initialize.apply(this, arguments);
this.setRosterContact(Strophe.getBareJidFromJid(this.get('from')));
}
},
/**
* Sets an auto-destruct timer for this message, if it's is_ephemeral.
* @private
* @method _converse.Message#setTimerForEphemeralMessage
* @returns { Boolean } - Indicates whether the message is
* ephemeral or not, and therefore whether the timer was set or not.
*/
setTimerForEphemeralMessage () {
const setTimer = () => {
this.ephemeral_timer = window.setTimeout(this.safeDestroy.bind(this), 10000);
};
if (this.ephemeral_timer) {
clearTimeout(this.ephemeral_timer);
}
if (this.isEphemeral()) {
setTimer();
return true;
} else {
this.on('change:is_ephemeral', () =>
this.isEphemeral() ? setTimer() : clearTimeout(this.ephemeral_timer)
);
return false;
this.ephemeral_timer = window.setTimeout(() => this.safeDestroy(), 10000);
}
},

View File

@ -14,11 +14,14 @@ const ChatRoomMessageMixin = {
return;
}
if (this.get('file')) {
this.on('change:put', this.uploadFile, this);
}
if (!this.setTimerForEphemeralMessage()) {
this.setOccupant();
this.on('change:put', () => this.uploadFile());
}
// If `type` changes from `error` to `groupchat`, we want to set the occupant. See #2733
this.on('change:type', () => this.setOccupant());
this.on('change:is_ephemeral', () => this.setTimerForEphemeralMessage());
this.setTimerForEphemeralMessage();
this.setOccupant();
/**
* Triggered once a {@link _converse.ChatRoomMessageInitialized} has been created and initialized.
* @event _converse#chatRoomMessageInitialized
@ -89,7 +92,7 @@ const ChatRoomMessageMixin = {
},
setOccupant () {
if (this.get('type') !== 'groupchat') {
if (this.get('type') !== 'groupchat' || this.isEphemeral() || this.occupant) {
return;
}
const chatbox = this?.collection?.chatbox;

View File

@ -219,6 +219,7 @@ describe("The OMEMO module", function() {
expect(view.model.messages.length).toBe(1);
const msg = view.model.messages.at(0);
expect(msg.get('is_ephemeral')).toBe(false)
expect(msg.getDisplayName()).toBe('Mercutio');
}));
it("will create a new device based on a received carbon message",