add notification when message transfer is completed analogous to completed file transfer

This commit is contained in:
schlagmichdoch 2022-11-08 15:43:24 +01:00
parent cc9c2bf088
commit c1575c8b85

View file

@ -167,8 +167,11 @@ class Peer {
case 'progress': case 'progress':
this._onDownloadProgress(message.progress); this._onDownloadProgress(message.progress);
break; break;
case 'transfer-complete': case 'file-transfer-complete':
this._onTransferCompleted(); this._onFileTransferCompleted();
break;
case 'message-transfer-complete':
this._onMessageTransferCompleted();
break; break;
case 'text': case 'text':
this._onTextReceived(message); this._onTextReceived(message);
@ -204,10 +207,10 @@ class Peer {
_onFileReceived(proxyFile) { _onFileReceived(proxyFile) {
Events.fire('file-received', proxyFile); Events.fire('file-received', proxyFile);
this.sendJSON({ type: 'transfer-complete' }); this.sendJSON({ type: 'file-transfer-complete' });
} }
_onTransferCompleted() { _onFileTransferCompleted() {
this._onDownloadProgress(1); this._onDownloadProgress(1);
this._reader = null; this._reader = null;
this._busy = false; this._busy = false;
@ -215,6 +218,10 @@ class Peer {
Events.fire('notify-user', 'File transfer completed.'); Events.fire('notify-user', 'File transfer completed.');
} }
_onMessageTransferCompleted() {
Events.fire('notify-user', 'Message transfer completed.');
}
sendText(text) { sendText(text) {
const unescaped = btoa(unescape(encodeURIComponent(text))); const unescaped = btoa(unescape(encodeURIComponent(text)));
this.sendJSON({ type: 'text', text: unescaped }); this.sendJSON({ type: 'text', text: unescaped });
@ -223,6 +230,7 @@ class Peer {
_onTextReceived(message) { _onTextReceived(message) {
const escaped = decodeURIComponent(escape(atob(message.text))); const escaped = decodeURIComponent(escape(atob(message.text)));
Events.fire('text-received', { text: escaped, sender: this._peerId }); Events.fire('text-received', { text: escaped, sender: this._peerId });
this.sendJSON({ type: 'message-transfer-complete' });
} }
} }