Skip to content

Commit

Permalink
Added message notification queue
Browse files Browse the repository at this point in the history
  • Loading branch information
f-r00t committed Feb 28, 2024
1 parent 59398c5 commit 0f51cee
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
34 changes: 23 additions & 11 deletions src/HuginUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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({
Expand All @@ -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);
Expand All @@ -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);
Expand Down
23 changes: 22 additions & 1 deletion src/MainScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -1127,4 +1146,6 @@ async function backgroundSyncMessages(navigation) {
Globals.syncingMessages = false;
}



}

0 comments on commit 0f51cee

Please sign in to comment.