chore: address PR reviews

pull/3281/head
Audric Ackermann 4 months ago
parent b129c409a7
commit 53cdcfbe35
No known key found for this signature in database

@ -47,7 +47,7 @@ export const StagedAttachmentList = (props: Props) => {
if (!conversationKey) {
return;
}
dispatch(removeAllStagedAttachmentsInConversation({ conversationKey }));
dispatch(removeAllStagedAttachmentsInConversation({ conversationId: conversationKey }));
};
const onRemoveByFilename = (filename: string) => {

@ -866,7 +866,7 @@ class CompositionBoxInner extends Component<Props, State> {
window.inboxStore?.dispatch(
removeAllStagedAttachmentsInConversation({
conversationKey: this.props.selectedConversationKey,
conversationId: this.props.selectedConversationKey,
})
);
// Empty composition box and stagedAttachments

@ -46,7 +46,7 @@ function useIsExpired(
dispatch(
messagesExpired([
{
conversationKey: convoId,
conversationId: convoId,
messageId,
},
])

@ -224,6 +224,10 @@ async function saveSeenMessageHashes(data: Array<SeenMessageHashes>): Promise<vo
await channels.saveSeenMessageHashes(cleanData(data));
}
async function clearLastHashesForConvoId(data: { convoId: string }): Promise<void> {
await channels.clearLastHashesForConvoId(cleanData(data));
}
async function updateLastHash(data: UpdateLastHashType): Promise<void> {
await channels.updateLastHash(cleanData(data));
}
@ -861,6 +865,7 @@ export const Data = {
searchMessagesInConversation,
cleanSeenMessages,
cleanLastHashes,
clearLastHashesForConvoId,
saveSeenMessageHashes,
updateLastHash,
saveMessage,

@ -38,6 +38,7 @@ const channelsToMake = new Set([
'cleanSeenMessages',
'cleanLastHashes',
'updateLastHash',
'clearLastHashesForConvoId',
'saveSeenMessageHashes',
'saveMessages',
'removeMessage',

@ -303,7 +303,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public getPriority() {
if (PubKey.is05Pubkey(this.id) && this.isPrivate()) {
// TODO once we have a libsession state, we can make this used accross the app without repeating as much
// TODO once we have a libsession state, we can make this used across the app without repeating as much
// if a private chat, trust the value from the Libsession wrapper cached first
const contact = SessionUtilContact.getContactCached(this.id);
if (contact) {
@ -1786,7 +1786,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
window.inboxStore?.dispatch(
conversationActions.messagesDeleted([
{
conversationKey: this.id,
conversationId: this.id,
messageId,
},
])
@ -1802,7 +1802,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public didApproveMe() {
if (PubKey.is05Pubkey(this.id) && this.isPrivate()) {
// if a private chat, trust the value from the Libsession wrapper cached first
// TODO once we have a libsession state, we can make this used accross the app without repeating as much
// TODO once we have a libsession state, we can make this used across the app without repeating as much
return SessionUtilContact.getContactCached(this.id)?.approvedMe ?? !!this.get('didApproveMe');
}
return !!this.get('didApproveMe');
@ -2861,7 +2861,7 @@ async function cleanUpExpireHistoryFromConvo(conversationId: string, isPrivate:
isPrivate
);
window?.inboxStore?.dispatch(
messagesDeleted(updateIdsRemoved.map(m => ({ conversationKey: conversationId, messageId: m })))
messagesDeleted(updateIdsRemoved.map(m => ({ conversationId, messageId: m })))
);
}

@ -973,6 +973,16 @@ function updateLastHash(data: UpdateLastHashType) {
});
}
function clearLastHashesForConvoId(data: { convoId: string }) {
const { convoId } = data;
if (!isString(convoId)) {
throw new Error('clearLastHashesForPubkey: convoId not a string');
}
assertGlobalInstance().prepare(`DELETE FROM ${LAST_HASHES_TABLE} WHERE pubkey=$convoId;`).run({
convoId,
});
}
function saveSeenMessageHash(data: any) {
const { expiresAt, hash } = data;
try {
@ -2645,6 +2655,7 @@ export const sqlNode = {
saveMessage,
cleanSeenMessages,
cleanLastHashes,
clearLastHashesForConvoId,
saveSeenMessageHashes,
saveSeenMessageHash,
updateLastHash,

@ -57,7 +57,6 @@ import {
} from './types';
import { ConversationTypeEnum } from '../../../models/types';
import { Snode } from '../../../data/types';
import { isDevProd } from '../../../shared/env_vars';
const minMsgCountShouldRetry = 95;
@ -292,12 +291,7 @@ export class SwarmPolling {
if (!window.getGlobalOnlineStatus()) {
window?.log?.error('SwarmPolling: pollForAllKeys: offline');
// Very important to set up a new polling call so we do retry at some point
timeouts.push(
setTimeout(
this.pollForAllKeys.bind(this),
isDevProd() ? SWARM_POLLING_TIMEOUT.ACTIVE_DEV : SWARM_POLLING_TIMEOUT.ACTIVE
)
);
timeouts.push(setTimeout(this.pollForAllKeys.bind(this), SWARM_POLLING_TIMEOUT.ACTIVE));
return;
}
@ -317,12 +311,7 @@ export class SwarmPolling {
window?.log?.warn('SwarmPolling: pollForAllKeys exception: ', e);
throw e;
} finally {
timeouts.push(
setTimeout(
this.pollForAllKeys.bind(this),
isDevProd() ? SWARM_POLLING_TIMEOUT.ACTIVE_DEV : SWARM_POLLING_TIMEOUT.ACTIVE
)
);
timeouts.push(setTimeout(this.pollForAllKeys.bind(this), SWARM_POLLING_TIMEOUT.ACTIVE));
}
}

@ -66,7 +66,7 @@ async function handleMetaMergeResults(groupPk: GroupPubkeyType) {
deletedMsgIds
);
window.inboxStore?.dispatch(
messagesExpired(deletedMsgIds.map(messageId => ({ conversationKey: groupPk, messageId })))
messagesExpired(deletedMsgIds.map(messageId => ({ conversationId: groupPk, messageId })))
);
ConvoHub.use().get(groupPk)?.updateLastMessage();
lastAppliedRemoveMsgSentBeforeSeconds.set(groupPk, infos.deleteBeforeSeconds);

@ -57,8 +57,6 @@ export const SWARM_POLLING_TIMEOUT = {
MEDIUM_ACTIVE: DURATION.SECONDS * 60,
/** 2 minutes */
INACTIVE: DURATION.SECONDS * 120,
/** 500 milliseconds */
ACTIVE_DEV: 500,
};
export const PROTOCOLS = {
@ -94,8 +92,6 @@ export const VALIDATION = {
export const DEFAULT_RECENT_REACTS = ['😂', '🥰', '😢', '😡', '😮', '😈'];
export const REACT_LIMIT = 6;
export const MAX_USERNAME_BYTES = 64;
export const UPDATER_INTERVAL_MS = 10 * DURATION.MINUTES;
export const FEATURE_RELEASE_TIMESTAMPS = {

@ -689,7 +689,7 @@ async function leaveClosedGroup(groupPk: PubkeyType | GroupPubkeyType, fromSyncM
method: 'sequence',
abortSignal: controller.signal,
}),
2 * DURATION.MINUTES,
30 * DURATION.SECONDS,
controller
);

@ -56,7 +56,11 @@ export async function destroyMessagesAndUpdateRedux(
window.log.error('destroyMessages: removeMessagesByIds failed', e && e.message ? e.message : e);
}
// trigger a redux update if needed for all those messages
window.inboxStore?.dispatch(messagesExpired(messages));
window.inboxStore?.dispatch(
messagesExpired(
messages.map(m => ({ conversationId: m.conversationKey, messageId: m.messageId }))
)
);
// trigger a refresh the last message for all those uniq conversation
conversationWithChanges.forEach(convoIdToUpdate => {

@ -79,13 +79,10 @@ export class GroupUpdateInfoChangeMessage extends GroupUpdateMessage {
switch (this.typeOfChange) {
case SignalService.GroupUpdateInfoChangeMessage.Type.NAME:
infoChangeMessage.updatedName = this.updatedName;
break;
case SignalService.GroupUpdateInfoChangeMessage.Type.DISAPPEARING_MESSAGES:
infoChangeMessage.updatedExpiration = this.updatedExpirationSeconds;
break;
case SignalService.GroupUpdateInfoChangeMessage.Type.AVATAR:
// nothing to do for the avatar case
break;

@ -32,7 +32,7 @@ type MembersPromotedMessageParams = GroupUpdateMessageParams & {
};
/**
* GroupUpdateInfoChangeMessage is sent to the group's swarm.
* GroupUpdateMemberChangeMessage is sent to the group's swarm.
*/
export class GroupUpdateMemberChangeMessage extends GroupUpdateMessage {
public readonly typeOfChange: 'added' | 'addedWithHistory' | 'removed' | 'promoted';

@ -553,7 +553,7 @@ async function sendToOpenGroupV2(
blinded: boolean,
filesToLink: Array<number>
): Promise<OpenGroupMessageV2 | boolean> {
// we agreed to pad message for opengroup v2
// we agreed to pad messages for opengroup v2
const paddedBody = addMessagePadding(rawMessage.plainTextBuffer());
const v2Message = new OpenGroupMessageV2({
sentTimestamp: NetworkTime.now(),
@ -660,7 +660,7 @@ async function handleBatchResultWithSubRequests({
hash: storedHash,
});
// We need to store the hash of our synced message when for a 1o1. (as this is the one stored on our swarm)
// We need to store the hash of our synced message for a 1o1. (as this is the one stored on our swarm)
// For groups, we can just store that hash directly as the group's swarm is hosting all of the group messages
if (subRequest.dbMessageIdentifier) {
// eslint-disable-next-line no-await-in-loop

@ -16,3 +16,7 @@ export type WithMaxSize = { max_size?: number };
export type WithShortenOrExtend = { shortenOrExtend: 'shorten' | 'extend' | '' };
export type WithCreatedAtNetworkTimestamp = { createdAtNetworkTimestamp: number };
export type WithMethod<T extends string> = { method: T };
export type WithConvoId = { conversationId: string };
export type WithMessageId = { messageId: string };

@ -1,7 +1,8 @@
import { GroupPubkeyType, PubkeyType } from 'libsession_util_nodejs';
import { debounce, difference, isNumber } from 'lodash';
import { v4 } from 'uuid';
import { ToastUtils, UserUtils } from '../..';
import AbortController from 'abort-controller';
import { MessageUtils, ToastUtils, UserUtils } from '../..';
import { groupInfoActions } from '../../../../state/ducks/metaGroups';
import {
MetaGroupWrapperActions,
@ -20,11 +21,12 @@ import {
import { LibSessionUtil } from '../../libsession/libsession_utils';
import { showUpdateGroupMembersByConvoId } from '../../../../interactions/conversationInteractions';
import { ConvoHub } from '../../../conversations';
import { MessageQueue } from '../../../sending';
import { MessageSender } from '../../../sending';
import { NetworkTime } from '../../../../util/NetworkTime';
import { SubaccountUnrevokeSubRequest } from '../../../apis/snode_api/SnodeRequestTypes';
import { GroupSync } from './GroupSyncJob';
import { DURATION } from '../../../constants';
import { timeoutWithAbort } from '../../Promise';
const defaultMsBetweenRetries = 10000;
const defaultMaxAttempts = 1;
@ -220,12 +222,24 @@ class GroupInviteJob extends PersistedJob<GroupInvitePersistedData> {
groupPk,
});
const storedAt = await MessageQueue.use().sendTo1o1NonDurably({
message: inviteDetails,
namespace: SnodeNamespaces.Default,
pubkey: PubKey.cast(member),
});
if (storedAt !== null) {
const controller = new AbortController();
const rawMessage = await MessageUtils.toRawMessage(
PubKey.cast(member),
inviteDetails,
SnodeNamespaces.Default
);
const { effectiveTimestamp } = await timeoutWithAbort(
MessageSender.sendSingleMessage({
message: rawMessage,
isSyncMessage: false,
}),
30 * DURATION.SECONDS,
controller
);
if (effectiveTimestamp !== null) {
failed = false;
}
} catch (e) {

@ -197,7 +197,7 @@ class GroupPendingRemovalsJob extends PersistedJob<GroupPendingRemovalsPersisted
method: 'sequence',
abortSignal: controller.signal,
}),
2 * DURATION.MINUTES,
30 * DURATION.SECONDS,
controller
);

@ -69,7 +69,8 @@ async function confirmPushedAndDump(
break;
}
case SnodeNamespaces.ClosedGroupKeys: {
// TODO chunk 2 closed group
// We don't need to confirm pushed keys, they are confirmed automatically
// when they are fetched from the group's swarm
break;
}
default:
@ -170,7 +171,7 @@ async function pushChangesToGroupSwarmIfNeeded({
method: 'sequence',
abortSignal: controller.signal,
}),
2 * DURATION.MINUTES,
30 * DURATION.SECONDS,
controller
);

@ -125,7 +125,7 @@ async function pushChangesToUserSwarmIfNeeded() {
method: 'sequence',
abortSignal: controller.signal,
}),
2 * DURATION.MINUTES,
30 * DURATION.SECONDS,
controller
);

@ -165,7 +165,7 @@ async function pendingChangesForUs(): Promise<UserDestinationChanges> {
results.messages.push({
ciphertext: data,
seqno: Long.fromNumber(seqno),
namespace, // we only use the namespace to know to wha
namespace,
});
hashes.forEach(h => results.allOldHashes.add(h)); // add all the hashes to the set
@ -187,8 +187,6 @@ async function pendingChangesForGroup(groupPk: GroupPubkeyType): Promise<GroupDe
// one of the wrapper behind the metagroup needs a push
const needsPush = await MetaGroupWrapperActions.needsPush(groupPk);
// we probably need to add the GROUP_KEYS check here
if (!needsPush) {
return { messages: [], allOldHashes: new Set() };
}

@ -190,11 +190,11 @@ async function refreshConvoVolatileCached(
if (OpenGroupUtils.isOpenGroupV2(convoId)) {
convoType = 'Community';
} else if (convoId.startsWith('05') && isLegacyGroup) {
} else if (PubKey.is05Pubkey(convoId) && isLegacyGroup) {
convoType = 'LegacyGroup';
} else if (PubKey.is03Pubkey(convoId)) {
convoType = 'Group';
} else if (convoId.startsWith('05')) {
} else if (PubKey.is05Pubkey(convoId)) {
convoType = '1o1';
}

@ -1,6 +1,6 @@
/**
* Returns a string with all spaces replaced to '-'.
* A datatestid cannot have spaces on desktop, so we use this to format them accross the app.
* A datatestid cannot have spaces on desktop, so we use this to format them across the app.
*
*/
export function strToDataTestId(input: string) {

@ -9,10 +9,6 @@ export function isDevProd() {
return envAppInstanceIncludes('devprod');
}
export function isAutoLogin() {
return !!process.env.SESSION_AUTO_REGISTER;
}
export function isTestNet() {
return envAppInstanceIncludes('testnet');
}

@ -32,6 +32,7 @@ import {
} from './types';
import { AttachmentType } from '../../types/Attachment';
import { CONVERSATION_PRIORITIES, ConversationTypeEnum } from '../../models/types';
import { WithConvoId, WithMessageHash, WithMessageId } from '../../session/types/with';
export type MessageModelPropsWithoutConvoProps = {
propsForMessage: PropsForMessageWithoutConvoProps;
@ -552,20 +553,13 @@ function handleMessagesChangedOrAdded(
function handleMessageExpiredOrDeleted(
state: ConversationsStateType,
payload: { conversationKey: string } & (
| {
messageId: string;
}
| {
messageHash: string;
}
)
payload: WithConvoId & (WithMessageId | WithMessageHash)
) {
const { conversationKey } = payload;
const { conversationId } = payload;
const messageId = (payload as any).messageId as string | undefined;
const messageHash = (payload as any).messageHash as string | undefined;
if (conversationKey === state.selectedConversation) {
if (conversationId === state.selectedConversation) {
// search if we find this message id.
// we might have not loaded yet, so this case might not happen
const messageInStoreIndex = state?.messages.findIndex(
@ -615,18 +609,7 @@ function handleMessageExpiredOrDeleted(
function handleMessagesExpiredOrDeleted(
state: ConversationsStateType,
action: PayloadAction<
Array<
{ conversationKey: string } & (
| {
messageId: string;
}
| {
messageHash: string;
}
)
>
>
action: PayloadAction<Array<WithConvoId & (WithMessageId | WithMessageHash)>>
): ConversationsStateType {
let stateCopy = state;
action.payload.forEach(element => {
@ -761,35 +744,20 @@ const conversationsSlice = createSlice({
messagesExpired(
state: ConversationsStateType,
action: PayloadAction<
Array<{
messageId: string;
conversationKey: string;
}>
>
action: PayloadAction<Array<WithConvoId & WithMessageId>>
) {
return handleMessagesExpiredOrDeleted(state, action);
},
messageHashesExpired(
state: ConversationsStateType,
action: PayloadAction<
Array<{
messageHash: string;
conversationKey: string;
}>
>
action: PayloadAction<Array<WithConvoId & WithMessageHash>>
) {
return handleMessagesExpiredOrDeleted(state, action);
},
messagesDeleted(
state: ConversationsStateType,
action: PayloadAction<
Array<{
messageId: string;
conversationKey: string;
}>
>
action: PayloadAction<Array<WithMessageId & WithConvoId>>
) {
return handleMessagesExpiredOrDeleted(state, action);
},

@ -84,7 +84,6 @@ type GroupDetailsUpdate = {
async function checkWeAreAdmin(groupPk: GroupPubkeyType) {
const us = UserUtils.getOurPubKeyStrFromCache();
const usInGroup = await MetaGroupWrapperActions.memberGet(groupPk, us);
const inUserGroup = await UserGroupsWrapperActions.getGroup(groupPk);
// if the secretKey is not empty AND we are a member of the group, we are a current admin
@ -1418,7 +1417,6 @@ export const groupInfoActions = {
currentDeviceGroupNameChange,
triggerFakeAvatarUpdate,
triggerFakeDeleteMsgBeforeNow,
...metaGroupSlice.actions,
};
export const groupReducer = metaGroupSlice.reducer;

@ -6,12 +6,12 @@ import { SessionConfirmDialogProps } from '../../components/dialog/SessionConfir
import { MediaItemType } from '../../components/lightbox/LightboxGallery';
import { AttachmentTypeWithPath } from '../../types/Attachment';
import type { EditProfilePictureModalProps, PasswordAction } from '../../types/ReduxTypes';
import { WithConvoId } from '../../session/types/with';
export type BanType = 'ban' | 'unban';
export type ConfirmModalState = SessionConfirmDialogProps | null;
type WithConvoId = { conversationId: string };
export type InviteContactModalState = WithConvoId | null;
export type BanOrUnbanUserModalState =
| (WithConvoId & {

@ -1,6 +1,7 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import _ from 'lodash';
import { StagedAttachmentType } from '../../components/conversation/composition/CompositionBox';
import { WithConvoId } from '../../session/types/with';
export type StagedAttachmentsStateType = {
stagedAttachments: { [conversationKey: string]: Array<StagedAttachmentType> };
@ -44,11 +45,11 @@ const stagedAttachmentsSlice = createSlice({
},
removeAllStagedAttachmentsInConversation(
state: StagedAttachmentsStateType,
action: PayloadAction<{ conversationKey: string }>
action: PayloadAction<WithConvoId>
) {
const { conversationKey } = action.payload;
const { conversationId } = action.payload;
const currentStagedAttachments = state.stagedAttachments[conversationKey];
const currentStagedAttachments = state.stagedAttachments[conversationId];
if (!currentStagedAttachments || _.isEmpty(currentStagedAttachments)) {
return state;
}
@ -61,7 +62,7 @@ const stagedAttachmentsSlice = createSlice({
}
});
delete state.stagedAttachments[conversationKey];
delete state.stagedAttachments[conversationId];
return state;
},
removeStagedAttachmentInConversation(

@ -141,7 +141,7 @@ describe('GroupSyncJob resultsToSuccessfulChange', () => {
).to.be.deep.eq([]);
expect(
LibSessionUtil.batchResultsToGroupSuccessfulChange([] as any as NotEmptyArrayOfBatchResults, {
LibSessionUtil.batchResultsToGroupSuccessfulChange([] as unknown as NotEmptyArrayOfBatchResults, {
allOldHashes: new Set(),
messages: [],
})

@ -104,10 +104,13 @@ describe('UserSyncJob batchResultsToUserSuccessfulChange', () => {
).to.be.deep.eq([]);
expect(
LibSessionUtil.batchResultsToUserSuccessfulChange([] as any as NotEmptyArrayOfBatchResults, {
allOldHashes: new Set(),
messages: [],
})
LibSessionUtil.batchResultsToUserSuccessfulChange(
[] as unknown as NotEmptyArrayOfBatchResults,
{
allOldHashes: new Set(),
messages: [],
}
)
).to.be.deep.eq([]);
});

Loading…
Cancel
Save