Commit 8eef8787cc

8eef8787cc2533fa1ed7f9b0e19049b0eb9cb284

parent: c9c547acc1

Unregistered key

Benjamin Große <ste3ls@gmail.com> · 2023-01-31 12:04 UTC
committer: <git@ulyssa.dev>

fix: attachment download flags + exists check (#34)

Fix files never downloading (unless it has been downloaded in the past
and using `!` force flag).

The logic should be:

* If file does not exist, or `!` force flag used, then download it
* Else if neither `!` or `:open` flag used, then error out

and then return downloaded-message or open-and-message.

I.e. `:open` should still open the file if it has already been
downloaded. Otherwise the only way to open it is to use `!` and
re-download it.

Layout: unified · split

src/windows/room/chat.rs +9 −11
@@ -215,17 +215,7 @@ impl ChatState {
215 }, 215 },
216 }; 216 };
217 217
218 if filename.exists() { 218 if !filename.exists() || flags.contains(DownloadFlags::FORCE) {
219 if !flags.contains(DownloadFlags::FORCE) {
220 let msg = format!(
221 "The file {} already exists; add ! to end of command to overwrite it.",
222 filename.display()
223 );
224 let err = UIError::Failure(msg);
225
226 return Err(err);
227 }
228
229 let req = MediaRequest { source, format: MediaFormat::File }; 219 let req = MediaRequest { source, format: MediaFormat::File };
230 220
231 let bytes = 221 let bytes =
@@ -234,6 +224,14 @@ impl ChatState {
234 fs::write(filename.as_path(), bytes.as_slice())?; 224 fs::write(filename.as_path(), bytes.as_slice())?;
235 225
236 msg.downloaded = true; 226 msg.downloaded = true;
227 } else if !flags.contains(DownloadFlags::OPEN) {
228 let msg = format!(
229 "The file {} already exists; add ! to end of command to overwrite it.",
230 filename.display()
231 );
232 let err = UIError::Failure(msg);
233
234 return Err(err);
237 } 235 }
238 236
239 let info = if flags.contains(DownloadFlags::OPEN) { 237 let info = if flags.contains(DownloadFlags::OPEN) {