Skip to content

Commit

Permalink
Merge pull request oxen-io#2555 from Bilb/fix-invalid-date
Browse files Browse the repository at this point in the history
fix: INVALID_DATE (-Infinity) when merging two conversations inactive
  • Loading branch information
Bilb authored Oct 17, 2022
2 parents acd2178 + 12161a1 commit d1a33ad
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
// tslint:disable: use-simple-attributes no-submodule-imports

import { useDispatch } from 'react-redux';
Expand All @@ -7,6 +7,7 @@ import useKey from 'react-use/lib/useKey';
import styled from 'styled-components';
import { SessionIcon, SessionIconType } from '../../../icon';
import { ContactsListWithBreaks } from './ContactsListWithBreaks';
import { isEmpty, isString } from 'lodash';

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

export const OverlayChooseAction = () => {
const dispatch = useDispatch();

function closeOverlay() {
dispatch(resetOverlayMode());
}
Expand All @@ -64,6 +64,28 @@ export const OverlayChooseAction = () => {

useKey('Escape', closeOverlay);

function handlePaste(event: ClipboardEvent) {
event.preventDefault();

const pasted = event.clipboardData?.getData('text');

if (pasted && isString(pasted) && !isEmpty(pasted)) {
if (pasted.startsWith('http') || pasted.startsWith('https')) {
openJoinCommunity();
} else if (pasted.startsWith('05')) {
openNewMessage();
}
}
}

useEffect(() => {
document?.addEventListener('paste', handlePaste);

return () => {
document?.removeEventListener('paste', handlePaste);
};
}, []);

return (
<div className="module-left-pane-overlay">
<StyledActionRow
Expand Down
8 changes: 7 additions & 1 deletion ts/data/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,13 @@ async function removeAllClosedGroupEncryptionKeyPairs(groupPublicKey: string): P
// Conversation
async function saveConversation(data: ConversationAttributes): Promise<void> {
const cleaned = _cleanData(data);

/**
* Merging two conversations in `handleMessageRequestResponse` introduced a bug where we would mark conversation active_at to be -Infinity.
* 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.,
*/
if (cleaned.active_at === -Infinity) {
cleaned.active_at = Date.now();
}
await channels.saveConversation(cleaned);
}

Expand Down
7 changes: 6 additions & 1 deletion ts/receiver/contentMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,14 @@ async function handleMessageRequestResponse(
unblindedConvoId,
ConversationTypeEnum.PRIVATE
);
const mostRecentActiveAt =
let mostRecentActiveAt =
Math.max(...compact(convosToMerge.map(m => m.get('active_at')))) || Date.now();

if (!isFinite(mostRecentActiveAt)) {
mostRecentActiveAt = Date.now();
}


conversationToApprove.set({
active_at: mostRecentActiveAt,
isApproved: true,
Expand Down

0 comments on commit d1a33ad

Please sign in to comment.