Closed Bug 1642189 Opened 4 months ago Closed 4 months ago

Fire event when the user changes compose identity

Categories

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

enhancement

Tracking

(thunderbird78+ fixed)

RESOLVED FIXED
Thunderbird 79.0
Tracking Status
thunderbird78 + fixed

People

(Reporter: dreadnaut, Assigned: darktrojan)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0

Steps to reproduce:

I'm working to port a Thunderbird add-on¹ to MailExtension.

[1] https://addons.thunderbird.net/thunderbird/addon/bordercolors-d/

Actual results:

I can read and write the compose identity with get/setComposeDetails, but there is no way to know when the user switches identity.

Expected results:

This could be solved by adding a new event in the compose extension API², something like onIdentityUpdated or onIdentityChanged.

[2] https://hg.mozilla.org/comm-central/file/tip/mail/components/extensions/parent/ext-compose.js#l380

Assignee: nobody → geoff
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true

We're not otherwise using the event in MsgComposeCommands.js, so I see no problem in changing it, and the change in onAttachmentRemoved is just correcting an earlier mistake.

Attachment #9156146 - Flags: review?(mkmelin+mozilla)
Comment on attachment 9156146 [details] [diff] [review]
1642189-compose-identitychanged-1.diff

Review of attachment 9156146 [details] [diff] [review]:
-----------------------------------------------------------------

Looks good
Attachment #9156146 - Flags: review?(mkmelin+mozilla) → review+

Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/163e5bbcbf51
Fire event when the user changes compose identity. r=mkmelin

Status: ASSIGNED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 79.0
Comment on attachment 9156146 [details] [diff] [review]
1642189-compose-identitychanged-1.diff

[Approval Request Comment]
Improved/fixed WX API
Attachment #9156146 - Flags: approval-comm-beta?

Is there any functional change here?

-      let event = document.createEvent("Events");
-      event.initEvent("compose-from-changed", false, true);
-      document.getElementById("msgcomposeWindow").dispatchEvent(event);
+      window.dispatchEvent(new CustomEvent("compose-from-changed"));

There are add-ons using this like window.addEventListener("compose-from-changed", myListener, true); - That will still work, right?

Flags: needinfo?(geoff)

It's just the "new" more modern way of doing it. initEvent is deprecated but still working

Flags: needinfo?(geoff)

Thanks. I understand it now. The bug is about providing this event as a WE API and you took the opportunity to modernise a bit.

Thank you all for getting this done so fast!

(In reply to Jorg K (CEST = GMT+2) from comment #5)

There are add-ons using this like window.addEventListener("compose-from-changed", myListener, true); - That will still work, right?

As written that would work, but we're now firing the event on the window not the root element of the document. A minor change is probably necessary.

Comment on attachment 9156146 [details] [diff] [review]
1642189-compose-identitychanged-1.diff

Approved for beta
Attachment #9156146 - Flags: approval-comm-beta? → approval-comm-beta+
You need to log in before you can comment on or make changes to this bug.