Skip to content

Commit d6a947e

Browse files
committed
Deduplicate event dispatch logic
1 parent 231ca59 commit d6a947e

File tree

1 file changed

+127
-64
lines changed

1 file changed

+127
-64
lines changed

index.html

Lines changed: 127 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,16 +1680,12 @@ <h2>
16801680
associated with |subscription| and the process described in [[RFC8291]]. Set |bytes|
16811681
to the resulting [=/byte sequence=].
16821682
</li>
1683-
<li>If the <a>push message</a> payload could not be decrypted for any reason:
1684-
<ol>
1685-
<li>Acknowledge the receipt of the <a>push message</a> according to [[RFC8030]].
1686-
Though the message was not successfully received and processed, this prevents the
1687-
push service from attempting to retransmit the message; a badly encrypted message
1688-
is not recoverable.
1689-
</li>
1690-
<li>Abort these steps.
1691-
</li>
1692-
</ol>
1683+
<li>
1684+
<p>
1685+
If the <a>push message</a> payload could not be decrypted for any reason, then
1686+
[=acknowledge a push message|acknowledge=] the <a>push message</a> and abort
1687+
these steps.
1688+
</p>
16931689
<p class="note">
16941690
A `push` event is not fired for a <a>push message</a> that was not successfully
16951691
decrypted using the key pair associated with the <a>push subscription</a>.
@@ -1740,6 +1736,16 @@ <h2>
17401736
|registration|.
17411737
</p>
17421738
</li>
1739+
<li>
1740+
<p>
1741+
Let |notificationShown| be false.
1742+
</p>
1743+
</li>
1744+
<li>
1745+
<p>
1746+
Let |appBadgeSet| be false.
1747+
</p>
1748+
</li>
17431749
<li>
17441750
<p>
17451751
If |declarativeResult|'s [=declarative push message parser result/mutable=]
@@ -1748,65 +1754,86 @@ <h2>
17481754
<ol>
17491755
<li>
17501756
<p>
1751-
[=/Fire a functional event=] named "`push`" using {{PushEvent}} on
1752-
|registration| with the following properties:
1753-
</p>
1754-
<dl>
1755-
<dt>
1756-
{{PushEvent/data}}
1757-
</dt>
1758-
<dd>
1759-
null
1760-
</dd>
1761-
<dt>
1762-
{{PushEvent/notification}}
1763-
</dt>
1764-
<dd>
1765-
|notification|
1766-
</dd>
1767-
<dt>
1768-
{{PushEvent/appBadge}}
1769-
</dt>
1770-
<dd>
1771-
|declarativeResult|'s [=declarative push message parser result/app
1772-
badge=]
1773-
</dd>
1774-
</dl>
1775-
</li>
1776-
<li>
1777-
<p>
1778-
Wait for all of the promises in the [=ExtendableEvent/extend lifetime
1779-
promises=] of the dispatched event to resolve.
1757+
Let |result| be the result of [=fire a push event|firing a push event=]
1758+
given |registration|, null, a new {{Notification}} object representing
1759+
|notification|, and |declarativeResult|'s [=declarative push message
1760+
parser result/app badge=].
17801761
</p>
17811762
</li>
17821763
<li>
17831764
<p>
1784-
If a notification has been shown through
1785-
{{ServiceWorkerRegistration/showNotification()}} at this point, then
1786-
abort these steps.
1765+
If |result| is not failure, then set |notificationShown| to |result|'s
1766+
[=push event result/notification shown=] and |appBadgeSet| to [=push
1767+
event result/app badge set=].
17871768
</p>
17881769
</li>
17891770
</ol>
17901771
</li>
17911772
<li>
17921773
<p>
1793-
Run the [=notification show steps=] given |notification|.
1774+
If |notificationShown| is false, then run the [=notification show steps=]
1775+
given |notification|.
17941776
</p>
17951777
</li>
17961778
<li>
17971779
<p>
1798-
<a href="https://github.com/w3c/badging/issues/111">w3c/badging #111</a>
1780+
If |appBadgeSet| is false, then <a href=
1781+
"https://github.com/w3c/badging/issues/111">w3c/badging #111</a>...
17991782
</p>
18001783
</li>
18011784
<li>
18021785
<p>
1803-
Abort these steps.
1786+
[=acknowledge a push message|Acknowledge=] the <a>push message</a> and abort
1787+
these steps.
18041788
</p>
18051789
</li>
18061790
</ol>
18071791
</li>
18081792
</ol>
18091793
</li>
1794+
<li>
1795+
<p>
1796+
Let |result| be the result of [=fire a push event|firing a push event=] given
1797+
|registration|, a new {{PushMessageData}} instance whose [=PushMessageData/bytes=] is
1798+
|bytes|, null, and null.
1799+
</p>
1800+
</li>
1801+
<li>
1802+
<p>
1803+
If <var>result</var> is failure and the same <a>push message</a> has been delivered
1804+
to a <a>service worker registration</a> multiple times unsuccessfully, then
1805+
[=acknowledge a push message|acknowledge=] the <a>push message</a>.
1806+
</p>
1807+
</li>
1808+
<li>
1809+
<p>
1810+
If <var>result</var> is not failure, then [=acknowledge a push message|acknowledge=]
1811+
the <a>push message</a>.
1812+
</p>
1813+
</li>
1814+
</ol>
1815+
<p>
1816+
A <dfn>push event result</dfn> is a [=/tuple=] consisting of a <dfn for=
1817+
"push event result">notification shown</dfn> (a [=/boolean=]) and a <dfn for=
1818+
"push event result">app badge set</dfn> (a [=/boolean=]).
1819+
</p>
1820+
<p>
1821+
To <dfn>fire a push event</dfn> given a [=/service worker registration=] |registration|,
1822+
{{PushMessageData}} object or null |data|, a [=/notification=] or null |notification|,
1823+
and an integer or null |appBadge|, run these steps. They return failure or a [=/push
1824+
event result=].
1825+
</p>
1826+
<ol>
1827+
<li>
1828+
<p>
1829+
Let |notificationResult| be null.
1830+
</p>
1831+
</li>
1832+
<li>
1833+
<p>
1834+
Let |appBadgeResult| be null.
1835+
</p>
1836+
</li>
18101837
<li>
18111838
<p>
18121839
<a>Fire a functional event</a> named "`push`" using <a>PushEvent</a> on
@@ -1817,53 +1844,89 @@ <h2>
18171844
{{PushEvent//data}}
18181845
</dt>
18191846
<dd>
1820-
A new {{PushMessageData}} instance whose [=PushMessageData/bytes=] is |bytes|.
1847+
|data|
18211848
</dd>
18221849
<dt>
18231850
{{PushEvent/notification}}
18241851
</dt>
18251852
<dd>
1826-
null
1853+
|notification|
18271854
</dd>
18281855
<dt>
18291856
{{PushEvent/appBadge}}
18301857
</dt>
18311858
<dd>
1832-
null
1859+
|appBadge|
18331860
</dd>
18341861
</dl>
18351862
<p>
18361863
Then run the following steps in parallel, with |dispatchedEvent|:
18371864
</p>
18381865
<ol>
1839-
<li>Wait for all of the promises in the [=ExtendableEvent/extend lifetime promises=]
1840-
of |dispatchedEvent| to resolve.
1841-
</li>
1842-
<li>If all the promises resolve successfully, acknowledge the receipt of the <a>push
1843-
message</a> according to [[RFC8030]] and abort these steps.
1866+
<li>
1867+
<p>
1868+
Wait for all of the promises in the [=ExtendableEvent/extend lifetime promises=]
1869+
of |dispatchedEvent| to resolve.
1870+
</p>
18441871
</li>
18451872
<li>
18461873
<p>
1847-
If the same <a>push message</a> has been delivered to a <a>service worker
1848-
registration</a> multiple times unsuccessfully, acknowledge the receipt of the
1849-
<a>push message</a> according to [[RFC8030]].
1874+
If they do not resolve successfully, then set |notificationResult| and
1875+
|appBadgeResult| to failure and abort these steps.
18501876
</p>
1877+
</li>
1878+
<li>
18511879
<p>
1852-
Acknowledging the <a>push message</a> causes the <a>push service</a> to stop
1853-
delivering the message and to report success to the <a>application server</a>.
1854-
This prevents the same <a>push message</a> from being retried by the <a>push
1855-
service</a> indefinitely.
1880+
Set |notificationResult| to true if
1881+
{{ServiceWorkerRegistration/showNotification()}} has been invoked; otherwise
1882+
false.
18561883
</p>
1884+
</li>
1885+
<li>
18571886
<p>
1858-
Acknowledging also means that an <a>application server</a> could incorrectly
1859-
receive a delivery receipt indicating successful delivery of the <a>push
1860-
message</a>. Therefore, multiple rejections SHOULD be permitted before
1861-
acknowledging; allowing at least three attempts is recommended.
1887+
Set |appBadgeResult| to true if {{NavigatorBadge/setAppBadge()}} has been
1888+
invoked; otherwise false.
18621889
</p>
18631890
</li>
18641891
</ol>
18651892
</li>
1893+
<li>
1894+
<p>
1895+
Wait for |notificationResult| and |appBadgeResult| to be non-null.
1896+
</p>
1897+
</li>
1898+
<li>
1899+
<p>
1900+
If |notificationResult| is failure, then return failure.
1901+
</p>
1902+
</li>
1903+
<li>
1904+
<p>
1905+
[=/Assert=]: |notificationResult| and |appBadgeResult| are [=/booleans=].
1906+
</p>
1907+
</li>
1908+
<li>
1909+
<p>
1910+
Return (|notificationResult|, |appBadgeResult|).
1911+
</p>
1912+
</li>
18661913
</ol>
1914+
<p>
1915+
To <dfn>acknowledge a push message</dfn> given a <a>push message</a>
1916+
<var>pushMessage</var> means to acknowledge the receipt of <var>pushMessage</var>
1917+
according to [[RFC8030]].
1918+
</p>
1919+
<p>
1920+
Acknowledging the <a>push message</a> causes the <a>push service</a> to stop delivering
1921+
the message and to report success to the <a>application server</a>. This prevents the
1922+
same <a>push message</a> from being retried by the <a>push service</a> indefinitely.
1923+
</p>
1924+
<p>
1925+
Acknowledging also means that an <a>application server</a> could incorrectly receive a
1926+
delivery receipt indicating successful delivery of the <a>push message</a>. Therefore,
1927+
multiple rejections SHOULD be permitted before acknowledging; allowing at least three
1928+
attempts is recommended.
1929+
</p>
18671930
</section>
18681931
<section>
18691932
<h2>

0 commit comments

Comments
 (0)