diff --git a/app/src/pages/Chat.tsx b/app/src/pages/Chat.tsx index 4884adf72..a9f833eda 100644 --- a/app/src/pages/Chat.tsx +++ b/app/src/pages/Chat.tsx @@ -18,6 +18,9 @@ import { patchGetOrJoinRoom } from "../api/chat"; import { Client4, WebSocketClient, WebSocketMessage } from "@mattermost/client"; import { Sleep } from "../utils/sleep"; import { Post, PostList } from "@mattermost/types/posts"; +import { addOutline } from "ionicons/icons"; +import { userGetAllByChain } from "../api/user"; +import { User } from "../api/types"; const VITE_CHAT_URL = import.meta.env.VITE_CHAT_URL; @@ -44,7 +47,9 @@ export default function Chat() { const [mmWsClient, setMmWsClient] = useState(null); const [message, setMessage] = useState(""); const [sendingMsg, setSendingMsg] = useState(SendingMsgState.DEFAULT); + const [chatRooms, setChatRooms] = useState(null); const [mmClient, setMmClient] = useState(null); + const [postList, setPostList] = useState({ order: [], posts: {}, @@ -101,6 +106,7 @@ export default function Chat() { setMmData(_mmData); }); } + getUsersChatrooms(); }, [mmData, chain]); async function handlePostedMessage( @@ -163,6 +169,21 @@ export default function Chat() { } } + async function getUsersChatrooms() { + if (authUser) { + try { + let _users = ( + await Promise.all( + authUser.chains.map((uc) => userGetAllByChain(uc.chain_uid)), + ) + ).map((d) => d.data); + setChatRooms(_users[0]); + } catch (err: any) { + console.error("Unable to load chains", err); + } + } + } + return ( @@ -174,59 +195,86 @@ export default function Chat() { -
-
- {postList.order.map((item) => { - let post = postList.posts[item]; - return ( -
- -
-
{post.props.username}
-
{post.message}
+
+
+
+
+ +
+ {chatRooms?.map((cr) => { + let initials = cr.name + .split(" ") + .map((word) => word[0]) + .join(""); + return ( +
+
+
{initials}
- -
- ); - })} +
+ {cr.name} +
+
+ ); + })} +
-
- - setMessage(e.detail.value as string)} - className="tw-ml-2" - /> - +
+ {postList.order.map((item) => { + let post = postList.posts[item]; + return ( +
+ +
+
+ {post.props.username} +
+
{post.message}
+
+
+
+ ); + })} +
+
+ - setMessage(e.detail.value as string)} + className="tw-ml-2" /> - - + + + + +