Skip to content

Commit

Permalink
chore: address PR reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilb committed Nov 25, 2024
1 parent 08605a0 commit 764aa35
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 52 deletions.
10 changes: 3 additions & 7 deletions ts/session/utils/job_runners/jobs/AvatarDownloadJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '../PersistedJob';

const defaultMsBetweenRetries = 10000;
const defaultMaxAttemps = 3;
const defaultMaxAttempts = 3;

/**
* Returns true if the provided conversationId is a private chat and that we should add an Avatar Download Job to the list of jobs to run.
Expand Down Expand Up @@ -74,19 +74,15 @@ class AvatarDownloadJob extends PersistedJob<AvatarDownloadPersistedData> {
Partial<
Pick<
AvatarDownloadPersistedData,
| 'nextAttemptTimestamp'
| 'identifier'
| 'maxAttempts'
| 'delayBetweenRetries'
| 'currentRetry'
'nextAttemptTimestamp' | 'identifier' | 'maxAttempts' | 'currentRetry'
>
>) {
super({
jobType: 'AvatarDownloadJobType',
identifier: identifier || v4(),
conversationId,
delayBetweenRetries: defaultMsBetweenRetries,
maxAttempts: isNumber(maxAttempts) ? maxAttempts : defaultMaxAttemps,
maxAttempts: isNumber(maxAttempts) ? maxAttempts : defaultMaxAttempts,
nextAttemptTimestamp: nextAttemptTimestamp || Date.now() + defaultMsBetweenRetries,
currentRetry: isNumber(currentRetry) ? currentRetry : 0,
});
Expand Down
13 changes: 5 additions & 8 deletions ts/session/utils/job_runners/jobs/GroupInviteJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { MessageQueue } from '../../../sending';
import { NetworkTime } from '../../../../util/NetworkTime';
import { SubaccountUnrevokeSubRequest } from '../../../apis/snode_api/SnodeRequestTypes';
import { GroupSync } from './GroupSyncJob';
import { DURATION } from '../../../constants';

const defaultMsBetweenRetries = 10000;
const defaultMaxAttempts = 1;
Expand All @@ -34,7 +35,7 @@ type JobExtraArgs = {
inviteAsAdmin: boolean;
/**
* When inviting a member, we usually only want to sent a message to his swarm.
* In the case of a invitation resend process though, we also want to make sure his token is unrevoked from the group's swarm.
* In the case of an invitation resend process though, we also want to make sure his token is unrevoked from the group's swarm.
*
*/
forceUnrevoke: boolean;
Expand Down Expand Up @@ -151,11 +152,7 @@ class GroupInviteJob extends PersistedJob<GroupInvitePersistedData> {
Partial<
Pick<
GroupInvitePersistedData,
| 'nextAttemptTimestamp'
| 'identifier'
| 'maxAttempts'
| 'delayBetweenRetries'
| 'currentRetry'
'nextAttemptTimestamp' | 'identifier' | 'maxAttempts' | 'currentRetry'
>
>) {
super({
Expand Down Expand Up @@ -298,7 +295,7 @@ class GroupInviteJob extends PersistedJob<GroupInvitePersistedData> {
}

public getJobTimeoutMs(): number {
return 15000;
return 15 * DURATION.SECONDS;
}
}

Expand All @@ -321,7 +318,7 @@ function updateFailedStateForMember(groupPk: GroupPubkeyType, member: PubkeyType
if (!thisGroupFailure) {
thisGroupFailure = {
failedMembers: [],
debouncedCall: debounce(displayFailedInvitesForGroup, 1000), // TODO change to 5000
debouncedCall: debounce(displayFailedInvitesForGroup, 5 * DURATION.SECONDS),
};
}

Expand Down
11 changes: 4 additions & 7 deletions ts/session/utils/job_runners/jobs/GroupPendingRemovalsJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
WithSecretKey,
} from '../../../types/with';
import { groupInfoActions } from '../../../../state/ducks/metaGroups';
import { DURATION } from '../../../constants';

const defaultMsBetweenRetries = 10000;
const defaultMaxAttempts = 1;
Expand Down Expand Up @@ -98,11 +99,7 @@ class GroupPendingRemovalsJob extends PersistedJob<GroupPendingRemovalsPersisted
Partial<
Pick<
GroupPendingRemovalsPersistedData,
| 'nextAttemptTimestamp'
| 'identifier'
| 'maxAttempts'
| 'delayBetweenRetries'
| 'currentRetry'
'nextAttemptTimestamp' | 'identifier' | 'maxAttempts' | 'currentRetry'
>
>) {
super({
Expand Down Expand Up @@ -135,7 +132,7 @@ class GroupPendingRemovalsJob extends PersistedJob<GroupPendingRemovalsPersisted
return RunJobResult.Success;
}
const deleteMessagesOfMembers = pendingRemovals
.filter(m => m.removedStatus === 'REMOVED_MEMBER_AND_MESSAGES')
.filter(m => m.memberStatus === 'REMOVED_MEMBER_AND_MESSAGES')

Check failure on line 135 in ts/session/utils/job_runners/jobs/GroupPendingRemovalsJob.ts

View workflow job for this annotation

GitHub Actions / build_windows

This comparison appears to be unintentional because the types 'MemberStateGroupV2' and '"REMOVED_MEMBER_AND_MESSAGES"' have no overlap.

Check failure on line 135 in ts/session/utils/job_runners/jobs/GroupPendingRemovalsJob.ts

View workflow job for this annotation

GitHub Actions / build_macos_x64

This comparison appears to be unintentional because the types 'MemberStateGroupV2' and '"REMOVED_MEMBER_AND_MESSAGES"' have no overlap.

Check failure on line 135 in ts/session/utils/job_runners/jobs/GroupPendingRemovalsJob.ts

View workflow job for this annotation

GitHub Actions / build_linux (deb)

This comparison appears to be unintentional because the types 'MemberStateGroupV2' and '"REMOVED_MEMBER_AND_MESSAGES"' have no overlap.
.map(m => m.pubkeyHex);

const sessionIdsHex = pendingRemovals.map(m => m.pubkeyHex);
Expand Down Expand Up @@ -274,7 +271,7 @@ class GroupPendingRemovalsJob extends PersistedJob<GroupPendingRemovalsPersisted
}

public getJobTimeoutMs(): number {
return 15000;
return 15 * DURATION.SECONDS;
}
}

Expand Down
9 changes: 3 additions & 6 deletions ts/session/utils/job_runners/jobs/GroupPromoteJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
RunJobResult,
} from '../PersistedJob';
import { MessageQueue } from '../../../sending';
import { DURATION } from '../../../constants';

