From 0f51ceeb88034049b2f0f981a77bd5b10cbe4749 Mon Sep 17 00:00:00 2001 From: f-r00t Date: Wed, 28 Feb 2024 12:13:51 +0100 Subject: [PATCH] Added message notification queue --- src/HuginUtilities.js | 34 +++++++++++++++++++++++----------- src/MainScreen.js | 23 ++++++++++++++++++++++- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/HuginUtilities.js b/src/HuginUtilities.js index d81e51b..d1a6d87 100644 --- a/src/HuginUtilities.js +++ b/src/HuginUtilities.js @@ -805,14 +805,16 @@ async function getGroupMessage(tx) { const groupname = await getGroupName(key); if (Globals.activeChat != key && !from_myself) { - PushNotification.localNotification({ - title: `${nickname} in ${groupname}`,//'Incoming transaction received!', + + Globals.notificationQueue.push({ + title: `${nickname} in ${groupname}`,//'Incoming transaction received!', //message: `You were sent ${prettyPrintAmount(transaction.totalAmount(), Config)}`, message: payload_json.m, data: tx.t, userInfo: group_object[0], - largeIconUrl: get_avatar(from, 64), + largeIconUrl: get_avatar(from, 64) }); + } return payload_json; @@ -996,7 +998,7 @@ export async function getMessage(extra, hash, navigation, fromBackground=false){ }) } else { // use URL to } - if (!from_myself) { + if (!from_myself && !missed) { console.log('Notifying call..') PushNotification.localNotification({ @@ -1007,6 +1009,16 @@ export async function getMessage(extra, hash, navigation, fromBackground=false){ largeIconUrl: get_avatar(payload_json.from, 64), }) + } else if(!from_myself && missed) { + Globals.notificationQueue.push({ + title: from, + //message: `You were sent ${prettyPrintAmount(transaction.totalAmount(), Config)}`, + message: 'Call missed', + data: payload_json.t, + userInfo: {nickname: from_payee.name, address: from_payee.address, paymentID: from_payee.paymentID}, + largeIconUrl: get_avatar(payload_json.from, 64), + }); + } payload_json.msg = 'Call received'; saveMessage(payload_json.from, received, 'Call received', payload_json.t); @@ -1028,13 +1040,13 @@ export async function getMessage(extra, hash, navigation, fromBackground=false){ saveMessage(payload_json.from, received, payload_json.msg, payload_json.t); if ((Globals.activeChat != payload_json.from && !from_myself) || (!from_myself && fromBackground)) { - PushNotification.localNotification({ - title: from, - message: payload_json.msg, - data: payload_json.t, - userInfo: from_payee, - largeIconUrl: get_avatar(payload_json.from, 64), - }); + Globals.notificationQueue.push({ + title: from, + message: payload_json.msg, + data: payload_json.t, + userInfo: from_payee, + largeIconUrl: get_avatar(payload_json.from, 64), + }); } resolve(payload_json); diff --git a/src/MainScreen.js b/src/MainScreen.js index 97e054f..5ba75f6 100644 --- a/src/MainScreen.js +++ b/src/MainScreen.js @@ -1115,7 +1115,26 @@ async function backgroundSyncMessages(navigation) { } } - console.log('Syncing complete!'); + console.log('Syncing complete!', Globals.notificationQueue); + if (Globals.notificationQueue.length > 2) { + + PushNotification.localNotification({ + title: "New messages received!", + message: `You've received ${Globals.notificationQueue.length} new messages.` + }); + + } else if (0 < Globals.notificationQueue.length && Globals.notificationQueue.length <= 2) { + for (n in Globals.notificationQueue) { + PushNotification.localNotification({ + title: Globals.notificationQueue[n].title, + message: Globals.notificationQueue[n].message, + data: Globals.notificationQueue[n].data, + userInfo: Globals.notificationQueue[n].userInfo, + largeIconUrl: Globals.notificationQueue[n].largeIconUrl, + }); + } + } + Globals.notificationQueue = []; Globals.syncingMessages = false; Globals.knownTXs = await getKnownTransactions(); @@ -1127,4 +1146,6 @@ async function backgroundSyncMessages(navigation) { Globals.syncingMessages = false; } + + }