Add check condition

This commit is contained in:
Nicola Benaglia 2025-06-05 21:42:33 +02:00
parent 1e078e1324
commit 5444bacdd0
3 changed files with 127 additions and 112 deletions

View File

@ -440,7 +440,7 @@ const handleNotificationDirect = async (directs) => {
let isFocused; let isFocused;
const wallet = await getSaveWallet(); const wallet = await getSaveWallet();
const address = wallet.address0; const address = wallet.address0;
let isDisableNotifications = const isDisableNotifications =
(await getUserSettings({ key: 'disable-push-notifications' })) || false; (await getUserSettings({ key: 'disable-push-notifications' })) || false;
const dataDirects = directs.filter((direct) => direct?.sender !== address); const dataDirects = directs.filter((direct) => direct?.sender !== address);
try { try {
@ -1734,7 +1734,7 @@ export async function decryptSingleFunc({
secretKeyObject, secretKeyObject,
skipDecodeBase64, skipDecodeBase64,
}) { }) {
let holdMessages = []; const holdMessages = [];
for (const message of messages) { for (const message of messages) {
try { try {
@ -1744,9 +1744,11 @@ export async function decryptSingleFunc({
skipDecodeBase64, skipDecodeBase64,
}); });
if (res) {
const decryptToUnit8Array = base64ToUint8Array(res); const decryptToUnit8Array = base64ToUint8Array(res);
const responseData = uint8ArrayToObject(decryptToUnit8Array); const responseData = uint8ArrayToObject(decryptToUnit8Array);
holdMessages.push({ ...message, decryptedData: responseData }); holdMessages.push({ ...message, decryptedData: responseData });
}
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
@ -1758,7 +1760,7 @@ export async function decryptSingleForPublishes({
secretKeyObject, secretKeyObject,
skipDecodeBase64, skipDecodeBase64,
}) { }) {
let holdMessages = []; const holdMessages = [];
for (const message of messages) { for (const message of messages) {
try { try {
@ -2888,6 +2890,7 @@ export async function getTimestampEnterChat() {
return {}; return {};
} }
} }
export async function getTimestampMention() { export async function getTimestampMention() {
const wallet = await getSaveWallet(); const wallet = await getSaveWallet();
const address = wallet.address0; const address = wallet.address0;
@ -2900,6 +2903,7 @@ export async function getTimestampMention() {
return {}; return {};
} }
} }
export async function getTimestampGroupAnnouncement() { export async function getTimestampGroupAnnouncement() {
const wallet = await getSaveWallet(); const wallet = await getSaveWallet();
const address = wallet.address0; const address = wallet.address0;
@ -2996,6 +3000,7 @@ async function getGroupData() {
return {}; return {};
} }
} }
export async function getGroupDataSingle(groupId) { export async function getGroupDataSingle(groupId) {
const wallet = await getSaveWallet(); const wallet = await getSaveWallet();
const address = wallet.address0; const address = wallet.address0;
@ -3266,6 +3271,7 @@ function setupMessageListener() {
break; break;
case 'updateThreadActivity': case 'updateThreadActivity':
updateThreadActivityCase(request, event); updateThreadActivityCase(request, event);
break;
case 'decryptGroupEncryption': case 'decryptGroupEncryption':
decryptGroupEncryptionCase(request, event); decryptGroupEncryptionCase(request, event);
break; break;
@ -3411,7 +3417,7 @@ export const checkNewMessages = async () => {
myName = userData.name; myName = userData.name;
} }
let newAnnouncements = []; const newAnnouncements = [];
const activeData = (await getStoredData('active-groups-directs')) || { const activeData = (await getStoredData('active-groups-directs')) || {
groups: [], groups: [],
directs: [], directs: [],
@ -3463,7 +3469,8 @@ export const checkNewMessages = async () => {
} }
}) })
); );
let isDisableNotifications =
const isDisableNotifications =
(await getUserSettings({ key: 'disable-push-notifications' })) || false; (await getUserSettings({ key: 'disable-push-notifications' })) || false;
if ( if (
@ -3611,8 +3618,8 @@ export const checkThreads = async (bringBack) => {
if (userData?.name) { if (userData?.name) {
myName = userData.name; myName = userData.name;
} }
let newAnnouncements = []; const newAnnouncements = [];
let dataToBringBack = []; const dataToBringBack = [];
const threadActivity = await getThreadActivity(); const threadActivity = await getThreadActivity();
if (!threadActivity) return null; if (!threadActivity) return null;
@ -3627,7 +3634,6 @@ export const checkThreads = async (bringBack) => {
for (const thread of selectedThreads) { for (const thread of selectedThreads) {
try { try {
const identifier = `thmsg-${thread?.threadId}`; const identifier = `thmsg-${thread?.threadId}`;
const name = thread?.qortalName;
const endpoint = await getArbitraryEndpoint(); const endpoint = await getArbitraryEndpoint();
const url = await createEndpoint( const url = await createEndpoint(
`${endpoint}?mode=ALL&service=DOCUMENT&identifier=${identifier}&limit=1&includemetadata=false&offset=${0}&reverse=true&prefix=true` `${endpoint}?mode=ALL&service=DOCUMENT&identifier=${identifier}&limit=1&includemetadata=false&offset=${0}&reverse=true&prefix=true`
@ -3643,7 +3649,6 @@ export const checkThreads = async (bringBack) => {
const latestMessage = responseData.filter( const latestMessage = responseData.filter(
(pub) => pub?.name !== myName (pub) => pub?.name !== myName
)[0]; )[0];
// const latestMessage = responseData[0]
if (!latestMessage) { if (!latestMessage) {
continue; continue;
@ -3717,7 +3722,7 @@ export const checkThreads = async (bringBack) => {
'_type=thread-post' + '_type=thread-post' +
`_data=${JSON.stringify(newAnnouncements[0])}` `_data=${JSON.stringify(newAnnouncements[0])}`
); );
let isDisableNotifications = const isDisableNotifications =
(await getUserSettings({ key: 'disable-push-notifications' })) || false; (await getUserSettings({ key: 'disable-push-notifications' })) || false;
if (!isDisableNotifications) { if (!isDisableNotifications) {
// Check user settings to see if notifications are disabled // Check user settings to see if notifications are disabled

View File

@ -276,15 +276,13 @@ export async function getNameInfo(address: string) {
} }
export const getGroupAdmins = async (groupNumber: number) => { export const getGroupAdmins = async (groupNumber: number) => {
// const validApi = await findUsableApi();
const response = await fetch( const response = await fetch(
`${getBaseApiReact()}/groups/members/${groupNumber}?limit=0&onlyAdmins=true` `${getBaseApiReact()}/groups/members/${groupNumber}?limit=0&onlyAdmins=true`
); );
const groupData = await response.json(); const groupData = await response.json();
let members: any = []; const members: any = [];
let membersAddresses = []; const membersAddresses = [];
let both = []; const both = [];
const getMemNames = groupData?.members?.map(async (member) => { const getMemNames = groupData?.members?.map(async (member) => {
if (member?.member) { if (member?.member) {
@ -601,9 +599,11 @@ export const Group = ({
const getGroupOwner = async (groupId) => { const getGroupOwner = async (groupId) => {
try { try {
if (groupId == 0) return;
const url = `${getBaseApiReact()}/groups/${groupId}`; const url = `${getBaseApiReact()}/groups/${groupId}`;
const response = await fetch(url); const response = await fetch(url);
let data = await response.json(); const data = await response.json();
const name = await getNameInfo(data?.owner); const name = await getNameInfo(data?.owner);
if (name) { if (name) {
@ -742,7 +742,7 @@ export const Group = ({
data = await res.text(); data = await res.text();
} }
const decryptedKey: any = await decryptResource(data); const decryptedKey: any = await decryptResource(data, null);
const dataint8Array = base64ToUint8Array(decryptedKey.data); const dataint8Array = base64ToUint8Array(decryptedKey.data);
const decryptedKeyToObject = uint8ArrayToObject(dataint8Array); const decryptedKeyToObject = uint8ArrayToObject(dataint8Array);
@ -877,6 +877,8 @@ export const Group = ({
}; };
const getOwnerNameForGroup = async (owner: string, groupId: string) => { const getOwnerNameForGroup = async (owner: string, groupId: string) => {
if (groupId == '0') return;
try { try {
if (!owner) return; if (!owner) return;
if (groupsOwnerNamesRef.current[groupId]) return; if (groupsOwnerNamesRef.current[groupId]) return;
@ -899,7 +901,7 @@ export const Group = ({
const url = `${getBaseApiReact()}/groups/member/${address}`; const url = `${getBaseApiReact()}/groups/member/${address}`;
const response = await fetch(url); const response = await fetch(url);
if (!response.ok) throw new Error('Cannot get group properties'); if (!response.ok) throw new Error('Cannot get group properties');
let data = await response.json(); const data = await response.json();
const transformToObject = data.reduce((result, item) => { const transformToObject = data.reduce((result, item) => {
result[item.groupId] = item; result[item.groupId] = item;
return result; return result;

View File

@ -303,6 +303,7 @@ export const decryptSingle = async ({
// First, decode the base64-encoded input (if skipDecodeBase64 is not set) // First, decode the base64-encoded input (if skipDecodeBase64 is not set)
const decodedData = skipDecodeBase64 ? data64 : atob(data64); const decodedData = skipDecodeBase64 ? data64 : atob(data64);
if (secretKeyObject) {
// Then, decode it again for the specific format (if double encoding is used) // Then, decode it again for the specific format (if double encoding is used)
const decodeForNumber = atob(decodedData); const decodeForNumber = atob(decodedData);
@ -390,7 +391,11 @@ export const decryptSingle = async ({
} }
// Decrypt the data using the nonce and messageKey // Decrypt the data using the nonce and messageKey
const decryptedData = nacl.secretbox.open(Uint8ArrayData, nonce, messageKey); const decryptedData = nacl.secretbox.open(
Uint8ArrayData,
nonce,
messageKey
);
// Check if decryption was successful // Check if decryption was successful
if (!decryptedData) { if (!decryptedData) {
@ -403,6 +408,9 @@ export const decryptSingle = async ({
// Convert the decrypted Uint8Array back to a Base64 string // Convert the decrypted Uint8Array back to a Base64 string
return uint8ArrayToBase64(decryptedData); return uint8ArrayToBase64(decryptedData);
}
return;
}; };
export const decryptGroupEncryptionWithSharingKey = async ({ export const decryptGroupEncryptionWithSharingKey = async ({