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

Fix check to see if we have keys or not. #865

Merged
merged 1 commit into from
Feb 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion libtextsecure/sendmessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,19 @@ MessageSender.prototype = {

const ourNumber = textsecure.storage.user.getNumber();

// Check wether we have the keys to start a session with the user
const hasKeys = async number => {
try {
const [preKey, signedPreKey] = await Promise.all([
textsecure.storage.protocol.loadContactPreKey(number),
textsecure.storage.protocol.loadContactSignedPreKey(number),
]);
return preKey !== undefined && signedPreKey !== undefined;
} catch (e) {
return false;
}
};

// Note: Since we're just doing independant tasks,
// using `async` in the `forEach` loop should be fine.
// If however we want to use the results from forEach then
Expand All @@ -428,7 +441,7 @@ MessageSender.prototype = {
// If we don't have a session but we already have prekeys to
// start communication then we should use them
if (!haveSession && !options.isPublic) {
keysFound = await outgoing.getKeysForNumber(number, []);
keysFound = await hasKeys(number);
}

if (
Expand Down