-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show/hide "jump to last message" button on visibility of the last mes…
…sage; Mark all the conversation as read on the "jump to last message" button click; Reload the conversation on the "jump to last message" click if the latest conversation messages were not load;
- Loading branch information
Roma Koval
committed
May 10, 2024
1 parent
bb19977
commit caec31b
Showing
8 changed files
with
176 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/script/components/LastMessageTracker/LastMessageTracker.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
import {HTMLProps, useState, FC, useEffect} from 'react'; | ||
|
||
import ko from 'knockout'; | ||
|
||
import {ChevronIcon, IconButton} from '@wireapp/react-ui-kit'; | ||
|
||
import {Conversation as ConversationEntity} from '../../entity/Conversation'; | ||
import {Message} from '../../entity/message/Message'; | ||
|
||
export interface MessageVisibility { | ||
message: Message; | ||
isVisible: boolean; | ||
} | ||
|
||
export interface LastMessageTrackerProps extends HTMLProps<HTMLElement> { | ||
onGoToLastMessage: () => void; | ||
messageVisibility: ko.Observable<MessageVisibility>; | ||
conversation: ConversationEntity; | ||
} | ||
|
||
// conversation.last_event_timestamp doesn't contain system messages | ||
const lastMessageId = (conversation: ConversationEntity): string => { | ||
if (!conversation.hasLastReceivedMessageLoaded() || (conversation.messages()?.length || 0) === 0) { | ||
return ''; | ||
} | ||
return conversation.messages()[conversation.messages().length - 1].id; | ||
}; | ||
|
||
export const LastMessageTracker: FC<LastMessageTrackerProps> = ({ | ||
onGoToLastMessage, | ||
messageVisibility, | ||
conversation, | ||
...rest | ||
}: LastMessageTrackerProps) => { | ||
const [lastMessageShown, setLastMessageShown] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
const subscription = messageVisibility.subscribe(({message, isVisible}: MessageVisibility) => { | ||
if (!conversation.hasLastReceivedMessageLoaded()) { | ||
setLastMessageShown(false); | ||
} else if (message.id === lastMessageId(conversation)) { | ||
setLastMessageShown(isVisible); | ||
} | ||
}); | ||
|
||
return () => { | ||
subscription.dispose(); | ||
}; | ||
}, []); | ||
|
||
if (lastMessageShown) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<IconButton onClick={onGoToLastMessage} {...rest}> | ||
Check failure on line 75 in src/script/components/LastMessageTracker/LastMessageTracker.tsx
|
||
<ChevronIcon css={{rotate: '90deg', height: 16, width: 16, path: {fill: '#0667C8'}}} /> | ||
</IconButton> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
export * from './LastMessageTracker'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters