Skip to content

Commit

Permalink
Backups: Handle groupV2 notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Apr 30, 2024
1 parent 4c4ab30 commit 5df8924
Show file tree
Hide file tree
Showing 27 changed files with 4,559 additions and 297 deletions.
38 changes: 25 additions & 13 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4159,15 +4159,15 @@
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--pending-add--many--other": {
"messageformat": "{memberName} invited {count, plural, one {#} other {#}} people to the group.",
"messageformat": "{memberName} invited {count, plural, one {# person} other {# people}} to the group.",
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--pending-add--many--you": {
"messageformat": "You invited {count, number} people to the group.",
"messageformat": "You invited {count, plural, one {# person} other {# people}} to the group.",
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--pending-add--many--unknown": {
"messageformat": "{count, plural, one {#} other {#}} people were invited to the group.",
"messageformat": "{count, plural, one {# person was} other {# people were}} invited to the group.",
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--pending-remove--decline--other": {
Expand Down Expand Up @@ -4207,15 +4207,15 @@
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--pending-remove--revoke--many--other": {
"messageformat": "{memberName} revoked invitations to the group for {count, number} people.",
"messageformat": "{memberName} revoked {count, plural, one {an invitation to the group for 1 person} other {invitations to the group for # people}}.",
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--pending-remove--revoke--many--you": {
"messageformat": "You revoked invitations to the group for {count, number} people.",
"messageformat": "You revoked {count, plural, one {an invitation to the group for 1 person} other {invitations to the group for # people}}.",
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--pending-remove--revoke--many--unknown": {
"messageformat": "An admin revoked invitations to the group for {count, number} people.",
"messageformat": "An admin revoked {count, plural, one {an invitation to the group for 1 person} other {invitations to the group for # people}}.",
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--pending-remove--revoke-invite-from--one--other": {
Expand Down Expand Up @@ -4243,27 +4243,27 @@
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--pending-remove--revoke-invite-from--many--other": {
"messageformat": "{adminName} revoked invitations to the group for {count, plural, one {# person} other {# people}} invited by {memberName}.",
"messageformat": "{adminName} revoked {count, plural, one {an invitation to the group for 1 person} other {invitations to the group for # people}} invited by {memberName}.",
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--pending-remove--revoke-invite-from--many--you": {
"messageformat": "You revoked invitations to the group for {count, number} people invited by {memberName}.",
"messageformat": "You revoked {count, plural, one {an invitation to the group for 1 person} other {invitations to the group for # people}} invited by {memberName}.",
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--pending-remove--revoke-invite-from--many--unknown": {
"messageformat": "An admin revoked invitations to the group for {count, number} people invited by {memberName}.",
"messageformat": "An admin revoked {count, plural, one {an invitation to the group for 1 person} other {invitations to the group for # people}} invited by {memberName}.",
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--pending-remove--revoke-invite-from-you--many--other": {
"messageformat": "{adminName} revoked the invitations to the group you sent to {count, number} people.",
"messageformat": "{adminName} revoked the {count, plural, one {invitation to the group you sent to 1 person} other {invitations to the group you sent to # people}}.",
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--pending-remove--revoke-invite-from-you--many--you": {
"messageformat": "You rescinded your invitation to {count, number} people.",
"messageformat": "You rescinded your invitation to {count, plural, one {# person} other {# people}}.",
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--pending-remove--revoke-invite-from-you--many--unknown": {
"messageformat": "An admin revoked the invitations to the group you sent to {count, number} people.",
"messageformat": "An admin revoked the {count, plural, one {invitation to the group you sent to 1 person} other {invitations to the group you sent to # people}}.",
"description": "Shown in timeline or conversation preview when v2 group changes"
},
"icu:GroupV2--admin-approval-add-one--you": {
Expand Down Expand Up @@ -4454,6 +4454,10 @@
"messageformat": "This member will need to accept an invite to join this group again, and will not receive group messages until they accept:",
"description": "Shown on Learn More popup after or Migration popup before GV1 migration"
},
"icu:GroupV1--Migration--info--invited--count": {
"messageformat": "{count, plural, one {# member} other {# members}} will need to accept an invite to join this group again, and will not receive group messages until they accept.",
"description": "Shown on Learn More popup after or Migration popup before GV1 migration"
},
"icu:GroupV1--Migration--info--removed--before--many": {
"messageformat": "These members are not capable of joining New Groups, and will be removed from the group:",
"description": "Shown on Learn More popup after or Migration popup before GV1 migration"
Expand All @@ -4462,6 +4466,10 @@
"messageformat": "This member is not capable of joining New Groups, and will be removed from the group:",
"description": "Shown on Learn More popup after or Migration popup before GV1 migration"
},
"icu:GroupV1--Migration--info--removed--before--count": {
"messageformat": "{count, plural, one {# member is} other {# members are}} not capable of joining New Groups, and will be removed from the group.",
"description": "Shown on Learn More popup after or Migration popup before GV1 migration"
},
"icu:GroupV1--Migration--info--removed--after--many": {
"messageformat": "These members were not capable of joining New Groups, and were removed from the group:",
"description": "Shown on Learn More popup after or Migration popup before GV1 migration"
Expand All @@ -4470,6 +4478,10 @@
"messageformat": "This member was not capable of joining New Groups, and was removed from the group:",
"description": "Shown on Learn More popup after or Migration popup before GV1 migration"
},
"icu:GroupV1--Migration--info--removed--after--count": {
"messageformat": "{count, plural, one {# member was not capable of joining New Groups, and was} other {# members were not capable of joining New Groups, and were}} removed from the group.",
"description": "Shown on Learn More popup after or Migration popup before GV1 migration"
},
"icu:GroupV1--Migration--invited--you": {
"messageformat": "You couldn't be added to the New Group and have been invited to join.",
"description": "Shown in timeline when a group is upgraded and you were invited instead of added"
Expand All @@ -4479,7 +4491,7 @@
"description": "Shown in timeline when a group is upgraded and one person was invited, instead of added"
},
"icu:GroupV1--Migration--invited--many": {
"messageformat": "{count, number} members couldn’t be added to the New Group and have been invited to join.",
"messageformat": "{count, plural, one {# member couldn’t be added to the New Group and has been invited to join} other {# members couldn’t be added to the New Group and have been invited to join}}.",
"description": "Shown in timeline when a group is upgraded and some people were invited, instead of added"
},
"icu:GroupV1--Migration--removed--one": {
Expand Down
2 changes: 1 addition & 1 deletion stylesheets/components/GroupDialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
border-radius: 8px;
margin-block: 0;
margin-inline: auto;
max-height: 100%;
max-height: 80vh;
max-width: 360px;
padding: 16px;
position: relative;
Expand Down
4 changes: 2 additions & 2 deletions ts/ConversationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export class ConversationController {
getOrCreate(
identifier: string | null,
type: ConversationAttributesTypeType,
additionalInitialProps = {}
additionalInitialProps: Partial<ConversationAttributesType> = {}
): ConversationModel {
if (typeof identifier !== 'string') {
throw new TypeError("'id' must be a string");
Expand Down Expand Up @@ -358,7 +358,7 @@ export class ConversationController {
async getOrCreateAndWait(
id: string | null,
type: ConversationAttributesTypeType,
additionalInitialProps = {}
additionalInitialProps: Partial<ConversationAttributesType> = {}
): Promise<ConversationModel> {
await this.load();
const conversation = this.getOrCreate(id, type, additionalInitialProps);
Expand Down
92 changes: 85 additions & 7 deletions ts/components/GroupV1MigrationDialog.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ const contact3: ConversationType = getDefaultConversation({

const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
areWeInvited: Boolean(overrideProps.areWeInvited),
droppedMembers: overrideProps.droppedMembers || [contact3, contact1],
droppedMembers: overrideProps.droppedMembers,
droppedMemberCount: overrideProps.droppedMemberCount || 0,
getPreferredBadge: () => undefined,
hasMigrated: Boolean(overrideProps.hasMigrated),
i18n,
invitedMembers: overrideProps.invitedMembers || [contact2],
invitedMembers: overrideProps.invitedMembers,
invitedMemberCount: overrideProps.invitedMemberCount || 0,
onMigrate: action('onMigrate'),
onClose: action('onClose'),
theme: ThemeType.light,
Expand Down Expand Up @@ -75,23 +77,41 @@ export function MigratedYouAreInvited(): JSX.Element {
);
}

export function NotYetMigratedMultipleDroppedAndInvitedMembers(): JSX.Element {
export function MigratedMultipleDroppedAndInvitedMember(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
hasMigrated: true,
droppedMembers: [contact1],
droppedMemberCount: 1,
invitedMembers: [contact2],
invitedMemberCount: 1,
})}
/>
);
}

export function MigratedMultipleDroppedAndInvitedMembers(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
hasMigrated: true,
droppedMembers: [contact3, contact1, contact2],
droppedMemberCount: 3,
invitedMembers: [contact2, contact3, contact1],
invitedMemberCount: 3,
})}
/>
);
}

