[FIX] Messages showing URL preview on Room Actions (#4065)

* using database query instead of Rocketchat search api to get message search results

* getting search data from server then converting it into the format as required for message rendering

* fixing some redundant changes

* remove ts-ignore

* removing redundant statements

* url preview is visible when we see messages in pinned, mentions and starred messages

Co-authored-by: Gerzon Z <gerzonzcanario@gmail.com>
This commit is contained in:
Samay Kothari 2022-05-04 01:22:56 +05:30 committed by GitHub
parent b006fc4358
commit 9d0b659097
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 4 deletions

View File

@ -22,7 +22,7 @@ import { ChatsStackParamList } from '../../stacks/types';
import { ISubscription, SubscriptionType } from '../../definitions/ISubscription'; import { ISubscription, SubscriptionType } from '../../definitions/ISubscription';
import { IEmoji } from '../../definitions/IEmoji'; import { IEmoji } from '../../definitions/IEmoji';
import { IRoomInfoParam } from '../SearchMessagesView'; import { IRoomInfoParam } from '../SearchMessagesView';
import { TMessageModel } from '../../definitions'; import { TMessageModel, IUrl } from '../../definitions';
import { Services } from '../../lib/services'; import { Services } from '../../lib/services';
interface IMessagesViewProps { interface IMessagesViewProps {
@ -280,8 +280,25 @@ class MessagesView extends React.Component<IMessagesViewProps, any> {
try { try {
const result = await this.content.fetchFunc(); const result = await this.content.fetchFunc();
if (result.success) { if (result.success) {
const urlRenderMessages = result.messages?.map((message: any) => {
if (message.urls && message.urls.length > 0) {
message.urls = message.urls?.map((url: any, index: any) => {
if (url.meta) {
return {
_id: index,
title: url.meta.pageTitle,
description: url.meta.ogDescription,
image: url.meta.ogImage,
url: url.url
} as IUrl;
}
return {} as IUrl;
});
}
return message;
});
this.setState({ this.setState({
messages: [...messages, ...result.messages], messages: [...messages, ...urlRenderMessages],
total: result.total, total: result.total,
loading: false loading: false
}); });

View File

@ -32,6 +32,7 @@ import styles from './styles';
import { InsideStackParamList, ChatsStackParamList } from '../../stacks/types'; import { InsideStackParamList, ChatsStackParamList } from '../../stacks/types';
import { IEmoji } from '../../definitions/IEmoji'; import { IEmoji } from '../../definitions/IEmoji';
import { compareServerVersion } from '../../lib/methods/helpers/compareServerVersion'; import { compareServerVersion } from '../../lib/methods/helpers/compareServerVersion';
import { IUrl } from '../../definitions';
import { Services } from '../../lib/services'; import { Services } from '../../lib/services';
const QUERY_SIZE = 50; const QUERY_SIZE = 50;
@ -155,9 +156,25 @@ class SearchMessagesView extends React.Component<ISearchMessagesViewProps, ISear
// If it's not a encrypted room, search messages on the server // If it's not a encrypted room, search messages on the server
const result = await Services.searchMessages(this.rid, searchText, QUERY_SIZE, this.offset); const result = await Services.searchMessages(this.rid, searchText, QUERY_SIZE, this.offset);
if (result.success) { if (result.success) {
return result.messages; const urlRenderMessages = result.messages?.map(message => {
if (message.urls && message.urls.length > 0) {
message.urls = message.urls?.map((url, index) => {
if (url.meta) {
return {
_id: index,
title: url.meta.pageTitle,
description: url.meta.ogDescription,
image: url.meta.ogImage,
url: url.url
} as IUrl;
}
return {} as IUrl;
});
}
return message;
});
return urlRenderMessages;
} }
return []; return [];
}; };
getMessages = async (searchText: string, debounced?: boolean) => { getMessages = async (searchText: string, debounced?: boolean) => {