Fix message update
This commit is contained in:
parent
e4f0fdb525
commit
537cd0032e
|
@ -68,7 +68,7 @@ const Attachments: React.FC<IMessageAttachments> = React.memo(
|
||||||
if (file && file.image_url) {
|
if (file && file.image_url) {
|
||||||
return (
|
return (
|
||||||
<Image
|
<Image
|
||||||
key={file.image_url}
|
key={index}
|
||||||
file={file}
|
file={file}
|
||||||
showAttachment={showAttachment}
|
showAttachment={showAttachment}
|
||||||
getCustomEmoji={getCustomEmoji}
|
getCustomEmoji={getCustomEmoji}
|
||||||
|
@ -81,7 +81,7 @@ const Attachments: React.FC<IMessageAttachments> = React.memo(
|
||||||
if (file && file.audio_url) {
|
if (file && file.audio_url) {
|
||||||
return (
|
return (
|
||||||
<Audio
|
<Audio
|
||||||
key={file.audio_url}
|
key={index}
|
||||||
file={file}
|
file={file}
|
||||||
getCustomEmoji={getCustomEmoji}
|
getCustomEmoji={getCustomEmoji}
|
||||||
isReply={isReply}
|
isReply={isReply}
|
||||||
|
@ -95,7 +95,7 @@ const Attachments: React.FC<IMessageAttachments> = React.memo(
|
||||||
if (file.video_url) {
|
if (file.video_url) {
|
||||||
return (
|
return (
|
||||||
<Video
|
<Video
|
||||||
key={file.video_url}
|
key={index}
|
||||||
file={file}
|
file={file}
|
||||||
showAttachment={showAttachment}
|
showAttachment={showAttachment}
|
||||||
getCustomEmoji={getCustomEmoji}
|
getCustomEmoji={getCustomEmoji}
|
||||||
|
|
|
@ -90,8 +90,8 @@ const Fields = React.memo(
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{attachment.fields.map(field => (
|
{attachment.fields.map((field, index) => (
|
||||||
<View key={field.title} style={[styles.fieldContainer, { width: field.short ? '50%' : '100%' }]}>
|
<View key={index} style={[styles.fieldContainer, { width: field.short ? '50%' : '100%' }]}>
|
||||||
<Text testID='collapsibleQuoteTouchableFieldTitle' style={[styles.fieldTitle, { color: themes[theme].bodyText }]}>
|
<Text testID='collapsibleQuoteTouchableFieldTitle' style={[styles.fieldTitle, { color: themes[theme].bodyText }]}>
|
||||||
{field.title}
|
{field.title}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
|
@ -10,7 +10,7 @@ const Emoji = React.memo(
|
||||||
const parsedContent = content.replace(/^:|:$/g, '');
|
const parsedContent = content.replace(/^:|:$/g, '');
|
||||||
const emoji = getCustomEmoji(parsedContent);
|
const emoji = getCustomEmoji(parsedContent);
|
||||||
if (emoji) {
|
if (emoji) {
|
||||||
return <CustomEmoji key={content} style={customEmojiStyle} emoji={emoji} />;
|
return <CustomEmoji style={customEmojiStyle} emoji={emoji} />;
|
||||||
}
|
}
|
||||||
return <Text style={standardEmojiStyle}>{shortnameToUnicode(content)}</Text>;
|
return <Text style={standardEmojiStyle}>{shortnameToUnicode(content)}</Text>;
|
||||||
},
|
},
|
||||||
|
|
|
@ -53,7 +53,6 @@ const Reaction = React.memo(({ reaction, getCustomEmoji, theme }: IMessageReacti
|
||||||
<Touchable
|
<Touchable
|
||||||
onPress={() => onReactionPress(reaction.emoji)}
|
onPress={() => onReactionPress(reaction.emoji)}
|
||||||
onLongPress={onReactionLongPress}
|
onLongPress={onReactionLongPress}
|
||||||
key={reaction.emoji}
|
|
||||||
testID={`message-reaction-${reaction.emoji}`}
|
testID={`message-reaction-${reaction.emoji}`}
|
||||||
style={[
|
style={[
|
||||||
styles.reactionButton,
|
styles.reactionButton,
|
||||||
|
@ -83,8 +82,8 @@ const Reactions = React.memo(({ reactions, getCustomEmoji }: IMessageReactions)
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<View style={styles.reactionsContainer}>
|
<View style={styles.reactionsContainer}>
|
||||||
{reactions.map(reaction => (
|
{reactions.map((reaction, index) => (
|
||||||
<Reaction key={reaction.emoji} reaction={reaction} getCustomEmoji={getCustomEmoji} theme={theme} />
|
<Reaction key={index} reaction={reaction} getCustomEmoji={getCustomEmoji} theme={theme} />
|
||||||
))}
|
))}
|
||||||
<AddReaction theme={theme} />
|
<AddReaction theme={theme} />
|
||||||
</View>
|
</View>
|
||||||
|
|
|
@ -184,8 +184,8 @@ const Fields = React.memo(
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.fieldsContainer}>
|
<View style={styles.fieldsContainer}>
|
||||||
{attachment.fields.map(field => (
|
{attachment.fields.map((field, index) => (
|
||||||
<View key={field.title} style={[styles.fieldContainer, { width: field.short ? '50%' : '100%' }]}>
|
<View key={index} style={[styles.fieldContainer, { width: field.short ? '50%' : '100%' }]}>
|
||||||
<Text style={[styles.fieldTitle, { color: themes[theme].bodyText }]}>{field.title}</Text>
|
<Text style={[styles.fieldTitle, { color: themes[theme].bodyText }]}>{field.title}</Text>
|
||||||
<Markdown msg={field?.value || ''} username={user.username} getCustomEmoji={getCustomEmoji} theme={theme} />
|
<Markdown msg={field?.value || ''} username={user.username} getCustomEmoji={getCustomEmoji} theme={theme} />
|
||||||
</View>
|
</View>
|
||||||
|
|
|
@ -141,7 +141,7 @@ const Urls = React.memo(
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls.map((url: IUrl, index: number) => <Url url={url} key={url.url} index={index} theme={theme} />);
|
return urls.map((url: IUrl, index: number) => <Url url={url} key={index} index={index} theme={theme} />);
|
||||||
},
|
},
|
||||||
(oldProps, newProps) => dequal(oldProps.urls, newProps.urls)
|
(oldProps, newProps) => dequal(oldProps.urls, newProps.urls)
|
||||||
);
|
);
|
||||||
|
|
|
@ -81,15 +81,21 @@ class MessageContainer extends React.Component<IMessageContainerProps, IMessageC
|
||||||
|
|
||||||
private subscription?: Subscription;
|
private subscription?: Subscription;
|
||||||
|
|
||||||
componentDidMount() {
|
// componentDidMount() {
|
||||||
const { item } = this.props;
|
// const { item } = this.props;
|
||||||
if (item && item.observe) {
|
// console.log(`did mount ${item.id}`);
|
||||||
const observable = item.observe();
|
// let isFirstRender = true;
|
||||||
this.subscription = observable.subscribe(() => {
|
// if (item && item.observe) {
|
||||||
this.forceUpdate();
|
// const observable = item.observe();
|
||||||
});
|
// this.subscription = observable.subscribe(msg => {
|
||||||
}
|
// // console.log('🚀 ~ file: index.tsx ~ line 90 ~ MessageContainer ~ componentDidMount ~ msg', msg);
|
||||||
}
|
// if (!isFirstRender) {
|
||||||
|
// this.forceUpdate();
|
||||||
|
// }
|
||||||
|
// isFirstRender = false;
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// shouldComponentUpdate(nextProps: IMessageContainerProps, nextState: IMessageContainerState) {
|
// shouldComponentUpdate(nextProps: IMessageContainerProps, nextState: IMessageContainerState) {
|
||||||
// const { isManualUnignored } = this.state;
|
// const { isManualUnignored } = this.state;
|
||||||
|
@ -112,11 +118,11 @@ class MessageContainer extends React.Component<IMessageContainerProps, IMessageC
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
componentWillUnmount() {
|
// componentWillUnmount() {
|
||||||
if (this.subscription && this.subscription.unsubscribe) {
|
// if (this.subscription && this.subscription.unsubscribe) {
|
||||||
this.subscription.unsubscribe();
|
// this.subscription.unsubscribe();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
onPressAction = () => {
|
onPressAction = () => {
|
||||||
const { closeEmojiAndAction } = this.props;
|
const { closeEmojiAndAction } = this.props;
|
||||||
|
|
|
@ -97,29 +97,29 @@ class ListContainer extends React.Component<IListContainerProps, IListContainerS
|
||||||
console.timeEnd(`${this.constructor.name} mount`);
|
console.timeEnd(`${this.constructor.name} mount`);
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps: IListContainerProps, nextState: IListContainerState) {
|
// shouldComponentUpdate(nextProps: IListContainerProps, nextState: IListContainerState) {
|
||||||
const { refreshing, highlightedMessage } = this.state;
|
// const { refreshing, highlightedMessage } = this.state;
|
||||||
const { hideSystemMessages, tunread, ignored, loading } = this.props;
|
// const { hideSystemMessages, tunread, ignored, loading } = this.props;
|
||||||
if (loading !== nextProps.loading) {
|
// if (loading !== nextProps.loading) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
if (highlightedMessage !== nextState.highlightedMessage) {
|
// if (highlightedMessage !== nextState.highlightedMessage) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
if (refreshing !== nextState.refreshing) {
|
// if (refreshing !== nextState.refreshing) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
if (!dequal(hideSystemMessages, nextProps.hideSystemMessages)) {
|
// if (!dequal(hideSystemMessages, nextProps.hideSystemMessages)) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
if (!dequal(tunread, nextProps.tunread)) {
|
// if (!dequal(tunread, nextProps.tunread)) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
if (!dequal(ignored, nextProps.ignored)) {
|
// if (!dequal(ignored, nextProps.ignored)) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
componentDidUpdate(prevProps: IListContainerProps) {
|
componentDidUpdate(prevProps: IListContainerProps) {
|
||||||
const { hideSystemMessages } = this.props;
|
const { hideSystemMessages } = this.props;
|
||||||
|
@ -165,7 +165,7 @@ class ListContainer extends React.Component<IListContainerProps, IListContainerS
|
||||||
this.messagesObservable = db
|
this.messagesObservable = db
|
||||||
.get('thread_messages')
|
.get('thread_messages')
|
||||||
.query(Q.where('rid', tmid), Q.experimentalSortBy('ts', Q.desc), Q.experimentalSkip(0), Q.experimentalTake(this.count))
|
.query(Q.where('rid', tmid), Q.experimentalSortBy('ts', Q.desc), Q.experimentalSkip(0), Q.experimentalTake(this.count))
|
||||||
.observe();
|
.observeWithColumns(['_updated_at']);
|
||||||
} else if (rid) {
|
} else if (rid) {
|
||||||
const whereClause = [
|
const whereClause = [
|
||||||
Q.where('rid', rid),
|
Q.where('rid', rid),
|
||||||
|
@ -179,12 +179,44 @@ class ListContainer extends React.Component<IListContainerProps, IListContainerS
|
||||||
this.messagesObservable = db
|
this.messagesObservable = db
|
||||||
.get('messages')
|
.get('messages')
|
||||||
.query(...whereClause)
|
.query(...whereClause)
|
||||||
.observe();
|
.observeWithColumns(['_updated_at', 'status']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rid) {
|
if (rid) {
|
||||||
this.unsubscribeMessages();
|
this.unsubscribeMessages();
|
||||||
this.messagesSubscription = this.messagesObservable?.subscribe(messages => {
|
this.messagesSubscription = this.messagesObservable?.subscribe(messages => {
|
||||||
|
// @ts-ignore is this enough cols?
|
||||||
|
messages = messages.map(m => ({
|
||||||
|
id: m.id,
|
||||||
|
msg: m.msg,
|
||||||
|
ts: m.ts,
|
||||||
|
status: m.status,
|
||||||
|
attachments: m.attachments,
|
||||||
|
urls: m.urls,
|
||||||
|
reactions: m.reactions,
|
||||||
|
t: m.t,
|
||||||
|
avatar: m.avatar,
|
||||||
|
emoji: m.emoji,
|
||||||
|
u: m.u,
|
||||||
|
alias: m.alias,
|
||||||
|
editedBy: m.editedBy,
|
||||||
|
role: m.role,
|
||||||
|
drid: m.drid,
|
||||||
|
dcount: m.dcount,
|
||||||
|
dlm: m.dlm,
|
||||||
|
tmid: m.tmid,
|
||||||
|
tcount: m.tcount,
|
||||||
|
tlm: m.tlm,
|
||||||
|
tmsg: m.tmsg,
|
||||||
|
mentions: m.mentions,
|
||||||
|
channels: m.channels,
|
||||||
|
unread: m.unread,
|
||||||
|
blocks: m.blocks,
|
||||||
|
autoTranslate: m.autoTranslate,
|
||||||
|
replies: m.replies,
|
||||||
|
md: m.md,
|
||||||
|
comment: m.comment
|
||||||
|
}));
|
||||||
if (tmid && this.thread) {
|
if (tmid && this.thread) {
|
||||||
messages = [...messages, this.thread];
|
messages = [...messages, this.thread];
|
||||||
}
|
}
|
||||||
|
@ -198,7 +230,11 @@ class ListContainer extends React.Component<IListContainerProps, IListContainerS
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.mounted) {
|
if (this.mounted) {
|
||||||
this.setState({ messages }, () => this.update());
|
// if (this.animated) {
|
||||||
|
// animateNextTransition();
|
||||||
|
// }
|
||||||
|
// this.setState({ messages }, () => this.update());
|
||||||
|
this.setState({ messages });
|
||||||
} else {
|
} else {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.state.messages = messages;
|
this.state.messages = messages;
|
||||||
|
@ -252,7 +288,7 @@ class ListContainer extends React.Component<IListContainerProps, IListContainerS
|
||||||
if (this.animated) {
|
if (this.animated) {
|
||||||
animateNextTransition();
|
animateNextTransition();
|
||||||
}
|
}
|
||||||
this.forceUpdate();
|
// this.forceUpdate();
|
||||||
};
|
};
|
||||||
|
|
||||||
unsubscribeMessages = () => {
|
unsubscribeMessages = () => {
|
||||||
|
|
Loading…
Reference in New Issue