pull/1778/head
Brice-W 4 years ago
parent c98fdec10e
commit 151fc758c0

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { useFocus } from "../../hooks/useFocus" import { useFocus } from '../../hooks/useFocus';
import { InView } from 'react-intersection-observer'; import { InView } from 'react-intersection-observer';
type ReadableMessageProps = { type ReadableMessageProps = {
@ -7,22 +7,16 @@ type ReadableMessageProps = {
id: string; id: string;
className: string; className: string;
onChange: (inView: boolean) => void; onChange: (inView: boolean) => void;
onContextMenu: (e: any) => void onContextMenu: (e: any) => void;
} };
export const ReadableMessage = (props: ReadableMessageProps) => { export const ReadableMessage = (props: ReadableMessageProps) => {
const { onChange } = props; const { onChange } = props;
useFocus(onChange); useFocus(onChange);
return ( return (
<InView <InView {...props} as="div" threshold={1} delay={200} triggerOnce={true}>
{...props}
as="div"
threshold={1}
delay={200}
triggerOnce={true}
>
{props.children} {props.children}
</InView>); </InView>
} );
};

@ -1,11 +1,10 @@
import { useEffect } from "react"; import { useEffect } from 'react';
export const useFocus = (action: (param: any) => void) => { export const useFocus = (action: (param: any) => void) => {
useEffect(() => { useEffect(() => {
window.addEventListener("focus", action); window.addEventListener('focus', action);
return () => { return () => {
window.removeEventListener("focus", action); window.removeEventListener('focus', action);
}; };
}); });
} };

@ -1047,6 +1047,8 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
public async markRead(readAt: number) { public async markRead(readAt: number) {
this.markReadNoCommit(readAt); this.markReadNoCommit(readAt);
this.getConversation()?.markRead(readAt);
await this.commit(); await this.commit();
} }

Loading…
Cancel
Save