diff --git a/src/common/component/Message/Mention.js b/src/common/component/Message/Mention.js index d622b79a..444dc966 100644 --- a/src/common/component/Message/Mention.js +++ b/src/common/component/Message/Mention.js @@ -10,10 +10,11 @@ const Styled = styled.span` cursor: pointer; } `; -export default function Mention({ uid, popover = true, cid }) { +export default function Mention({ uid, popover = true, cid, textOnly = false }) { const contactsData = useSelector((store) => store.contacts.byId); const user = contactsData[uid]; if (!user) return null; + if (textOnly) return `@${user.name}`; return ( 3 ? 50 : initials.length > 2 ? 40 : initials.length == 2 ? 30 : 0; + context.font = `${weight} ${((initial_size || height) - subtract) / 2}px ${fontFamily}`; context.textAlign = "center"; context.textBaseline = "middle"; diff --git a/src/routes/chat/SessionList/Session.js b/src/routes/chat/SessionList/Session.js index 7dc281ad..af990247 100644 --- a/src/routes/chat/SessionList/Session.js +++ b/src/routes/chat/SessionList/Session.js @@ -7,6 +7,7 @@ import relativeTime from "dayjs/plugin/relativeTime"; import ContextMenu from "./ContextMenu"; import getUnreadCount, { renderPreviewMessage } from "../utils"; import Contact from "../../../common/component/Contact"; +import Avatar from "../../../common/component/Avatar"; import iconChannel from "../../../assets/icons/channel.svg?url"; import IconLock from "../../../assets/icons/lock.svg"; import useContextMenu from "../../../common/hook/useContextMenu"; @@ -45,7 +46,7 @@ export default function Session({ ); const { visible: contextMenuVisible, handleContextMenuEvent, hideContextMenu } = useContextMenu(); const [data, setData] = useState(null); - const { messageData, contactData, channelData, readIndex, loginUid, mids } = useSelector( + const { messageData, contactData, channelData, readIndex, loginUid, mids, muted } = useSelector( (store) => { return { mids: type == "user" ? store.userMessage.byId[id] : store.channelMessage[id], @@ -54,7 +55,8 @@ export default function Session({ type == "user" ? store.footprint.readUsers[id] : store.footprint.readChannels[id], messageData: store.message, contactData: store.contacts.byId, - channelData: store.channels.byId + channelData: store.channels.byId, + muted: type == "user" ? store.footprint.muteUsers[id] : store.footprint.muteChannels[id] }; } ); @@ -92,7 +94,7 @@ export default function Session({ > @@ -100,11 +102,12 @@ export default function Session({ {type == "user" ? ( ) : ( - + + // )}
diff --git a/src/routes/chat/SessionList/index.js b/src/routes/chat/SessionList/index.js index b1101003..20929d91 100644 --- a/src/routes/chat/SessionList/index.js +++ b/src/routes/chat/SessionList/index.js @@ -24,7 +24,7 @@ export default function SessionList({ tempSession = null }) { const cSessions = channelIDs.map((id) => { const mids = channelMessage[id]; if (!mids || mids.length == 0) { - return { mid: null, unreads: 0, id, type: "channel" }; + return { key: `channel_${id}`, mid: null, unreads: 0, id, type: "channel" }; } const mid = [...mids].pop(); return { key: `channel_${id}`, id, mid, type: "channel" }; @@ -32,7 +32,7 @@ export default function SessionList({ tempSession = null }) { const uSessions = DMs.map((id) => { const mids = userMessage[id]; if (!mids || mids.length == 0) { - return { mid: null, unreads: 0, id, type: "user" }; + return { key: `user_${id}`, mid: null, unreads: 0, id, type: "user" }; } const mid = [...mids].pop(); return { key: `user_${id}`, type: "user", id, mid }; diff --git a/src/routes/chat/SessionList/styled.js b/src/routes/chat/SessionList/styled.js index 846b51b7..c6ec9b80 100644 --- a/src/routes/chat/SessionList/styled.js +++ b/src/routes/chat/SessionList/styled.js @@ -21,7 +21,7 @@ const Styled = styled.ul` box-shadow: inset 0 0 0 2px #52edff; } .icon { - flex: 1; + display: flex; background-color: #eee; border-radius: 50%; img { @@ -101,6 +101,16 @@ const Styled = styled.ul` } } } + &.muted { + .up .name, + .up .time, + .down .msg { + color: #d0d5dd; + } + .down .badge { + background: #bfbfbf; + } + } } } `; diff --git a/src/routes/chat/index.js b/src/routes/chat/index.js index 15e99bd8..d5e211f1 100644 --- a/src/routes/chat/index.js +++ b/src/routes/chat/index.js @@ -30,7 +30,7 @@ export default function ChatPage() { const tmpSession = sessionUids.findIndex((i) => i == user_id) > -1 ? null - : { mid: null, unreads: 0, id: user_id, type: "user" }; + : { key: `user_${user_id}`, mid: null, unreads: 0, id: user_id, type: "user" }; // console.log("temp uid", tmpUid); const placeholderVisible = !channel_id && !user_id; return ( diff --git a/src/routes/chat/utils.js b/src/routes/chat/utils.js index 0d8c77bd..d50392f9 100644 --- a/src/routes/chat/utils.js +++ b/src/routes/chat/utils.js @@ -8,6 +8,8 @@ import Checkbox from "../../common/component/styled/Checkbox"; import Divider from "../../common/component/Divider"; import Message from "../../common/component/Message"; import { updateSelectMessages } from "../../app/slices/ui"; +import Mention from "../../common/component/Message/Mention"; +import reactStringReplace from "react-string-replace"; // function debounce(callback, wait = 2000, immediate = false) { // let timeout = null; // return function () { @@ -55,7 +57,11 @@ export const renderPreviewMessage = (message = null) => { switch (content_type) { case ContentTypes.text: { - res = content; + res = reactStringReplace(content, /(\s{1}@[0-9]+\s{1})/g, (match, idx) => { + console.log("match", match); + const uid = match.trim().slice(1); + return ; + }); } break; case ContentTypes.markdown: diff --git a/src/routes/index.js b/src/routes/index.js index 07f690e3..5da10911 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -6,7 +6,7 @@ import toast from "react-hot-toast"; import NotFoundPage from "./404"; // const HomePage = lazy(() => import("./home")); const RegBasePage = lazy(() => import("./reg")); -const ChatPage = lazy(() => import("./chat")); +// const ChatPage = lazy(() => import("./chat")); const RegWithUsernamePage = lazy(() => import("./reg/RegWithUsername")); const SendMagicLinkPage = lazy(() => import("./sendMagicLink")); const RegPage = lazy(() => import("./reg/Register")); @@ -23,7 +23,7 @@ import RequireAuth from "../common/component/RequireAuth"; import RequireNoAuth from "../common/component/RequireNoAuth"; import Meta from "../common/component/Meta"; import HomePage from "./home"; -// import ChatPage from "./chat"; +import ChatPage from "./chat"; import Loading from "../common/component/Loading"; import store from "../app/store"; @@ -114,9 +114,9 @@ const PageRoutes = () => { }> - - + // }> + + // } /> @@ -124,17 +124,17 @@ const PageRoutes = () => { }> - - + // }> + + // } /> }> - - + // }> + + // } />