const defaultMsBetweenRetries = 10000;
const defaultMaxAttempts = 1;
Expand Down Expand Up @@ -62,11 +63,7 @@ class GroupPromoteJob extends PersistedJob<GroupPromotePersistedData> {
Partial<
Pick<
GroupPromotePersistedData,
| 'nextAttemptTimestamp'
| 'identifier'
| 'maxAttempts'
| 'delayBetweenRetries'
| 'currentRetry'
'nextAttemptTimestamp' | 'identifier' | 'maxAttempts' | 'currentRetry'
>
>) {
super({
Expand Down Expand Up @@ -153,7 +150,7 @@ class GroupPromoteJob extends PersistedJob<GroupPromotePersistedData> {
}

public getJobTimeoutMs(): number {
return 15000;
return 15 * DURATION.SECONDS;
}
}

Expand Down
12 changes: 5 additions & 7 deletions ts/session/utils/job_runners/jobs/GroupSyncJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ async function pushChangesToGroupSwarmIfNeeded({
]);

const result = await MessageSender.sendEncryptedDataToSnode({
// Note: this is on purpose that supplementalKeysSubRequest is before pendingConfigRequests
// as this is to avoid a race condition where a device is polling right
// while we are posting the configs (already encrypted with the new keys)
// Note: this is on purpose that supplementalKeysSubRequest is before pendingConfigRequests.
// This is to avoid a race condition where a device is polling while we
// are posting the configs (already encrypted with the new keys)
sortedSubRequests,
destination: groupPk,
method: 'sequence',
Expand Down Expand Up @@ -198,7 +198,7 @@ async function pushChangesToGroupSwarmIfNeeded({

class GroupSyncJob extends PersistedJob<GroupSyncPersistedData> {
constructor({
identifier, // this has to be the pubkey to which we
identifier, // this has to be the group's pubkey
nextAttemptTimestamp,
maxAttempts,
currentRetry,
Expand Down Expand Up @@ -241,8 +241,6 @@ class GroupSyncJob extends PersistedJob<GroupSyncPersistedData> {
groupPk: thisJobDestination,
extraStoreRequests: [],
});

// eslint-disable-next-line no-useless-catch
} catch (e) {
window.log.warn('GroupSyncJob failed with', e.message);
return RunJobResult.RetryJobIfPossible;
Expand All @@ -251,7 +249,7 @@ class GroupSyncJob extends PersistedJob<GroupSyncPersistedData> {
`GroupSyncJob ${ed25519Str(thisJobDestination)} run() took ${Date.now() - start}ms`
);

// this is a simple way to make sure whatever happens here, we update the lastest timestamp.
// this is a simple way to make sure whatever happens here, we update the latest timestamp.
// (a finally statement is always executed (no matter if exception or returns in other try/catch block)
this.updateLastTickTimestamp();
}
Expand Down
2 changes: 1 addition & 1 deletion ts/session/utils/job_runners/jobs/UserSyncJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class UserSyncJob extends PersistedJob<UserSyncPersistedData> {
} finally {
window.log.debug(`UserSyncJob run() took ${Date.now() - start}ms`);

// this is a simple way to make sure whatever happens here, we update the lastest timestamp.
// this is a simple way to make sure whatever happens here, we update the latest timestamp.
// (a finally statement is always executed (no matter if exception or returns in other try/catch block)
this.updateLastTickTimestamp();
}
Expand Down
32 changes: 21 additions & 11 deletions ts/state/selectors/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ function getMemberPromotionNotSent(state: StateType, pubkey: PubkeyType, convo?:

function getMemberPendingRemoval(state: StateType, pubkey: PubkeyType, convo?: GroupPubkeyType) {
const members = getMembersOfGroup(state, convo);
const removedStatus = findMemberInMembers(members, pubkey)?.removedStatus;
return removedStatus !== 'NOT_REMOVED';
const removedStatus = findMemberInMembers(members, pubkey)?.memberStatus;
return (
removedStatus === 'REMOVED_UNKNOWN' ||

Check failure on line 113 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_windows

This comparison appears to be unintentional because the types 'MemberStateGroupV2 | undefined' and '"REMOVED_UNKNOWN"' have no overlap.

Check failure on line 113 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_macos_x64

This comparison appears to be unintentional because the types 'MemberStateGroupV2 | undefined' and '"REMOVED_UNKNOWN"' have no overlap.

Check failure on line 113 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_linux (deb)

This comparison appears to be unintentional because the types 'MemberStateGroupV2 | undefined' and '"REMOVED_UNKNOWN"' have no overlap.
removedStatus === 'REMOVED_MEMBER' ||

Check failure on line 114 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_windows

This comparison appears to be unintentional because the types 'MemberStateGroupV2 | undefined' and '"REMOVED_MEMBER"' have no overlap.

Check failure on line 114 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_macos_x64

This comparison appears to be unintentional because the types 'MemberStateGroupV2 | undefined' and '"REMOVED_MEMBER"' have no overlap.

Check failure on line 114 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_linux (deb)

This comparison appears to be unintentional because the types 'MemberStateGroupV2 | undefined' and '"REMOVED_MEMBER"' have no overlap.
removedStatus === 'REMOVED_MEMBER_AND_MESSAGES'

Check failure on line 115 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_windows

This comparison appears to be unintentional because the types 'MemberStateGroupV2 | undefined' and '"REMOVED_MEMBER_AND_MESSAGES"' have no overlap.

Check failure on line 115 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_macos_x64

This comparison appears to be unintentional because the types 'MemberStateGroupV2 | undefined' and '"REMOVED_MEMBER_AND_MESSAGES"' have no overlap.

Check failure on line 115 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_linux (deb)

This comparison appears to be unintentional because the types 'MemberStateGroupV2 | undefined' and '"REMOVED_MEMBER_AND_MESSAGES"' have no overlap.
);
}

export function getLibMembersCount(state: StateType, convo?: GroupPubkeyType): Array<string> {
Expand Down Expand Up @@ -317,32 +321,38 @@ export function useStateOf03GroupMembers(convoId?: string) {
switch (item.memberStatus) {
case 'INVITE_FAILED':
case 'INVITE_NOT_SENT':
stateSortingOrder = -5;
stateSortingOrder = -50;
break;
case 'INVITE_SENDING':
stateSortingOrder = -4;
stateSortingOrder = -40;
break;
case 'INVITE_SENT':
stateSortingOrder = -3;
stateSortingOrder = -30;
break;
case 'REMOVED_UNKNOWN': // fallback, hopefully won't happen in production

Check failure on line 332 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_windows

Type '"REMOVED_UNKNOWN"' is not comparable to type 'MemberStateGroupV2WithSending'.

Check failure on line 332 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_macos_x64

Type '"REMOVED_UNKNOWN"' is not comparable to type 'MemberStateGroupV2WithSending'.

Check failure on line 332 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_linux (deb)

Type '"REMOVED_UNKNOWN"' is not comparable to type 'MemberStateGroupV2WithSending'.
case 'REMOVED_MEMBER': // we want pending removal members at the end

Check failure on line 333 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_windows

Type '"REMOVED_MEMBER"' is not comparable to type 'MemberStateGroupV2WithSending'.

Check failure on line 333 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_macos_x64

Type '"REMOVED_MEMBER"' is not comparable to type 'MemberStateGroupV2WithSending'.

Check failure on line 333 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_linux (deb)

Type '"REMOVED_MEMBER"' is not comparable to type 'MemberStateGroupV2WithSending'.
case 'REMOVED_MEMBER_AND_MESSAGES':

Check failure on line 334 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_windows

Type '"REMOVED_MEMBER_AND_MESSAGES"' is not comparable to type 'MemberStateGroupV2WithSending'.

Check failure on line 334 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_macos_x64

Type '"REMOVED_MEMBER_AND_MESSAGES"' is not comparable to type 'MemberStateGroupV2WithSending'.

Check failure on line 334 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_linux (deb)

Type '"REMOVED_MEMBER_AND_MESSAGES"' is not comparable to type 'MemberStateGroupV2WithSending'.
stateSortingOrder = -20;
break;
case 'PROMOTION_FAILED':
case 'PROMOTION_NOT_SENT':
stateSortingOrder = -2;
stateSortingOrder = -15;
break;
case 'PROMOTION_SENDING':
stateSortingOrder = -1;
stateSortingOrder = -10;
break;
case 'PROMOTION_SENT':
stateSortingOrder = 0;
break;
case 'PROMOTION_ACCEPTED':
stateSortingOrder = 1;
stateSortingOrder = 10;
break;
case 'INVITE_ACCEPTED':
stateSortingOrder = 2;
stateSortingOrder = 20;
break;
case 'UNKNOWN':
stateSortingOrder = 5; // just a fallback, hopefully won't happen in production
case 'INVITE_UNKNOWN': // fallback, hopefully won't happen in production

Check failure on line 353 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_windows

Type '"INVITE_UNKNOWN"' is not comparable to type 'MemberStateGroupV2WithSending'.

Check failure on line 353 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_macos_x64

Type '"INVITE_UNKNOWN"' is not comparable to type 'MemberStateGroupV2WithSending'.

Check failure on line 353 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_linux (deb)

Type '"INVITE_UNKNOWN"' is not comparable to type 'MemberStateGroupV2WithSending'.
case 'PROMOTION_UNKNOWN': // fallback, hopefully won't happen in production

Check failure on line 354 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_windows

Type '"PROMOTION_UNKNOWN"' is not comparable to type 'MemberStateGroupV2WithSending'.

Check failure on line 354 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_macos_x64

Type '"PROMOTION_UNKNOWN"' is not comparable to type 'MemberStateGroupV2WithSending'.

Check failure on line 354 in ts/state/selectors/groups.ts

View workflow job for this annotation

GitHub Actions / build_linux (deb)

Type '"PROMOTION_UNKNOWN"' is not comparable to type 'MemberStateGroupV2WithSending'.
stateSortingOrder = 50;
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function emptyMember(pubkeyHex: PubkeyType): GroupMemberGet {
url: null,
},
nominatedAdmin: false,
removedStatus: 'NOT_REMOVED',
pubkeyHex,
};
}
Expand Down Expand Up @@ -299,8 +298,7 @@ describe('libsession_metagroup', () => {
expect(metaGroupWrapper.memberGetAll().length).to.be.deep.eq(1);
const expected: GroupMemberGet = {
...emptyMember(member),
removedStatus: 'REMOVED_MEMBER_AND_MESSAGES',
memberStatus: 'INVITE_ACCEPTED', // marking a member as pending removal auto-marks him as accepted (so we don't retry sending an invite)
memberStatus: 'REMOVED_MEMBER_AND_MESSAGES',
};
expect(metaGroupWrapper.memberGetAll().length).to.be.deep.eq(1);
expect(metaGroupWrapper.memberGetAll()[0]).to.be.deep.eq(expected);
Expand All @@ -312,8 +310,7 @@ describe('libsession_metagroup', () => {
expect(metaGroupWrapper.memberGetAll().length).to.be.deep.eq(1);
const expected: GroupMemberGet = {
...emptyMember(member),
removedStatus: 'REMOVED_MEMBER',
memberStatus: 'INVITE_ACCEPTED', // marking a member as pending removal auto-marks him as accepted (so we don't retry sending an invite)
memberStatus: 'REMOVED_MEMBER',
};
expect(metaGroupWrapper.memberGetAll()).to.be.deep.eq([expected]);
});
Expand Down

0 comments on commit 764aa35

Please sign in to comment.