mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-10 01:03:36 -05:00
parent
74e786053e
commit
fb1de01edd
1 changed files with 16 additions and 17 deletions
|
@ -81,10 +81,11 @@ const Base = styled.div`
|
|||
`;
|
||||
|
||||
// ! FIXME: Move to global config
|
||||
const MAX_REPLIES = 4;
|
||||
const MAX_REPLIES = 5;
|
||||
export default observer(({ channel, replies, setReplies }: Props) => {
|
||||
const client = useClient();
|
||||
const client = channel.client;
|
||||
|
||||
// Event listener for adding new messages to reply bar.
|
||||
useEffect(() => {
|
||||
return internalSubscribe("ReplyBar", "add", (_message) => {
|
||||
const message = _message as Message;
|
||||
|
@ -107,26 +108,24 @@ export default observer(({ channel, replies, setReplies }: Props) => {
|
|||
});
|
||||
}, [replies, setReplies, client.user]);
|
||||
|
||||
const renderer = getRenderer(channel);
|
||||
if (renderer.state !== "RENDER") return null;
|
||||
// Map all the replies to messages we are aware of.
|
||||
const messages = replies.map((x) => client.messages.get(x.id));
|
||||
|
||||
const ids = replies.map((x) => x.id);
|
||||
const messages = renderer.messages.filter((x) => ids.includes(x._id));
|
||||
// Remove any replies which don't resolve to valid messages.
|
||||
useEffect(() => {
|
||||
if (messages.includes(undefined)) {
|
||||
setReplies(
|
||||
replies.filter((_, i) => typeof messages[i] !== "undefined"),
|
||||
);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [messages, replies, setReplies]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{replies.map((reply, index) => {
|
||||
const message = messages.find((x) => reply.id === x._id);
|
||||
// ! FIXME: better solution would be to
|
||||
// ! have a hook for resolving messages from
|
||||
// ! render state along with relevant users
|
||||
// -> which then fetches any unknown messages
|
||||
if (!message)
|
||||
return (
|
||||
<span>
|
||||
<Text id="app.main.channel.misc.failed_load" />
|
||||
</span>
|
||||
);
|
||||
const message = messages[index];
|
||||
if (!message) return null;
|
||||
|
||||
return (
|
||||
<Base key={reply.id}>
|
||||
|
|
Loading…
Reference in a new issue