Proper handling of moderator clearing files and sharing same file twice. Fixes #257

auto_join_3.3
Håvar Aambø Fosstveit 2020-04-30 23:06:02 +02:00
parent de413fb670
commit 3de8555c10
2 changed files with 31 additions and 6 deletions

View File

@ -674,7 +674,7 @@ export default class RoomClient
{ {
if (err) if (err)
{ {
return store.dispatch(requestActions.notify( store.dispatch(requestActions.notify(
{ {
type : 'error', type : 'error',
text : intl.formatMessage({ text : intl.formatMessage({
@ -682,6 +682,8 @@ export default class RoomClient
defaultMessage : 'Unable to save file' defaultMessage : 'Unable to save file'
}) })
})); }));
return;
} }
saveAs(blob, file.name); saveAs(blob, file.name);
@ -698,7 +700,9 @@ export default class RoomClient
if (existingTorrent) if (existingTorrent)
{ {
// Never add duplicate torrents, use the existing one instead. // Never add duplicate torrents, use the existing one instead.
return this._handleTorrent(existingTorrent); this._handleTorrent(existingTorrent);
return;
} }
this._webTorrent.add(magnetUri, this._handleTorrent); this._webTorrent.add(magnetUri, this._handleTorrent);
@ -710,11 +714,13 @@ export default class RoomClient
// same file was sent multiple times. // same file was sent multiple times.
if (torrent.progress === 1) if (torrent.progress === 1)
{ {
return store.dispatch( store.dispatch(
fileActions.setFileDone( fileActions.setFileDone(
torrent.magnetURI, torrent.magnetURI,
torrent.files torrent.files
)); ));
return;
} }
let lastMove = 0; let lastMove = 0;
@ -757,7 +763,7 @@ export default class RoomClient
{ {
if (err) if (err)
{ {
return store.dispatch(requestActions.notify( store.dispatch(requestActions.notify(
{ {
type : 'error', type : 'error',
text : intl.formatMessage({ text : intl.formatMessage({
@ -765,13 +771,30 @@ export default class RoomClient
defaultMessage : 'Unable to share file' defaultMessage : 'Unable to share file'
}) })
})); }));
return;
} }
const existingTorrent = this._webTorrent.get(torrent); const existingTorrent = this._webTorrent.get(torrent);
if (existingTorrent) if (existingTorrent)
{ {
return this._sendFile(existingTorrent.magnetURI); store.dispatch(requestActions.notify(
{
text : intl.formatMessage({
id : 'filesharing.successfulFileShare',
defaultMessage : 'File successfully shared'
})
}));
store.dispatch(fileActions.addFile(
this._peerId,
existingTorrent.magnetURI
));
this._sendFile(existingTorrent.magnetURI);
return;
} }
this._webTorrent.seed( this._webTorrent.seed(

View File

@ -36,7 +36,7 @@ const FileSharing = (props) =>
{ {
if (event.target.files.length > 0) if (event.target.files.length > 0)
{ {
props.roomClient.shareFiles(event.target.files); await props.roomClient.shareFiles(event.target.files);
} }
}; };
@ -65,6 +65,8 @@ const FileSharing = (props) =>
type='file' type='file'
disabled={!canShare} disabled={!canShare}
onChange={handleFileChange} onChange={handleFileChange}
// Need to reset to be able to share same file twice
onClick={(e) => (e.target.value = null)}
id='share-files-button' id='share-files-button'
/> />
<label htmlFor='share-files-button'> <label htmlFor='share-files-button'>