export function NotYetMigratedNoMembers(): JSX.Element {
export function MigratedNoMembers(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
droppedMembers: [],
invitedMembers: [],
hasMigrated: true,
droppedMemberCount: 0,
invitedMemberCount: 0,
})}
/>
);
Expand All @@ -101,7 +121,65 @@ export function NotYetMigratedJustDroppedMember(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
invitedMembers: [],
droppedMembers: [contact1],
droppedMemberCount: 1,
})}
/>
);
}

export function NotYetMigratedJustDroppedMembers(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
droppedMembers: [contact1, contact2],
droppedMemberCount: 2,
})}
/>
);
}

export function NotYetMigratedDropped1(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
droppedMemberCount: 1,
invitedMemberCount: 0,
})}
/>
);
}

export function NotYetMigratedDropped2(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
droppedMemberCount: 2,
invitedMemberCount: 0,
})}
/>
);
}

export function MigratedJustCountIs1(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
hasMigrated: true,
droppedMemberCount: 1,
invitedMemberCount: 1,
})}
/>
);
}

export function MigratedJustCountIs2(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
hasMigrated: true,
droppedMemberCount: 2,
invitedMemberCount: 2,
})}
/>
);
Expand Down
51 changes: 43 additions & 8 deletions ts/components/GroupV1MigrationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import { missingCaseError } from '../util/missingCaseError';

