Skip to content

Commit

Permalink
feat: 更新限时消息
Browse files Browse the repository at this point in the history
  • Loading branch information
Sioncovy committed May 26, 2024
1 parent 3c46e44 commit 645c34b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
29 changes: 28 additions & 1 deletion src/components/Chat/InputArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ChatMessageType, MessageSpecialType } from '@/typings'
import { createObjectURL } from '@/utils'
import {
AudioOutlined,
ClockCircleOutlined,
FileImageOutlined,
FileOutlined,
FireOutlined,
Expand Down Expand Up @@ -193,7 +194,33 @@ function InputArea({ userId, friendId }: InputAreaProps) {
/>
}
onClick={() => {
setSpecial(MessageSpecialType.BurnAfterReading)
setSpecial(
special === MessageSpecialType.BurnAfterReading
? MessageSpecialType.Normal
: MessageSpecialType.BurnAfterReading
)
}}
/>
</Tooltip>
<Tooltip title="限时消息:发送五秒后自动销毁">
<Button
type="text"
icon={
<ClockCircleOutlined
style={{
color:
special === MessageSpecialType.BurnAfterTime
? token.colorPrimary
: undefined
}}
/>
}
onClick={() => {
setSpecial(
special === MessageSpecialType.BurnAfterTime
? MessageSpecialType.Normal
: MessageSpecialType.BurnAfterTime
)
}}
/>
</Tooltip>
Expand Down
7 changes: 5 additions & 2 deletions src/components/Chat/Message/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ function Message({
if (special === MessageSpecialType.BurnAfterReading) {
if (read) {
const destroyTime = 5000 - (dayjs().valueOf() - updatedAt.valueOf())

console.log('✨ ~ useEffect ~ destroyTime:', destroyTime)
setTimeout(() => {
mailpenDatabase.messages.findOne({ selector: { _id } }).remove()
}, destroyTime)
}
} else if (special === MessageSpecialType.BurnAfterTime) {
const destroyTime = 5000 - (dayjs().valueOf() - createdAt.valueOf())
setTimeout(() => {
mailpenDatabase.messages.findOne({ selector: { _id } }).remove()
}, destroyTime)
}
}, [read])

Expand Down
11 changes: 11 additions & 0 deletions src/components/Sider/ChatSider/ChatItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ function ChatItem({ chat }: ChatItemProps) {
})
return '[阅后即焚]'
}
case MessageSpecialType.BurnAfterTime: {
if (content === '[限时消息]') return content
mailpenDatabase.chats.findOne({ selector: { _id: chat._id } }).update({
$set: {
message: {
...message,
content: '[限时消息]'
}
}
})
}
}
switch (Number(type)) {
case ChatMessageType.Text: {
Expand Down

0 comments on commit 645c34b

Please sign in to comment.