Compare commits
3 Commits
3a56415968
...
d60a11995e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d60a11995e | ||
|
|
68886573a8 | ||
|
|
fabd325976 |
@@ -77,6 +77,8 @@ export default function App() {
|
|||||||
|
|
||||||
const [currentChatId, setCurrentChatId] = React.useState('')
|
const [currentChatId, setCurrentChatId] = React.useState('')
|
||||||
|
|
||||||
|
const [sharedFavouriteChats, setSharedFavouriteChats] = React.useState<Chat[]>([])
|
||||||
|
|
||||||
useAsyncEffect(async () => {
|
useAsyncEffect(async () => {
|
||||||
const split = Split(['#SideBar', '#ChatFragment'], {
|
const split = Split(['#SideBar', '#ChatFragment'], {
|
||||||
sizes: data.split_sizes ? data.split_sizes : [25, 75],
|
sizes: data.split_sizes ? data.split_sizes : [25, 75],
|
||||||
@@ -176,6 +178,7 @@ export default function App() {
|
|||||||
chatInfoDialogRef={chatInfoDialogRef as any}
|
chatInfoDialogRef={chatInfoDialogRef as any}
|
||||||
openChatFragment={openChatFragment}
|
openChatFragment={openChatFragment}
|
||||||
openUserInfoDialog={openUserInfoDialog}
|
openUserInfoDialog={openUserInfoDialog}
|
||||||
|
sharedFavouriteChats={sharedFavouriteChats}
|
||||||
chat={chatInfo} />
|
chat={chatInfo} />
|
||||||
|
|
||||||
<MyProfileDialog
|
<MyProfileDialog
|
||||||
@@ -218,6 +221,7 @@ export default function App() {
|
|||||||
// 對話列表
|
// 對話列表
|
||||||
<ContactsList
|
<ContactsList
|
||||||
openChatInfoDialog={openChatInfoDialog}
|
openChatInfoDialog={openChatInfoDialog}
|
||||||
|
setSharedFavouriteChats={setSharedFavouriteChats}
|
||||||
addContactDialogRef={addContactDialogRef as any}
|
addContactDialogRef={addContactDialogRef as any}
|
||||||
createGroupDialogRef={createGroupDialogRef as any}
|
createGroupDialogRef={createGroupDialogRef as any}
|
||||||
display={navigationItemSelected == "Contacts"} />
|
display={navigationItemSelected == "Contacts"} />
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ export default function AppMobile() {
|
|||||||
|
|
||||||
const [currentChatId, setCurrentChatId] = React.useState('')
|
const [currentChatId, setCurrentChatId] = React.useState('')
|
||||||
|
|
||||||
|
const [sharedFavouriteChats, setSharedFavouriteChats] = React.useState<Chat[]>([])
|
||||||
|
|
||||||
const chatFragmentDialogRef = React.useRef<Dialog>(null)
|
const chatFragmentDialogRef = React.useRef<Dialog>(null)
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const shadow = chatFragmentDialogRef.current!.shadowRoot as ShadowRoot
|
const shadow = chatFragmentDialogRef.current!.shadowRoot as ShadowRoot
|
||||||
@@ -162,6 +164,7 @@ export default function AppMobile() {
|
|||||||
<ChatInfoDialog
|
<ChatInfoDialog
|
||||||
chatInfoDialogRef={chatInfoDialogRef as any}
|
chatInfoDialogRef={chatInfoDialogRef as any}
|
||||||
openUserInfoDialog={openUserInfoDialog}
|
openUserInfoDialog={openUserInfoDialog}
|
||||||
|
sharedFavouriteChats={sharedFavouriteChats}
|
||||||
openChatFragment={(id) => {
|
openChatFragment={(id) => {
|
||||||
setCurrentChatId(id)
|
setCurrentChatId(id)
|
||||||
setIsShowChatFragment(true)
|
setIsShowChatFragment(true)
|
||||||
@@ -226,6 +229,7 @@ export default function AppMobile() {
|
|||||||
// 對話列表
|
// 對話列表
|
||||||
<ContactsList
|
<ContactsList
|
||||||
openChatInfoDialog={openChatInfoDialog}
|
openChatInfoDialog={openChatInfoDialog}
|
||||||
|
setSharedFavouriteChats={setSharedFavouriteChats}
|
||||||
addContactDialogRef={addContactDialogRef as any}
|
addContactDialogRef={addContactDialogRef as any}
|
||||||
createGroupDialogRef={createGroupDialogRef as any}
|
createGroupDialogRef={createGroupDialogRef as any}
|
||||||
display={navigationItemSelected == "Contacts"} />
|
display={navigationItemSelected == "Contacts"} />
|
||||||
|
|||||||
@@ -8,17 +8,20 @@ import Avatar from "../Avatar.tsx"
|
|||||||
import { checkApiSuccessOrSncakbar } from "../snackbar.ts"
|
import { checkApiSuccessOrSncakbar } from "../snackbar.ts"
|
||||||
import User from "../../api/client_data/User.ts"
|
import User from "../../api/client_data/User.ts"
|
||||||
import getUrlForFileByHash from "../../getUrlForFileByHash.ts"
|
import getUrlForFileByHash from "../../getUrlForFileByHash.ts"
|
||||||
|
import openImageViewer from "../openImageViewer.ts"
|
||||||
|
import EventBus from "../../EventBus.ts"
|
||||||
|
|
||||||
interface Args extends React.HTMLAttributes<HTMLElement> {
|
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||||
chat: Chat
|
chat: Chat
|
||||||
openChatFragment: (id: string) => void
|
openChatFragment: (id: string) => void
|
||||||
chatInfoDialogRef: React.MutableRefObject<Dialog>
|
chatInfoDialogRef: React.MutableRefObject<Dialog>
|
||||||
openUserInfoDialog: (user: User | string) => void
|
openUserInfoDialog: (user: User | string) => void
|
||||||
|
sharedFavouriteChats: Chat[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragment, openUserInfoDialog }: Args) {
|
export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragment, openUserInfoDialog, sharedFavouriteChats }: Args) {
|
||||||
const [chatInfo, setChatInfo] = React.useState(null as unknown as Chat)
|
const [chatInfo, setChatInfo] = React.useState(null as unknown as Chat)
|
||||||
const isMySelf = Client.myUserProfile?.id == chatInfo?.user_a_id && Client.myUserProfile?.id == chatInfo?.user_b_id
|
const [favourited, setIsFavourited] = React.useState(false)
|
||||||
|
|
||||||
useAsyncEffect(async () => {
|
useAsyncEffect(async () => {
|
||||||
if (chat == null) return
|
if (chat == null) return
|
||||||
@@ -28,8 +31,12 @@ export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragme
|
|||||||
})
|
})
|
||||||
if (re.code != 200)
|
if (re.code != 200)
|
||||||
return checkApiSuccessOrSncakbar(re, '获取对话信息失败')
|
return checkApiSuccessOrSncakbar(re, '获取对话信息失败')
|
||||||
setChatInfo(re.data!.chat_info as Chat)
|
|
||||||
})
|
const info = re.data as Chat
|
||||||
|
setChatInfo(info)
|
||||||
|
setIsFavourited(sharedFavouriteChats.indexOf(info) != -1)
|
||||||
|
}, [chat, sharedFavouriteChats])
|
||||||
|
const avatarUrl = getUrlForFileByHash(chat?.avatar_file_hash as string)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<mdui-dialog close-on-overlay-click close-on-esc ref={chatInfoDialogRef}>
|
<mdui-dialog close-on-overlay-click close-on-esc ref={chatInfoDialogRef}>
|
||||||
@@ -37,10 +44,10 @@ export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragme
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
}}>
|
}}>
|
||||||
<Avatar src={getUrlForFileByHash(chat?.avatar_file_hash as string)} text={chat?.nickname as string} style={{
|
<Avatar src={avatarUrl} text={chat?.nickname as string} style={{
|
||||||
width: '50px',
|
width: '50px',
|
||||||
height: '50px',
|
height: '50px',
|
||||||
}} />
|
}} onClick={() => avatarUrl && openImageViewer(avatarUrl)} />
|
||||||
<span style={{
|
<span style={{
|
||||||
marginLeft: "15px",
|
marginLeft: "15px",
|
||||||
fontSize: '16.5px',
|
fontSize: '16.5px',
|
||||||
@@ -64,6 +71,17 @@ export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragme
|
|||||||
openUserInfoDialog(re.data!.user_id as string)
|
openUserInfoDialog(re.data!.user_id as string)
|
||||||
}}>用户详情</mdui-list-item>
|
}}>用户详情</mdui-list-item>
|
||||||
}
|
}
|
||||||
|
<mdui-list-item icon={favourited ? "favorite_border" : "favorite"} rounded onClick={async () => {
|
||||||
|
const re = await Client.invoke(favourited ? "User.removeContacts" : "User.addContacts", {
|
||||||
|
token: data.access_token,
|
||||||
|
targets: [
|
||||||
|
chat.id
|
||||||
|
],
|
||||||
|
})
|
||||||
|
if (re.code != 200)
|
||||||
|
checkApiSuccessOrSncakbar(re, favourited ? "取消收藏失败" : "收藏失败")
|
||||||
|
EventBus.emit('ContactsList.updateContacts')
|
||||||
|
}}>{favourited ? '取消收藏' : '收藏对话'}</mdui-list-item>
|
||||||
<mdui-list-item icon="chat" rounded onClick={() => {
|
<mdui-list-item icon="chat" rounded onClick={() => {
|
||||||
chatInfoDialogRef.current!.open = false
|
chatInfoDialogRef.current!.open = false
|
||||||
openChatFragment(chat.id)
|
openChatFragment(chat.id)
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import data from "../../Data.ts"
|
|||||||
import Avatar from "../Avatar.tsx"
|
import Avatar from "../Avatar.tsx"
|
||||||
import User from "../../api/client_data/User.ts"
|
import User from "../../api/client_data/User.ts"
|
||||||
import getUrlForFileByHash from "../../getUrlForFileByHash.ts"
|
import getUrlForFileByHash from "../../getUrlForFileByHash.ts"
|
||||||
|
import openImageViewer from "../openImageViewer.ts"
|
||||||
|
import Chat from "../../api/client_data/Chat.ts"
|
||||||
|
|
||||||
interface Refs {
|
interface Refs {
|
||||||
userProfileDialogRef: React.MutableRefObject<Dialog>
|
userProfileDialogRef: React.MutableRefObject<Dialog>
|
||||||
@@ -21,16 +23,17 @@ export default function UserProfileDialog({
|
|||||||
openChatFragment,
|
openChatFragment,
|
||||||
user
|
user
|
||||||
}: Refs) {
|
}: Refs) {
|
||||||
|
const avatarUrl = getUrlForFileByHash(user?.avatar_file_hash)
|
||||||
return (
|
return (
|
||||||
<mdui-dialog close-on-overlay-click close-on-esc ref={userProfileDialogRef}>
|
<mdui-dialog close-on-overlay-click close-on-esc ref={userProfileDialogRef}>
|
||||||
<div style={{
|
<div style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
}}>
|
}}>
|
||||||
<Avatar src={getUrlForFileByHash(user?.avatar_file_hash)} text={user?.nickname} style={{
|
<Avatar src={avatarUrl} text={user?.nickname} style={{
|
||||||
width: '50px',
|
width: '50px',
|
||||||
height: '50px',
|
height: '50px',
|
||||||
}} />
|
}} onClick={() => avatarUrl && openImageViewer(avatarUrl)} />
|
||||||
<span style={{
|
<span style={{
|
||||||
marginLeft: "15px",
|
marginLeft: "15px",
|
||||||
fontSize: '16.5px',
|
fontSize: '16.5px',
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ interface Args extends React.HTMLAttributes<HTMLElement> {
|
|||||||
openChatInfoDialog: (chat: Chat) => void
|
openChatInfoDialog: (chat: Chat) => void
|
||||||
addContactDialogRef: React.MutableRefObject<Dialog>
|
addContactDialogRef: React.MutableRefObject<Dialog>
|
||||||
createGroupDialogRef: React.MutableRefObject<Dialog>
|
createGroupDialogRef: React.MutableRefObject<Dialog>
|
||||||
|
setSharedFavouriteChats: React.Dispatch<React.SetStateAction<Chat[]>>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ContactsList({
|
export default function ContactsList({
|
||||||
@@ -20,6 +21,7 @@ export default function ContactsList({
|
|||||||
openChatInfoDialog,
|
openChatInfoDialog,
|
||||||
addContactDialogRef,
|
addContactDialogRef,
|
||||||
createGroupDialogRef,
|
createGroupDialogRef,
|
||||||
|
setSharedFavouriteChats,
|
||||||
...props
|
...props
|
||||||
}: Args) {
|
}: Args) {
|
||||||
const searchRef = React.useRef<HTMLElement>(null)
|
const searchRef = React.useRef<HTMLElement>(null)
|
||||||
@@ -40,7 +42,9 @@ export default function ContactsList({
|
|||||||
if (re.code != 200)
|
if (re.code != 200)
|
||||||
return checkApiSuccessOrSncakbar(re, "获取所有对话列表失败")
|
return checkApiSuccessOrSncakbar(re, "获取所有对话列表失败")
|
||||||
|
|
||||||
setContactsList(re.data!.contacts_list as Chat[])
|
const ls = re.data!.contacts_list as Chat[]
|
||||||
|
setContactsList(ls)
|
||||||
|
setSharedFavouriteChats(ls)
|
||||||
}
|
}
|
||||||
updateContacts()
|
updateContacts()
|
||||||
EventBus.on('ContactsList.updateContacts', () => updateContacts())
|
EventBus.on('ContactsList.updateContacts', () => updateContacts())
|
||||||
|
|||||||
Reference in New Issue
Block a user