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