Fix typing indicator in groups: now goes away when we get the message
This commit is contained in:
parent
d1d7e0aa99
commit
5f6a9a661f
1 changed files with 23 additions and 14 deletions
|
@ -546,11 +546,20 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
async onNewMessage(message) {
|
async onNewMessage(message) {
|
||||||
|
const uuid = message.get ? message.get('sourceUuid') : message.sourceUuid;
|
||||||
|
const e164 = message.get ? message.get('source') : message.source;
|
||||||
|
const sourceDevice = message.get
|
||||||
|
? message.get('sourceDevice')
|
||||||
|
: message.sourceDevice;
|
||||||
|
|
||||||
|
const sourceId = window.ConversationController.ensureContactIds({
|
||||||
|
uuid,
|
||||||
|
e164,
|
||||||
|
});
|
||||||
|
const typingToken = `${sourceId}.${sourceDevice}`;
|
||||||
|
|
||||||
// Clear typing indicator for a given contact if we receive a message from them
|
// Clear typing indicator for a given contact if we receive a message from them
|
||||||
const deviceId = message.get
|
this.clearContactTypingTimer(typingToken);
|
||||||
? `${message.get('conversationId')}.${message.get('sourceDevice')}`
|
|
||||||
: `${message.conversationId}.${message.sourceDevice}`;
|
|
||||||
this.clearContactTypingTimer(deviceId);
|
|
||||||
|
|
||||||
this.debouncedUpdateLastMessage();
|
this.debouncedUpdateLastMessage();
|
||||||
},
|
},
|
||||||
|
@ -3142,26 +3151,26 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const deviceId = `${senderId}.${senderDevice}`;
|
const typingToken = `${senderId}.${senderDevice}`;
|
||||||
|
|
||||||
this.contactTypingTimers = this.contactTypingTimers || {};
|
this.contactTypingTimers = this.contactTypingTimers || {};
|
||||||
const record = this.contactTypingTimers[deviceId];
|
const record = this.contactTypingTimers[typingToken];
|
||||||
|
|
||||||
if (record) {
|
if (record) {
|
||||||
clearTimeout(record.timer);
|
clearTimeout(record.timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isTyping) {
|
if (isTyping) {
|
||||||
this.contactTypingTimers[deviceId] = this.contactTypingTimers[
|
this.contactTypingTimers[typingToken] = this.contactTypingTimers[
|
||||||
deviceId
|
typingToken
|
||||||
] || {
|
] || {
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
senderId,
|
senderId,
|
||||||
senderDevice,
|
senderDevice,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.contactTypingTimers[deviceId].timer = setTimeout(
|
this.contactTypingTimers[typingToken].timer = setTimeout(
|
||||||
this.clearContactTypingTimer.bind(this, deviceId),
|
this.clearContactTypingTimer.bind(this, typingToken),
|
||||||
15 * 1000
|
15 * 1000
|
||||||
);
|
);
|
||||||
if (!record) {
|
if (!record) {
|
||||||
|
@ -3169,7 +3178,7 @@
|
||||||
this.trigger('change', this);
|
this.trigger('change', this);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
delete this.contactTypingTimers[deviceId];
|
delete this.contactTypingTimers[typingToken];
|
||||||
if (record) {
|
if (record) {
|
||||||
// User was previously typing, and is no longer. State change!
|
// User was previously typing, and is no longer. State change!
|
||||||
this.trigger('change', this);
|
this.trigger('change', this);
|
||||||
|
@ -3177,13 +3186,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
clearContactTypingTimer(deviceId) {
|
clearContactTypingTimer(typingToken) {
|
||||||
this.contactTypingTimers = this.contactTypingTimers || {};
|
this.contactTypingTimers = this.contactTypingTimers || {};
|
||||||
const record = this.contactTypingTimers[deviceId];
|
const record = this.contactTypingTimers[typingToken];
|
||||||
|
|
||||||
if (record) {
|
if (record) {
|
||||||
clearTimeout(record.timer);
|
clearTimeout(record.timer);
|
||||||
delete this.contactTypingTimers[deviceId];
|
delete this.contactTypingTimers[typingToken];
|
||||||
|
|
||||||
// User was previously typing, but timed out or we received message. State change!
|
// User was previously typing, but timed out or we received message. State change!
|
||||||
this.trigger('change', this);
|
this.trigger('change', this);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue