update IMessage
This commit is contained in:
parent
6a9f878d28
commit
5e26954644
|
@ -1,3 +1,44 @@
|
||||||
export interface IMessage {
|
import Model from '@nozbe/watermelondb/Model';
|
||||||
msg: string;
|
|
||||||
|
import { ISubscriptions } from './ISubscriptions';
|
||||||
|
|
||||||
|
export interface IMessage extends ISubscriptions {
|
||||||
|
id: string;
|
||||||
|
rid: string;
|
||||||
|
ts: number;
|
||||||
|
u: string;
|
||||||
|
alias: string;
|
||||||
|
parse_urls: string;
|
||||||
|
_updated_at: number;
|
||||||
|
msg?: string;
|
||||||
|
t?: string;
|
||||||
|
groupable?: boolean;
|
||||||
|
avatar?: string;
|
||||||
|
emoji?: string;
|
||||||
|
attachments?: string;
|
||||||
|
urls?: string;
|
||||||
|
status?: number;
|
||||||
|
pinned?: boolean;
|
||||||
|
starred?: boolean;
|
||||||
|
edited_by?: string;
|
||||||
|
reactions?: string;
|
||||||
|
role?: string;
|
||||||
|
drid?: string;
|
||||||
|
dcount?: number;
|
||||||
|
dlm?: number;
|
||||||
|
tmid?: string;
|
||||||
|
tcount?: number;
|
||||||
|
tlm?: number;
|
||||||
|
replies?: string;
|
||||||
|
mentions?: string;
|
||||||
|
channels?: string;
|
||||||
|
auto_translate?: boolean;
|
||||||
|
translations?: string;
|
||||||
|
tmsg?: string;
|
||||||
|
blocks?: string;
|
||||||
|
e2e?: string;
|
||||||
|
tshow?: boolean;
|
||||||
|
md?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type TMessageModel = IMessage & Model;
|
||||||
|
|
|
@ -22,14 +22,14 @@ export interface IThread {
|
||||||
attachments: IAttachment[];
|
attachments: IAttachment[];
|
||||||
urls: IUrl[];
|
urls: IUrl[];
|
||||||
status: number;
|
status: number;
|
||||||
pinned: null;
|
pinned: boolean;
|
||||||
starred: null;
|
starred: boolean;
|
||||||
edited_by: { username: string };
|
edited_by: { username: string };
|
||||||
reactions: IReaction[];
|
reactions: IReaction[];
|
||||||
role: null;
|
role: string;
|
||||||
drid: string;
|
drid: string;
|
||||||
dcount: null;
|
dcount: number;
|
||||||
dlm: null;
|
dlm: number;
|
||||||
tmid: string;
|
tmid: string;
|
||||||
tcount: 2;
|
tcount: 2;
|
||||||
tlm: Date;
|
tlm: Date;
|
||||||
|
|
|
@ -5,6 +5,7 @@ import Animated from 'react-native-reanimated';
|
||||||
import { isIOS } from '../../../utils/deviceInfo';
|
import { isIOS } from '../../../utils/deviceInfo';
|
||||||
import scrollPersistTaps from '../../../utils/scrollPersistTaps';
|
import scrollPersistTaps from '../../../utils/scrollPersistTaps';
|
||||||
import { IRoomItem } from '../index';
|
import { IRoomItem } from '../index';
|
||||||
|
import { IMessage } from '../../../definitions/IMessage';
|
||||||
|
|
||||||
const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
|
const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ const styles = StyleSheet.create({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
interface IRoomListProps extends FlatListProps<IRoomItem> {
|
interface IRoomListProps extends FlatListProps<IRoomItem | IMessage> {
|
||||||
listRef: React.Ref<FlatList>;
|
listRef: React.Ref<FlatList>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import moment from 'moment';
|
||||||
import { dequal } from 'dequal';
|
import { dequal } from 'dequal';
|
||||||
import { Value, event } from 'react-native-reanimated';
|
import { Value, event } from 'react-native-reanimated';
|
||||||
import { Observable, Subscription } from 'rxjs';
|
import { Observable, Subscription } from 'rxjs';
|
||||||
import Model from '@nozbe/watermelondb/Model';
|
|
||||||
import { StackNavigationProp } from '@react-navigation/stack';
|
import { StackNavigationProp } from '@react-navigation/stack';
|
||||||
|
|
||||||
import database from '../../../lib/database';
|
import database from '../../../lib/database';
|
||||||
|
@ -22,6 +21,7 @@ import NavBottomFAB from './NavBottomFAB';
|
||||||
import { ChatsStackParamList } from '../../../stacks/types';
|
import { ChatsStackParamList } from '../../../stacks/types';
|
||||||
import { IRoomItem } from '../index';
|
import { IRoomItem } from '../index';
|
||||||
import { IThread } from '../../../definitions/IThread';
|
import { IThread } from '../../../definitions/IThread';
|
||||||
|
import { IMessage, TMessageModel } from '../../../definitions/IMessage';
|
||||||
|
|
||||||
const QUERY_SIZE = 50;
|
const QUERY_SIZE = 50;
|
||||||
|
|
||||||
|
@ -52,7 +52,13 @@ interface IRoomListContainerProps {
|
||||||
serverVersion: string;
|
serverVersion: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ListContainer extends React.Component<IRoomListContainerProps, any> {
|
interface IRoomListContainerState {
|
||||||
|
messages: TMessageModel[];
|
||||||
|
refreshing: boolean;
|
||||||
|
highlightedMessage: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ListContainer extends React.Component<IRoomListContainerProps, IRoomListContainerState> {
|
||||||
private count: number;
|
private count: number;
|
||||||
private mounted: boolean;
|
private mounted: boolean;
|
||||||
private animated: boolean;
|
private animated: boolean;
|
||||||
|
@ -63,7 +69,7 @@ class ListContainer extends React.Component<IRoomListContainerProps, any> {
|
||||||
private viewabilityConfig: { itemVisiblePercentThreshold: number };
|
private viewabilityConfig: { itemVisiblePercentThreshold: number };
|
||||||
private highlightedMessageTimeout?: ReturnType<typeof setTimeout> | false;
|
private highlightedMessageTimeout?: ReturnType<typeof setTimeout> | false;
|
||||||
private thread?: IThread;
|
private thread?: IThread;
|
||||||
private messagesObservable?: Observable<Model>;
|
private messagesObservable?: Observable<TMessageModel[]>;
|
||||||
private messagesSubscription?: Subscription;
|
private messagesSubscription?: Subscription;
|
||||||
private viewableItems?: ViewToken[];
|
private viewableItems?: ViewToken[];
|
||||||
|
|
||||||
|
@ -97,7 +103,7 @@ class ListContainer extends React.Component<IRoomListContainerProps, any> {
|
||||||
console.timeEnd(`${this.constructor.name} mount`);
|
console.timeEnd(`${this.constructor.name} mount`);
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps: IRoomListContainerProps, nextState: any) {
|
shouldComponentUpdate(nextProps: IRoomListContainerProps, nextState: IRoomListContainerState) {
|
||||||
const { refreshing, highlightedMessage } = this.state;
|
const { refreshing, highlightedMessage } = this.state;
|
||||||
const { hideSystemMessages, theme, tunread, ignored, loading } = this.props;
|
const { hideSystemMessages, theme, tunread, ignored, loading } = this.props;
|
||||||
if (theme !== nextProps.theme) {
|
if (theme !== nextProps.theme) {
|
||||||
|
@ -187,8 +193,9 @@ class ListContainer extends React.Component<IRoomListContainerProps, any> {
|
||||||
|
|
||||||
if (rid) {
|
if (rid) {
|
||||||
this.unsubscribeMessages();
|
this.unsubscribeMessages();
|
||||||
this.messagesSubscription = this.messagesObservable?.subscribe((messages: any) => {
|
this.messagesSubscription = this.messagesObservable?.subscribe((messages: TMessageModel[]) => {
|
||||||
if (tmid && this.thread) {
|
if (tmid && this.thread) {
|
||||||
|
// @ts-ignore
|
||||||
messages = [...messages, this.thread];
|
messages = [...messages, this.thread];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +204,7 @@ class ListContainer extends React.Component<IRoomListContainerProps, any> {
|
||||||
* hide system message is enabled
|
* hide system message is enabled
|
||||||
*/
|
*/
|
||||||
if (compareServerVersion(serverVersion, '3.16.0', methods.lowerThan) || hideSystemMessages.length) {
|
if (compareServerVersion(serverVersion, '3.16.0', methods.lowerThan) || hideSystemMessages.length) {
|
||||||
messages = messages.filter((m: { t: string }) => !m.t || !hideSystemMessages?.includes(m.t));
|
messages = messages.filter((m: TMessageModel) => !m.t || !hideSystemMessages?.includes(m.t));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.mounted) {
|
if (this.mounted) {
|
||||||
|
@ -282,7 +289,7 @@ class ListContainer extends React.Component<IRoomListContainerProps, any> {
|
||||||
this.jumping = true;
|
this.jumping = true;
|
||||||
const { messages } = this.state;
|
const { messages } = this.state;
|
||||||
const { listRef } = this.props;
|
const { listRef } = this.props;
|
||||||
const index = messages.findIndex((item: { id: string }) => item.id === messageId);
|
const index = messages.findIndex((item: TMessageModel) => item.id === messageId);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
listRef.current?.scrollToIndex({ index, viewPosition: 0.5, viewOffset: 100 });
|
listRef.current?.scrollToIndex({ index, viewPosition: 0.5, viewOffset: 100 });
|
||||||
await new Promise(res => setTimeout(res, 300));
|
await new Promise(res => setTimeout(res, 300));
|
||||||
|
@ -326,7 +333,7 @@ class ListContainer extends React.Component<IRoomListContainerProps, any> {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
renderItem = ({ item, index }: { item: IRoomItem; index: number }) => {
|
renderItem = ({ item, index }: { item: IRoomItem | IMessage; index: number }) => {
|
||||||
const { messages, highlightedMessage } = this.state;
|
const { messages, highlightedMessage } = this.state;
|
||||||
const { renderRow } = this.props;
|
const { renderRow } = this.props;
|
||||||
return renderRow(item, messages[index + 1], highlightedMessage);
|
return renderRow(item, messages[index + 1], highlightedMessage);
|
||||||
|
|
|
@ -71,6 +71,7 @@ import { IAttachment } from '../../definitions/IAttachment';
|
||||||
import { IThread } from '../../definitions/IThread';
|
import { IThread } from '../../definitions/IThread';
|
||||||
import { ISubscriptions } from '../../definitions/ISubscriptions';
|
import { ISubscriptions } from '../../definitions/ISubscriptions';
|
||||||
import { ModalStackParamList } from '../../stacks/MasterDetailStack/types';
|
import { ModalStackParamList } from '../../stacks/MasterDetailStack/types';
|
||||||
|
import { IMessage } from '../../definitions/IMessage';
|
||||||
|
|
||||||
type TStateAttrsUpdate =
|
type TStateAttrsUpdate =
|
||||||
| 'joined'
|
| 'joined'
|
||||||
|
@ -751,7 +752,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onReplyInit = (message: string, mention: boolean) => {
|
onReplyInit = (message: IMessage, mention: boolean) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedMessage: message,
|
selectedMessage: message,
|
||||||
replying: true,
|
replying: true,
|
||||||
|
@ -1086,7 +1087,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
this.goRoomActionsView('SearchMessagesView');
|
this.goRoomActionsView('SearchMessagesView');
|
||||||
} else if (handleCommandReplyLatest(event)) {
|
} else if (handleCommandReplyLatest(event)) {
|
||||||
if (this.list && this.list.current) {
|
if (this.list && this.list.current) {
|
||||||
const message = this.list.current.getLastMessage();
|
const message = this.list.current.getLastMessage() as IMessage;
|
||||||
this.onReplyInit(message, false);
|
this.onReplyInit(message, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue