git ssb

1+

Daan Patchwork / manyverse



Commit ad1e377078944cf49b55b1038229a07535ec049d

ux: fix notifications getting stuck (not clearing)

Andre Staltz committed on 9/6/2018, 10:19:40 AM
Parent: f5987dbc1b172941814d496fa224e3ba4e6bb05f

Files changed

package-lock.jsonchanged
package.jsonchanged
src/ssb/syncing-notifications.tschanged
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 950893 bytes
New file size: 951514 bytes
package.jsonView
@@ -50,8 +50,9 @@
5050 "pull-flat-list": "2.8.0",
5151 "pull-notify": "0.1.1",
5252 "pull-pushable": "2.1.1",
5353 "pull-stream": "3.6.9",
54+ "pull-thenable": "1.0.0",
5455 "quicktask": "1.1.0",
5556 "react": "16.4.1",
5657 "react-human-time": "^1.1.0",
5758 "react-markdown": "3.4.0",
@@ -105,5 +106,5 @@
105106 "react-native": {
106107 "os": "@staltz/react-native-os",
107108 "rn-viewpager": "@staltz/rn-viewpager"
108109 }
109-}
110+}
src/ssb/syncing-notifications.tsView
@@ -17,20 +17,20 @@
1717 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1818 */
1919
2020 import {Palette} from '../app/global-styles/palette';
21-const pull = require('pull-stream');
21+const Thenable = require('pull-thenable');
2222 const Notification = require('react-native-android-local-notification');
2323
24-const NOTIFICATION_ID = 175942; // only used in this module
24+const NOTIFICATION_ID = 1984; // magic number used only in this file
2525
2626 type Response = {
2727 started: number;
2828 prog: number;
2929 bytes: number;
3030 };
3131
32-function showNotification(data: Response) {
32+function showNotification(data: Response): Promise<void> {
3333 const progress = data.prog;
3434 const downloadedBytes = data.bytes;
3535 // tslint:disable-next-line:no-bitwise
3636 const downloadedKB = downloadedBytes >> 10;
@@ -42,9 +42,9 @@
4242 if (downloadedMB > 1024) message = `${downloadedGB} GB synced so far`;
4343 else if (downloadedKB > 1024) message = `${downloadedMB} MB synced so far`;
4444 else if (downloadedBytes > 1024) message = `${downloadedKB} KB synced so far`;
4545 else message = `${downloadedBytes} bytes synced so far`;
46- Notification.create({
46+ return Notification.create({
4747 id: NOTIFICATION_ID,
4848 subject: 'Syncing',
4949 message,
5050 localOnly: true,
@@ -60,23 +60,22 @@
6060 autoClear: true,
6161 });
6262 }
6363
64-function hideNotification() {
65- Notification.clear(NOTIFICATION_ID);
64+function hideNotification(): Promise<void> {
65+ return Notification.clear(NOTIFICATION_ID);
6666 }
6767
68-export function startSyncingNotifications(syncingStream: any) {
68+export async function startSyncingNotifications(syncingStream: any) {
6969 let showing = false;
70- pull(
71- syncingStream,
72- pull.drain((response: Response) => {
73- if (response.started > 0 && Date.now() - response.started > 3000) {
74- showNotification(response);
75- showing = true;
76- } else if (response.started === 0 && showing) {
77- hideNotification();
78- showing = false;
79- }
80- }),
81- );
70+ const nextSyncingResponse = Thenable(syncingStream);
71+ while (true) {
72+ const response = await nextSyncingResponse;
73+ if (response.started > 0 && Date.now() - response.started > 3000) {
74+ await showNotification(response);
75+ showing = true;
76+ } else if (response.started === 0 && showing) {
77+ await hideNotification();
78+ showing = false;
79+ }
80+ }
8281 }

Built with git-ssb-web