- {!hasMore && (
-
-
Welcome to #{name} !
-
This is the start of the #{name} channel.
-
-
- Edit Channel
-
-
- )}
- {/* */}
- }
- isReverse={true}
- loadMore={pullUp}
- >
- {msgIdList.map((mid, idx) => {
- const curr = messageData[mid];
- if (!curr) return null;
- const isFirst = idx == 0;
- const prev = idx == 0 ? null : messageData[msgIdList[idx - 1]];
- const read = curr?.from_uid == loginUid || mid <= readIndex;
- return renderMessageFragment({
- selectMode: !!selects,
- updateReadIndex: updateReadDebounced,
- read,
- isFirst,
- prev,
- curr,
- contextId: cid,
- context: "channel",
- });
- })}
-
- {appends.map((mid, idx) => {
- const curr = messageData[mid];
- if (!curr) return null;
- const isFirst = idx == 0;
- const prev =
- idx == 0 ? msgIdList.slice(-1)[0] : messageData[appends[idx - 1]];
- const read = curr?.from_uid == loginUid || mid <= readIndex;
- return renderMessageFragment({
- selectMode: !!selects,
- updateReadIndex: updateReadDebounced,
- read,
- isFirst,
- prev,
- curr,
- contextId: cid,
- context: "channel",
- });
- })}
- {/*
*/}
+
+
+
Welcome to #{name} !
+
This is the start of the #{name} channel.
+
+
+ Edit Channel
+
+
+
+ {[...msgIds]
+ .sort((a, b) => {
+ return Number(a) - Number(b);
+ })
+ .map((mid, idx) => {
+ const curr = messageData[mid];
+ if (!curr) return null;
+ const isFirst = idx == 0;
+ const prev = idx == 0 ? null : messageData[msgIds[idx - 1]];
+ const read = curr?.from_uid == loginUid || mid <= readIndex;
+ return renderMessageFragment({
+ selectMode: !!selects,
+ updateReadIndex: updateReadDebounced,
+ read,
+ isFirst,
+ prev,
+ curr,
+ contextId: cid,
+ context: "channel",
+ });
+ })}
+
{/* {unreads != 0 && (
diff --git a/src/routes/chat/ChannelChat/index.tmp.js b/src/routes/chat/ChannelChat/index.tmp.js
new file mode 100644
index 00000000..43444b93
--- /dev/null
+++ b/src/routes/chat/ChannelChat/index.tmp.js
@@ -0,0 +1,287 @@
+import { useState, useEffect } from "react";
+import { useDebounce } from "rooks";
+import { NavLink, useLocation } from "react-router-dom";
+import Tippy from "@tippyjs/react";
+import InfiniteScroll from "react-infinite-scroller";
+import { useDispatch, useSelector } from "react-redux";
+import PinList from "./PinList";
+import LoadMore from "./LoadMore";
+import FavList from "../FavList";
+import { useReadMessageMutation } from "../../../app/services/message";
+import { updateRemeberedNavs } from "../../../app/slices/ui";
+// import useChatScroll from "../../../common/hook/useChatScroll";
+import useMessageFeed from "../../../common/hook/useMessageFeed";
+import ChannelIcon from "../../../common/component/ChannelIcon";
+import Tooltip from "../../../common/component/Tooltip";
+import Contact from "../../../common/component/Contact";
+import Layout from "../Layout";
+import { renderMessageFragment } from "../utils";
+import EditIcon from "../../../assets/icons/edit.svg";
+// import alertIcon from "../../../assets/icons/alert.svg?url";
+import IconFav from "../../../assets/icons/bookmark.svg";
+import IconPeople from "../../../assets/icons/people.svg";
+import IconPin from "../../../assets/icons/pin.svg";
+// import searchIcon from "../../../assets/icons/search.svg?url";
+import IconHeadphone from "../../../assets/icons/headphone.svg";
+import boardosIcon from "../../../assets/icons/app.boardos.svg?url";
+import webrowseIcon from "../../../assets/icons/app.webrowse.svg?url";
+import addIcon from "../../../assets/icons/add.svg?url";
+import { StyledContacts, StyledChannelChat, StyledHeader } from "./styled";
+import InviteModal from "../../../common/component/InviteModal";
+
+export default function ChannelChat({ cid = "", dropFiles = [] }) {
+ const { list: msgIdList, appends, hasMore, pullUp } = useMessageFeed({
+ context: "channel",
+ id: cid,
+ });
+ const [toolVisible, setToolVisible] = useState("");
+ const { pathname } = useLocation();
+ const dispatch = useDispatch();
+ const [updateReadIndex] = useReadMessageMutation();
+ const updateReadDebounced = useDebounce(updateReadIndex, 300);
+ const [membersVisible, setMembersVisible] = useState(true);
+ const [addMemberModalVisible, setAddMemberModalVisible] = useState(false);
+ const {
+ selects,
+ userIds,
+ data,
+ messageData,
+ loginUid,
+ loginUser,
+ footprint,
+ } = useSelector((store) => {
+ return {
+ selects: store.ui.selectMessages[`channel_${cid}`],
+ footprint: store.footprint,
+ loginUser: store.contacts.byId[store.authData.uid],
+ loginUid: store.authData.uid,
+ userIds: store.contacts.ids,
+ data: store.channels.byId[cid] || {},
+ messageData: store.message || {},
+ };
+ });
+ // const ref = useChatScroll(mids);
+ // const handleClearUnreads = () => {
+ // dispatch(readMessage(msgIds));
+ // };
+ // remember the route while switching out
+ useEffect(() => {
+ dispatch(updateRemeberedNavs());
+ return () => {
+ dispatch(updateRemeberedNavs({ path: pathname }));
+ };
+ }, [pathname]);
+
+ const toggleMembersVisible = () => {
+ setMembersVisible((prev) => !prev);
+ };
+ const toggleAddVisible = () => {
+ setAddMemberModalVisible((prev) => !prev);
+ };
+ if (!data) return null;
+ const { name, description, is_public, members = [], owner } = data;
+ const memberIds = is_public
+ ? userIds
+ : members.slice(0).sort((n) => (n == owner ? -1 : 0));
+ const addVisible = loginUser?.is_admin || owner == loginUid;
+ const readIndex = footprint.readChannels[cid];
+ const pinCount = data?.pinned_messages?.length || 0;
+ // const finalHasMore = selects ? false : hasMore;
+ const msgs = [...msgIdList, ...appends];
+ return (
+ <>
+ {addMemberModalVisible && (
+
+ )}
+
+
+ -
+
+
+
+
+
+ {
+ setToolVisible("pin");
+ }}
+ onHide={() => {
+ setToolVisible("");
+ }}
+ placement="left-start"
+ popperOptions={{ strategy: "fixed" }}
+ offset={[0, 80]}
+ interactive
+ trigger="click"
+ content={}
+ >
+ - 0 ? "badge" : ""} ${
+ toolVisible == "pin" ? "active" : ""
+ } `}
+ data-count={pinCount}
+ >
+
+
+
+
+
+ {
+ setToolVisible("favorite");
+ }}
+ onHide={() => {
+ setToolVisible("");
+ }}
+ placement="left-start"
+ popperOptions={{ strategy: "fixed" }}
+ offset={[0, 180]}
+ interactive
+ trigger="click"
+ content={}
+ >
+ -
+
+
+
+
+ -
+
+
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+
+ >
+ }
+ header={
+
+
+
+ {name}
+ {description}
+
+
+ }
+ contacts={
+ membersVisible ? (
+ <>
+
+ {addVisible && (
+
+

+
Add members
+
+ )}
+ {memberIds.map((uid) => {
+ return (
+
+ );
+ })}
+
+ >
+ ) : null
+ }
+ >
+
+ {!hasMore && (
+
+
Welcome to #{name} !
+
This is the start of the #{name} channel.
+
+
+ Edit Channel
+
+
+ )}
+ {/* */}
+ }
+ isReverse={true}
+ loadMore={pullUp}
+ >
+ {msgs.map((mid, idx) => {
+ const curr = messageData[mid];
+ if (!curr) return null;
+ const isFirst = idx == 0;
+ const prev = idx == 0 ? null : messageData[msgs[idx - 1]];
+ const read = curr?.from_uid == loginUid || mid <= readIndex;
+ return renderMessageFragment({
+ selectMode: !!selects,
+ updateReadIndex: updateReadDebounced,
+ read,
+ isFirst,
+ prev,
+ curr,
+ contextId: cid,
+ context: "channel",
+ });
+ })}
+
+ {/*
*/}
+
+ {/* {unreads != 0 && (
+
+
+ {unreads} new messages
+ {msgs.lastAccess
+ ? `since ${dayjs(msgs.lastAccess).format("YYYY-MM-DD h:mm:ss A")}`
+ : ""}
+
+
+
+ )} */}
+
+ >
+ );
+}
diff --git a/src/routes/chat/utils.js b/src/routes/chat/utils.js
index 9e79f08b..2768435e 100644
--- a/src/routes/chat/utils.js
+++ b/src/routes/chat/utils.js
@@ -123,7 +123,14 @@ const StyledWrapper = styled.div`
}
}
`;
-const MessageWrapper = ({ selectMode = false, context, id, mid, children }) => {
+const MessageWrapper = ({
+ selectMode = false,
+ context,
+ id,
+ mid,
+ children,
+ ...rest
+}) => {
const dispatch = useDispatch();
const selects = useSelector(
@@ -135,7 +142,7 @@ const MessageWrapper = ({ selectMode = false, context, id, mid, children }) => {
dispatch(updateSelectMessages({ context, id, operation, data: mid }));
};
return (
-
+
{/* {React.cloneElement(children, { readOnly: selected })} */}
{children}
@@ -177,6 +184,8 @@ export const renderMessageFragment = ({
{divider && }