2023-06-02 17:54:36 +00:00
|
|
|
// Copyright 2023 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import type { ConversationAttributesType } from '../model-types';
|
|
|
|
import { SignalService as Proto } from '../protobuf';
|
|
|
|
import { isGroupV2 } from './whatTypeOfConversation';
|
|
|
|
|
|
|
|
export function areWeAdmin(
|
|
|
|
attributes: Pick<
|
|
|
|
ConversationAttributesType,
|
|
|
|
'groupId' | 'groupVersion' | 'membersV2'
|
|
|
|
>
|
|
|
|
): boolean {
|
|
|
|
if (!isGroupV2(attributes)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const memberEnum = Proto.Member.Role;
|
|
|
|
const members = attributes.membersV2 || [];
|
2023-08-10 16:43:33 +00:00
|
|
|
const ourAci = window.textsecure.storage.user.getAci();
|
2023-08-16 20:54:39 +00:00
|
|
|
const me = members.find(item => item.aci === ourAci);
|
2023-06-02 17:54:36 +00:00
|
|
|
if (!me) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return me.role === memberEnum.ADMINISTRATOR;
|
|
|
|
}
|