export type DataPropsType = {
readonly areWeInvited: boolean;
readonly droppedMembers: Array<ConversationType>;
readonly droppedMembers?: Array<ConversationType>;
readonly droppedMemberCount: number;
readonly hasMigrated: boolean;
readonly invitedMembers: Array<ConversationType>;
readonly invitedMembers?: Array<ConversationType>;
readonly invitedMemberCount: number;
readonly getPreferredBadge: PreferredBadgeSelectorType;
readonly i18n: LocalizerType;
readonly theme: ThemeType;
Expand All @@ -30,10 +32,12 @@ export const GroupV1MigrationDialog: React.FunctionComponent<PropsType> =
React.memo(function GroupV1MigrationDialogInner({
areWeInvited,
droppedMembers,
droppedMemberCount,
getPreferredBadge,
hasMigrated,
i18n,
invitedMembers,
invitedMemberCount,
theme,
onClose,
onMigrate,
Expand Down Expand Up @@ -88,6 +92,7 @@ export const GroupV1MigrationDialog: React.FunctionComponent<PropsType> =
getPreferredBadge,
i18n,
members: invitedMembers,
count: invitedMemberCount,
hasMigrated,
kind: 'invited',
theme,
Expand All @@ -96,6 +101,7 @@ export const GroupV1MigrationDialog: React.FunctionComponent<PropsType> =
getPreferredBadge,
i18n,
members: droppedMembers,
count: droppedMemberCount,
hasMigrated,
kind: 'dropped',
theme,
Expand All @@ -110,21 +116,50 @@ function renderMembers({
getPreferredBadge,
i18n,
members,
count,
hasMigrated,
kind,
theme,
}: Readonly<{
getPreferredBadge: PreferredBadgeSelectorType;
i18n: LocalizerType;
members: Array<ConversationType>;
members?: Array<ConversationType>;
count: number;
hasMigrated: boolean;
kind: 'invited' | 'dropped';
theme: ThemeType;
}>): React.ReactNode {
if (!members.length) {
if (count === 0) {
return null;
}

if (!members) {
if (kind === 'invited') {
return (
<GroupDialog.Paragraph>
{i18n('icu:GroupV1--Migration--info--invited--count', { count })}
</GroupDialog.Paragraph>
);
}
if (hasMigrated) {
return (
<GroupDialog.Paragraph>
{i18n('icu:GroupV1--Migration--info--removed--after--count', {
count,
})}
</GroupDialog.Paragraph>
);
}

return (
<GroupDialog.Paragraph>
{i18n('icu:GroupV1--Migration--info--removed--before--count', {
count,
})}
</GroupDialog.Paragraph>
);
}

let text: string;
switch (kind) {
case 'invited':
Expand All @@ -137,13 +172,13 @@ function renderMembers({
if (hasMigrated) {
text =
members.length === 1
? i18n('icu:GroupV1--Migration--info--removed--before--one')
: i18n('icu:GroupV1--Migration--info--removed--before--many');
? i18n('icu:GroupV1--Migration--info--removed--after--one')
: i18n('icu:GroupV1--Migration--info--removed--after--many');
} else {
text =
members.length === 1
? i18n('icu:GroupV1--Migration--info--removed--after--one')
: i18n('icu:GroupV1--Migration--info--removed--after--many');
? i18n('icu:GroupV1--Migration--info--removed--before--one')
: i18n('icu:GroupV1--Migration--info--removed--before--many');
}
break;
default:
Expand Down

0 comments on commit 5df8924

Please sign in to comment.