Closed Bug 1747441 Opened 2 years ago Closed 2 years ago

`compose.listAttachments` and `compose.addAttachment` should be reflexive

Categories

(Thunderbird :: Add-Ons: Extensions API, enhancement)

Thunderbird 91
enhancement

Tracking

(thunderbird_esr91 wontfix)

RESOLVED FIXED
98 Branch
Tracking Status
thunderbird_esr91 --- wontfix

People

(Reporter: siefkenj, Assigned: TbSync)

Details

Attachments

(1 file)

Steps to reproduce:

The results from compose.listAttachments should be able to be fed into compose.addAttachment. Currently there is an error that an attachments needs a file property.

A potential backwards-compatible solution would be to look at an attachment object. If it has an id, then clone the existing attachment with that id. Otherwise, proceed as before.

However, I think it would be nice if the addAttachment API also accepted a File object directly. Would there be a downside to this?

Related to this issue, it would be nice if there were an addAttachments API so one could do compose.addAttachments(10, await compose.listAttachments(9)) to clone the attachments from tab 9 to tab 10.

Unrelated (and maybe discussed elsewhere...) is there a reason for the name listAttachments rather than getAttachments?

Unrelated (and maybe discussed elsewhere...) is there a reason for the name listAttachments rather than getAttachments?

I guess the reason was to align it with messages.list(), which gets a list of all messages in a folder, and with messages.listAttachements()

With this patch, something like this should work:

browser.composeAction.onClicked.addListener(async (tab) => {
    let details = await browser.compose.getComposeDetails(tab.id);
    details.attachments = await browser.compose.listAttachments(tab.id);
    await browser.compose.beginNew(details)
})

or

let attachments = await browser.compose.listAttachments(tab1.id);
attachments.forEach(attachment => await browser.compose.addAttachment(tab2.id, attachment));

I think adding an extra addAttachments() function just to save the forEach loop is not necessary.

Does the patch work for you? It will also improve the documentation, as currently the attachments property of the ComposeDetails type is just of type object but there is no explanation what kind of object it is: it is either a FileAttachment or a ComposeAttachment.

Assignee: nobody → john
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Attachment #9256828 - Attachment description: WIP: Bug 1747441 - Add support for referencing existing ComposeAttachments when adding/updating attachments. → Bug 1747441 - Add support for referencing existing ComposeAttachments when adding attachments. r=mkmelin

Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/6b5b06bd76f2
Add support for referencing existing ComposeAttachments when adding attachments. r=mkmelin

Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 98 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: