Skip to content

Commit d1a33ad

Browse files
authored
Merge pull request oxen-io#2555 from Bilb/fix-invalid-date
fix: INVALID_DATE (-Infinity) when merging two conversations inactive
2 parents acd2178 + 12161a1 commit d1a33ad

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

ts/components/leftpane/overlay/choose-action/OverlayChooseAction.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
// tslint:disable: use-simple-attributes no-submodule-imports
33

44
import { useDispatch } from 'react-redux';
@@ -7,6 +7,7 @@ import useKey from 'react-use/lib/useKey';
77
import styled from 'styled-components';
88
import { SessionIcon, SessionIconType } from '../../../icon';
99
import { ContactsListWithBreaks } from './ContactsListWithBreaks';
10+
import { isEmpty, isString } from 'lodash';
1011

1112
const StyledActionRow = styled.button`
1213
border: none;
@@ -45,7 +46,6 @@ const IconOnActionRow = (props: { iconType: SessionIconType }) => {
4546

4647
export const OverlayChooseAction = () => {
4748
const dispatch = useDispatch();
48-
4949
function closeOverlay() {
5050
dispatch(resetOverlayMode());
5151
}
@@ -64,6 +64,28 @@ export const OverlayChooseAction = () => {
6464

6565
useKey('Escape', closeOverlay);
6666

67+
function handlePaste(event: ClipboardEvent) {
68+
event.preventDefault();
69+
70+
const pasted = event.clipboardData?.getData('text');
71+
72+
if (pasted && isString(pasted) && !isEmpty(pasted)) {
73+
if (pasted.startsWith('http') || pasted.startsWith('https')) {
74+
openJoinCommunity();
75+
} else if (pasted.startsWith('05')) {
76+
openNewMessage();
77+
}
78+
}
79+
}
80+
81+
useEffect(() => {
82+
document?.addEventListener('paste', handlePaste);
83+
84+
return () => {
85+
document?.removeEventListener('paste', handlePaste);
86+
};
87+
}, []);
88+
6789
return (
6890
<div className="module-left-pane-overlay">
6991
<StyledActionRow

ts/data/data.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,13 @@ async function removeAllClosedGroupEncryptionKeyPairs(groupPublicKey: string): P
279279
// Conversation
280280
async function saveConversation(data: ConversationAttributes): Promise<void> {
281281
const cleaned = _cleanData(data);
282-
282+
/**
283+
* Merging two conversations in `handleMessageRequestResponse` introduced a bug where we would mark conversation active_at to be -Infinity.
284+
* The root issue has been fixed, but just to make sure those INVALID DATE does not show up, update those -Infinity active_at conversations to be now(), once.,
285+
*/
286+
if (cleaned.active_at === -Infinity) {
287+
cleaned.active_at = Date.now();
288+
}
283289
await channels.saveConversation(cleaned);
284290
}
285291

ts/receiver/contentMessage.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,14 @@ async function handleMessageRequestResponse(
626626
unblindedConvoId,
627627
ConversationTypeEnum.PRIVATE
628628
);
629-
const mostRecentActiveAt =
629+
let mostRecentActiveAt =
630630
Math.max(...compact(convosToMerge.map(m => m.get('active_at')))) || Date.now();
631631

632+
if (!isFinite(mostRecentActiveAt)) {
633+
mostRecentActiveAt = Date.now();
634+
}
635+
636+
632637
conversationToApprove.set({
633638
active_at: mostRecentActiveAt,
634639
isApproved: true,

0 commit comments

Comments
 (0)