diff --git a/ts/components/conversation/SessionMessagesListContainer.tsx b/ts/components/conversation/SessionMessagesListContainer.tsx index 228358664..23a1cd605 100644 --- a/ts/components/conversation/SessionMessagesListContainer.tsx +++ b/ts/components/conversation/SessionMessagesListContainer.tsx @@ -3,10 +3,9 @@ import React from 'react'; import { SessionScrollButton } from '../SessionScrollButton'; import { contextMenu } from 'react-contexify'; -import { connect, useSelector } from 'react-redux'; +import { connect } from 'react-redux'; import { SessionMessagesList } from './SessionMessagesList'; -import styled from 'styled-components'; import autoBind from 'auto-bind'; import { ConversationTypeEnum } from '../../models/conversation'; import { getConversationController } from '../../session/conversations'; @@ -19,12 +18,10 @@ import { } from '../../state/ducks/conversations'; import { StateType } from '../../state/reducer'; import { - getFirstUnreadMessageId, getQuotedMessageToAnimate, getSelectedConversation, getSelectedConversationKey, getSortedMessagesOfSelectedConversation, - isFirstUnreadMessageIdAbove, } from '../../state/selectors/conversations'; import { TypingBubble } from './TypingBubble'; @@ -46,37 +43,12 @@ export const ScrollToLoadedMessageContext = React.createContext( (_loadedMessageIdToScrollTo: string, _reason: ScrollToLoadedReasons) => {} ); -const SessionUnreadAboveIndicator = styled.div` - position: sticky; - top: 0; - margin: 1em; - display: flex; - justify-content: center; - background: var(--color-sent-message-background); - color: var(--color-sent-message-text); -`; - -const UnreadAboveIndicator = () => { - const isFirstUnreadAbove = useSelector(isFirstUnreadMessageIdAbove); - const firstUnreadMessageId = useSelector(getFirstUnreadMessageId) as string; - - if (!isFirstUnreadAbove) { - return null; - } - return ( - - {window.i18n('latestUnreadIsAbove')} - - ); -}; - type Props = SessionMessageListProps & { conversationKey?: string; messagesProps: Array; conversation?: ReduxConversationType; animateQuotedMessageId: string | undefined; - firstUnreadOnOpen: string | undefined; scrollToNow: () => Promise; }; @@ -136,8 +108,6 @@ class SessionMessagesListContainerInner extends React.Component { ref={this.props.messageContainerRef} data-testid="messages-container" > - - { conversation: getSelectedConversation(state), messagesProps: getSortedMessagesOfSelectedConversation(state), animateQuotedMessageId: getQuotedMessageToAnimate(state), - firstUnreadOnOpen: getFirstUnreadMessageId(state), }; }; diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index fec679bc2..14cf58afd 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -890,35 +890,27 @@ export class ConversationModel extends Backbone.Model { messageAttributes: Omit< MessageAttributesOptionals, 'conversationId' | 'source' | 'type' | 'direction' | 'received_at' - >, - setToExpire = true + > ) { - return this.addSingleMessage( - { - ...messageAttributes, - conversationId: this.id, - source: UserUtils.getOurPubKeyStrFromCache(), - type: 'outgoing', - direction: 'outgoing', - received_at: messageAttributes.sent_at, // make sure to set an received_at timestamp for an outgoing message, so the order are right. - }, - setToExpire - ); + return this.addSingleMessage({ + ...messageAttributes, + conversationId: this.id, + source: UserUtils.getOurPubKeyStrFromCache(), + type: 'outgoing', + direction: 'outgoing', + received_at: messageAttributes.sent_at, // make sure to set an received_at timestamp for an outgoing message, so the order are right. + }); } public async addSingleIncomingMessage( - messageAttributes: Omit, - setToExpire = true + messageAttributes: Omit ) { - return this.addSingleMessage( - { - ...messageAttributes, - conversationId: this.id, - type: 'incoming', - direction: 'outgoing', - }, - setToExpire - ); + return this.addSingleMessage({ + ...messageAttributes, + conversationId: this.id, + type: 'incoming', + direction: 'outgoing', + }); } public async leaveClosedGroup() { @@ -1470,10 +1462,7 @@ export class ConversationModel extends Backbone.Model { } } - private async addSingleMessage( - messageAttributes: MessageAttributesOptionals, - setToExpire = true - ) { + private async addSingleMessage(messageAttributes: MessageAttributesOptionals) { const model = new MessageModel(messageAttributes); const isMe = messageAttributes.source === UserUtils.getOurPubKeyStrFromCache(); @@ -1490,9 +1479,8 @@ export class ConversationModel extends Backbone.Model { const messageId = await model.commit(false); model.set({ id: messageId }); - if (setToExpire) { - await model.setToExpire(); - } + await model.setToExpire(); + window.inboxStore?.dispatch( conversationActions.messagesAdded([ { diff --git a/ts/receiver/queuedJob.ts b/ts/receiver/queuedJob.ts index 970e592a2..e4e6bcd89 100644 --- a/ts/receiver/queuedJob.ts +++ b/ts/receiver/queuedJob.ts @@ -309,12 +309,6 @@ async function handleExpirationTimerUpdate( }); conversation.set({ expireTimer }); - window?.log?.info("Update conversation 'expireTimer'", { - id: conversation.idForLogging(), - expireTimer, - source: 'handleSwarmDataMessage', - }); - await conversation.updateExpireTimer(expireTimer, source, message.get('received_at')); } @@ -412,9 +406,7 @@ export async function handleMessageJob( conversation.throttledNotify(messageModel); } - if (confirm) { - confirm(); - } + confirm?.(); } catch (error) { const errorForLog = error && error.stack ? error.stack : error; window?.log?.error( diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index f310e2951..e0fc22a04 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -279,7 +279,23 @@ export type ConversationsStateType = { quotedMessage?: ReplyingToMessageProps; areMoreTopMessagesBeingFetched: boolean; areMoreBottomMessagesBeingFetched: boolean; + + /** + * oldTopMessageId should only be set when, as the user scroll up we trigger a load of more top messages. + * Saving it here, make it possible to restore the position of the user before the refresh by pointing + * at that same messageId and aligning the list to the top. + * + * Once the view scrolled, this value is reseted by resetOldTopMessageId + */ + oldTopMessageId: string | null; + /** + * oldBottomMessageId should only be set when, as the user scroll down we trigger a load of more bottom messages. + * Saving it here, make it possible to restore the position of the user before the refresh by pointing + * at that same messageId and aligning the list to the bottom. + * + * Once the view scrolled, this value is reseted by resetOldBottomMessageId + */ oldBottomMessageId: string | null; showScrollButton: boolean;