-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(messages): add embed type image & gallery
- Loading branch information
1 parent
82ce797
commit 01f4211
Showing
28 changed files
with
5,736 additions
and
4,140 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
68 changes: 68 additions & 0 deletions
68
src/ui/src/Apps/Calls/Messages/Conversation/ConversationImages.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,68 @@ | ||
import { ImageViewer } from '@/components/Gallery/ImageViewer'; | ||
import { clsx } from 'clsx'; | ||
import { AnimatePresence } from 'framer-motion'; | ||
import { useState } from 'react'; | ||
import { motion } from 'framer-motion'; | ||
|
||
interface ConversationImageProps { | ||
images: string[]; | ||
isReceiver: boolean; | ||
} | ||
export const ConversationImages = ({ images, isReceiver }: ConversationImageProps) => { | ||
const [selectedImageIndex, setSelectedImageIndex] = useState(-1); | ||
|
||
return ( | ||
<> | ||
<AnimatePresence> | ||
{selectedImageIndex !== -1 && ( | ||
<ImageViewer | ||
images={images} | ||
initialIndex={selectedImageIndex} | ||
onClose={() => { | ||
setSelectedImageIndex(-1); | ||
}} | ||
/> | ||
)} | ||
</AnimatePresence> | ||
|
||
<div className="flex flex-col gap-1 mt-2 w-full flex-1"> | ||
{images.length > 1 && ( | ||
<span | ||
className={clsx( | ||
'font-bold text-xs text-secondary', | ||
isReceiver ? 'text-left' : 'text-right', | ||
)} | ||
> | ||
{images.length} images | ||
</span> | ||
)} | ||
|
||
<div className="flex overflow-auto justify-start max-w-80 isolate border rounded-2xl"> | ||
{images.map((src, index) => ( | ||
<motion.div | ||
key={src} | ||
className={clsx( | ||
'h-40 rounded-xl flex-none object-cover cursor-pointer shadow-2xl drop-shadow-2xl', | ||
)} | ||
style={{ | ||
zIndex: -index, | ||
marginLeft: index !== 0 ? `-45px` : 0, | ||
}} | ||
onClick={() => setSelectedImageIndex(index)} | ||
animate={{ opacity: 1 }} | ||
> | ||
<img | ||
draggable={false} | ||
src={src} | ||
alt="Image" | ||
className={clsx( | ||
'h-40 rounded-xl flex-none object-cover cursor-pointer shadow-2xl drop-shadow-2xl', | ||
)} | ||
/> | ||
</motion.div> | ||
))} | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; |
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,59 @@ | ||
import { Fragment } from 'react'; | ||
import { Message as MessageType } from '../../../../../../shared/Types'; | ||
import { DateTime } from 'luxon'; | ||
import { StringifyDates } from '../../../../../../shared/TypeUtils'; | ||
import { clsx } from 'clsx'; | ||
import { ConversationImages } from './ConversationImages'; | ||
|
||
interface MessageProps { | ||
isReceiver: boolean; | ||
message: StringifyDates<MessageType>; | ||
previousMessage: StringifyDates<MessageType>; | ||
} | ||
export const Message = ({ isReceiver, message, previousMessage }: MessageProps) => { | ||
const timeDiffSincePrevMessage = previousMessage | ||
? new Date(message.created_at).getTime() - new Date(previousMessage?.created_at).getTime() | ||
: 0; | ||
|
||
const shouldDisplayDate = !previousMessage || timeDiffSincePrevMessage > 60 * 5 * 1000; | ||
const isPreviousMessageDifferentSender = previousMessage?.sender_id !== message.sender_id; | ||
const luxonDate = DateTime.fromISO(message.created_at); | ||
|
||
const images = (message.embed_type === 'image' && message.embed_content?.split(',')) || []; | ||
|
||
return ( | ||
<Fragment> | ||
{shouldDisplayDate && ( | ||
<div className="flex gap-1 m-auto text-xs my-4"> | ||
<span className="font-medium">Today</span> | ||
<span className="">{luxonDate?.toFormat('HH:mm')}</span> | ||
</div> | ||
)} | ||
|
||
{images.length > 0 && ( | ||
<div | ||
className={clsx('flex gap-1', { | ||
'self-end': !isReceiver, | ||
'self-start': isReceiver, | ||
})} | ||
> | ||
<ConversationImages images={images} isReceiver={isReceiver} /> | ||
</div> | ||
)} | ||
|
||
<li | ||
className={clsx( | ||
'p-4 rounded-lg max-w-[80%] shadow-sm text-ellipsis flex-1 break-words', | ||
{ | ||
'self-end': !isReceiver, | ||
'self-start': isReceiver, | ||
}, | ||
!isReceiver ? 'dark:bg-cyan-800 bg-cyan-100' : 'bg-secondary', | ||
!shouldDisplayDate && isPreviousMessageDifferentSender && 'mt-2', | ||
)} | ||
> | ||
{message.content} | ||
</li> | ||
</Fragment> | ||
); | ||
}; |
Oops, something went wrong.