Merge pull request #2122 from Bilb/remove-dedupe-by-hash-sogs

Remove dedupe by hash sogs + update electron
pull/2129/head
Audric Ackermann 3 years ago committed by GitHub
commit 44c44ec174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,8 +13,6 @@ type Props = {
isConversationListItem?: boolean;
};
const UPDATE_FREQUENCY = 60 * 1000;
const TimestampContainerListItem = styled.div`
flex-shrink: 0;
margin-inline-start: 6px;
@ -28,6 +26,8 @@ const TimestampContainerListItem = styled.div`
color: var(--color-text);
`;
const UPDATE_FREQUENCY = 60 * 1000;
const TimestampContainerNotListItem = styled.div`
font-size: 11px;
line-height: 16px;

@ -19,7 +19,7 @@ import {
useIsPrivate,
} from '../../../hooks/useParamSelector';
import { MemoConversationListItemContextMenu } from '../../menu/ConversationListItemContextMenu';
import { HeaderItem } from './HeaderItem';
import { ConversationListItemHeaderItem } from './HeaderItem';
import { MessageItem } from './MessageItem';
// tslint:disable-next-line: no-empty-interface
@ -127,7 +127,7 @@ const ConversationListItem = (props: Props) => {
>
<AvatarItem />
<div className="module-conversation-list-item__content">
<HeaderItem />
<ConversationListItemHeaderItem />
<MessageItem isMessageRequest={Boolean(isMessageRequest)} />
</div>
</div>

@ -73,7 +73,7 @@ const ListItemIcons = () => {
);
};
export const HeaderItem = () => {
export const ConversationListItemHeaderItem = () => {
const conversationId = useContext(ContextConversationId);
const convoProps = useHeaderItemProps(conversationId);

@ -362,29 +362,28 @@ export async function isMessageDuplicate({
serverTimestamp,
}: MessageId) {
const { Errors } = window.Signal.Types;
// serverId is only used for opengroupv2
// serverTimestamp is only used for opengroupv2
try {
let result;
if (serverTimestamp) {
// first try to find a duplicate with the same serverTimestamp from this sender
if (serverTimestamp) {
result = await getMessageBySenderAndServerTimestamp({
source,
serverTimestamp,
});
}
// if we have a result, it means a specific user sent two messages either with the same serverTimestamp.
// no need to do anything else, those messages must be the same
// Note: this test is not based on which conversation the user sent the message
// but we consider that a user sending two messages with the same serverTimestamp is unlikely
return Boolean(result);
} else {
}
result = await getMessageBySender({
source,
sourceDevice,
sentAt: timestamp,
});
}
if (!result) {
return false;

@ -1,48 +0,0 @@
import _ from 'lodash';
import { SignalService } from '../protobuf';
import { sha256 } from '../session/crypto';
const recentHashByConvo = new Map<string, Array<string>>();
const maxHashToKeepPerConvo = 10;
export function isDuplicateBasedOnHash(
dataMessage: SignalService.DataMessage,
conversationId: string,
sender: string
): boolean {
const toUseForHash = {
..._.omit(
SignalService.DataMessage.toObject(dataMessage),
'timestamp',
'profile',
'preview',
'profileKey'
),
conversationId,
sender,
};
if (!recentHashByConvo.has(conversationId)) {
recentHashByConvo.set(conversationId, new Array());
}
const newHash = sha256(JSON.stringify(toUseForHash));
// this can only be set based on the .set above()
let recentHashForConvo = recentHashByConvo.get(conversationId) as Array<string>;
// this hash already exists for this convo
if (recentHashForConvo.some(n => n === newHash)) {
return true;
}
// push the new hash at the end
recentHashForConvo.push(newHash);
if (recentHashForConvo.length > maxHashToKeepPerConvo) {
// slice the last maxHashToKeepPerConvo hashes
recentHashForConvo = recentHashForConvo?.slice(-maxHashToKeepPerConvo);
}
recentHashByConvo.set(conversationId, recentHashForConvo);
return false;
}
// build a hash of the data and check against recent messages

@ -26,7 +26,6 @@ import { OpenGroupRequestCommonType } from '../session/apis/open_group_api/openg
import { handleMessageJob } from './queuedJob';
import { fromBase64ToArray } from '../session/utils/String';
import { removeMessagePadding } from '../session/crypto/BufferPadding';
import { isDuplicateBasedOnHash } from './hashDuplicateFilter';
import { createTaskWithTimeout } from '../session/utils/TaskWithTimeout';
import { perfEnd, perfStart } from '../session/utils/Performance';
@ -317,7 +316,7 @@ export async function handleOpenGroupV2Message(
source: sender,
message: dataMessage,
};
// WARNING this is very important that the isMessageDuplicate is made in the conversation.queueJob
// WARNING this is important that the isMessageDuplicate is made in the conversation.queueJob
const isDuplicate = await isMessageDuplicate(messageCreationData);
if (isDuplicate) {
@ -325,10 +324,6 @@ export async function handleOpenGroupV2Message(
return;
}
if (isDuplicateBasedOnHash(dataMessage, conversationId, sender)) {
window?.log?.info('Received duplicate message based on hash. Dropping it.');
return;
}
// this line just create an empty message with some basic stuff set.
// the whole decoding of data is happening in handleMessageJob()
const msg = createMessage(messageCreationData, !isMe);

Loading…
Cancel
Save