Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify loops in GetMessages that handles encryption/decryption #533

Merged
merged 2 commits into from
Dec 16, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions src/app/backend-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1317,18 +1317,14 @@ export class BackendApiService {
map((res) => {
// This array contains encrypted messages with public keys
// Public keys of the other party involved in the correspondence
const encryptedMessages = [];
for (const threads of res.OrderedContactsWithMessages) {
for (const message of threads.Messages) {
const payload = {
EncryptedHex: message.EncryptedText,
PublicKey: message.IsSender ? message.RecipientPublicKeyBase58Check : message.SenderPublicKeyBase58Check,
IsSender: message.IsSender,
Legacy: !message.V2,
};
encryptedMessages.push(payload);
}
}
const encryptedMessages = res.OrderedContactsWithMessages.map((thread) =>
thread.messages.map((message) => ({
EncryptedHex: message.EncryptedText,
PublicKey: message.IsSender ? message.RecipientPublicKeyBase58Check : message.SenderPublicKeyBase58Check,
IsSender: message.IsSender,
Legacy: !message.V2,
}))
);
return { ...res, encryptedMessages };
})
);
Expand All @@ -1343,12 +1339,11 @@ export class BackendApiService {
})
.pipe(
map((decrypted) => {
for (const threads of res.OrderedContactsWithMessages) {
for (const message of threads.Messages) {
message.DecryptedText = decrypted.decryptedHexes[message.EncryptedText];
}
}

res.OrderedContactsWithMessages.forEach((threads) =>
threads.messages.forEach(
lazynina marked this conversation as resolved.
Show resolved Hide resolved
(message) => (message.DecryptedText = decrypted.decryptedHexes[message.EncryptedText])
)
);
return { ...res, ...decrypted };
})
);
Expand Down