2021-05-05 16:39:16 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-05-11 18:26:44 +00:00
|
|
|
import { ConversationModel } from '../models/conversations';
|
2021-06-07 16:39:13 +00:00
|
|
|
import { isMe } from './whatTypeOfConversation';
|
2021-05-05 16:39:16 +00:00
|
|
|
|
|
|
|
export async function shouldRespondWithProfileKey(
|
2021-05-11 18:26:44 +00:00
|
|
|
sender: ConversationModel
|
2021-05-05 16:39:16 +00:00
|
|
|
): Promise<boolean> {
|
2021-06-07 16:39:13 +00:00
|
|
|
if (isMe(sender.attributes) || !sender.getAccepted() || sender.isBlocked()) {
|
2021-05-05 16:39:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We do message check in an attempt to avoid a database lookup. If someone was EVER in
|
|
|
|
// a shared group with us, we should've shared our profile key with them in the past,
|
|
|
|
// so we should respond with a profile key now.
|
|
|
|
if (sender.get('sharedGroupNames')?.length) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
await sender.updateSharedGroups();
|
|
|
|
return Boolean(sender.get('sharedGroupNames')?.length);
|
|
|
|
}
|