cleanup search of contacts excluding not active

pull/2142/head
Audric Ackermann 3 years ago
parent a3be2c347d
commit d269693544
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -1839,7 +1839,7 @@ function searchConversations(query, { limit } = {}) {
id LIKE $id OR id LIKE $id OR
name LIKE $name OR name LIKE $name OR
profileName LIKE $profileName profileName LIKE $profileName
) ) AND active_at IS NOT NULL AND active_at > 0
ORDER BY id ASC ORDER BY id ASC
LIMIT $limit` LIMIT $limit`
) )

@ -17,7 +17,6 @@ import {
resetOldTopMessageId, resetOldTopMessageId,
showScrollToBottomButton, showScrollToBottomButton,
SortedMessageModelProps, SortedMessageModelProps,
updateHaveDoneFirstScroll,
} from '../../state/ducks/conversations'; } from '../../state/ducks/conversations';
import { StateType } from '../../state/reducer'; import { StateType } from '../../state/reducer';
import { import {
@ -211,10 +210,6 @@ class SessionMessagesListContainerInner extends React.Component<Props> {
}); });
} }
} }
setTimeout(() => {
window.inboxStore?.dispatch(updateHaveDoneFirstScroll());
}, 100);
} }
/** /**
@ -250,6 +245,8 @@ class SessionMessagesListContainerInner extends React.Component<Props> {
block, block,
}); });
this.props.messageContainerRef.current?.scrollBy({ top: -50 });
if (options?.isLoadMoreTop) { if (options?.isLoadMoreTop) {
// reset the oldTopInRedux so that a refresh/new message does not scroll us back here again // reset the oldTopInRedux so that a refresh/new message does not scroll us back here again
window.inboxStore?.dispatch(resetOldTopMessageId()); window.inboxStore?.dispatch(resetOldTopMessageId());

@ -27,7 +27,7 @@ const Subtle = styled.div`
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
word-break: break-all; word-break: break-all;
-webkit-line-clamp: 3; -webkit-line-clamp: 2;
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
display: -webkit-box; display: -webkit-box;
color: var(--color-text); color: var(--color-text);

@ -13,7 +13,6 @@ import {
import { import {
areMoreBottomMessagesBeingFetched, areMoreBottomMessagesBeingFetched,
areMoreTopMessagesBeingFetched, areMoreTopMessagesBeingFetched,
getHaveDoneFirstScroll,
getLoadedMessagesLength, getLoadedMessagesLength,
getMostRecentMessageId, getMostRecentMessageId,
getOldestMessageId, getOldestMessageId,
@ -63,7 +62,6 @@ export const ReadableMessage = (props: ReadableMessageProps) => {
const selectedConversationKey = useSelector(getSelectedConversationKey); const selectedConversationKey = useSelector(getSelectedConversationKey);
const loadedMessagesLength = useSelector(getLoadedMessagesLength); const loadedMessagesLength = useSelector(getLoadedMessagesLength);
const haveDoneFirstScroll = useSelector(getHaveDoneFirstScroll);
const mostRecentMessageId = useSelector(getMostRecentMessageId); const mostRecentMessageId = useSelector(getMostRecentMessageId);
const oldestMessageId = useSelector(getOldestMessageId); const oldestMessageId = useSelector(getOldestMessageId);
const youngestMessageId = useSelector(getYoungestMessageId); const youngestMessageId = useSelector(getYoungestMessageId);
@ -74,14 +72,6 @@ export const ReadableMessage = (props: ReadableMessageProps) => {
const onVisible = useCallback( const onVisible = useCallback(
// tslint:disable-next-line: cyclomatic-complexity // tslint:disable-next-line: cyclomatic-complexity
async (inView: boolean | Object) => { async (inView: boolean | Object) => {
// when the view first loads, it needs to scroll to the unread messages.
// we need to disable the inview on the first loading
if (!haveDoneFirstScroll) {
if (inView === true) {
window.log.info('onVisible but waiting for first scroll event');
}
return;
}
// we are the most recent message // we are the most recent message
if (mostRecentMessageId === messageId) { if (mostRecentMessageId === messageId) {
// make sure the app is focused, because we mark message as read here // make sure the app is focused, because we mark message as read here
@ -137,7 +127,6 @@ export const ReadableMessage = (props: ReadableMessageProps) => {
}, },
[ [
selectedConversationKey, selectedConversationKey,
haveDoneFirstScroll,
mostRecentMessageId, mostRecentMessageId,
oldestMessageId, oldestMessageId,
fetchingTopMore, fetchingTopMore,
@ -158,8 +147,8 @@ export const ReadableMessage = (props: ReadableMessageProps) => {
className={className} className={className}
as="div" as="div"
threshold={0.5} threshold={0.5}
delay={haveDoneFirstScroll && isAppFocused ? 100 : 200} delay={isAppFocused ? 100 : 200}
onChange={haveDoneFirstScroll && isAppFocused ? onVisible : noop} onChange={isAppFocused ? onVisible : noop}
triggerOnce={false} triggerOnce={false}
trackVisibility={true} trackVisibility={true}
key={`inview-msg-${messageId}`} key={`inview-msg-${messageId}`}

@ -97,7 +97,7 @@ const ResultBody = styled.div`
overflow: hidden; overflow: hidden;
display: -webkit-box; display: -webkit-box;
-webkit-line-clamp: 3; -webkit-line-clamp: 2;
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
`; `;

@ -276,7 +276,6 @@ export type ConversationsStateType = {
areMoreBottomMessagesBeingFetched: boolean; areMoreBottomMessagesBeingFetched: boolean;
oldTopMessageId: string | null; oldTopMessageId: string | null;
oldBottomMessageId: string | null; oldBottomMessageId: string | null;
haveDoneFirstScroll: boolean;
showScrollButton: boolean; showScrollButton: boolean;
animateQuotedMessageId?: string; animateQuotedMessageId?: string;
@ -394,7 +393,6 @@ export function getEmptyConversationState(): ConversationsStateType {
showScrollButton: false, showScrollButton: false,
mentionMembers: [], mentionMembers: [],
firstUnreadMessageId: undefined, firstUnreadMessageId: undefined,
haveDoneFirstScroll: false,
oldTopMessageId: null, oldTopMessageId: null,
oldBottomMessageId: null, oldBottomMessageId: null,
}; };
@ -741,8 +739,6 @@ const conversationsSlice = createSlice({
oldBottomMessageId: null, oldBottomMessageId: null,
mentionMembers: [], mentionMembers: [],
firstUnreadMessageId: action.payload.firstUnreadIdOnOpen, firstUnreadMessageId: action.payload.firstUnreadIdOnOpen,
haveDoneFirstScroll: false,
}; };
}, },
navigateInConversationToMessageId( navigateInConversationToMessageId(
@ -773,10 +769,6 @@ const conversationsSlice = createSlice({
state.oldBottomMessageId = null; state.oldBottomMessageId = null;
return state; return state;
}, },
updateHaveDoneFirstScroll(state: ConversationsStateType) {
state.haveDoneFirstScroll = true;
return state;
},
showLightBox( showLightBox(
state: ConversationsStateType, state: ConversationsStateType,
action: PayloadAction<LightBoxOptions | undefined> action: PayloadAction<LightBoxOptions | undefined>
@ -913,7 +905,6 @@ export const {
messagesChanged, messagesChanged,
resetOldTopMessageId, resetOldTopMessageId,
resetOldBottomMessageId, resetOldBottomMessageId,
updateHaveDoneFirstScroll,
markConversationFullyRead, markConversationFullyRead,
// layout stuff // layout stuff
showMessageDetailsView, showMessageDetailsView,

@ -6,6 +6,7 @@ import { ReduxConversationType } from './conversations';
import { PubKey } from '../../session/types'; import { PubKey } from '../../session/types';
import { ConversationTypeEnum } from '../../models/conversation'; import { ConversationTypeEnum } from '../../models/conversation';
import _ from 'lodash'; import _ from 'lodash';
import { getConversationController } from '../../session/conversations';
// State // State
@ -84,19 +85,15 @@ async function doSearch(query: string, options: SearchOptions): Promise<SearchRe
const { conversations, contacts } = discussions; const { conversations, contacts } = discussions;
let filteredMessages = _.compact(messages); let filteredMessages = _.compact(messages);
if (isAdvancedQuery) { if (isAdvancedQuery) {
if (advancedSearchOptions.from && advancedSearchOptions.from.length > 0) { const senderFilterQuery =
const senderFilterQuery = await queryConversationsAndContacts( advancedSearchOptions.from && advancedSearchOptions.from.length > 0
advancedSearchOptions.from, ? await queryConversationsAndContacts(advancedSearchOptions.from, options)
options : undefined;
); filteredMessages = advancedFilterMessages(
filteredMessages = filterMessages( filteredMessages,
filteredMessages, advancedSearchOptions,
advancedSearchOptions, senderFilterQuery?.contacts || []
senderFilterQuery.contacts );
);
} else {
filteredMessages = filterMessages(filteredMessages, advancedSearchOptions, []);
}
} }
return { return {
query, query,
@ -123,7 +120,7 @@ export function updateSearchTerm(query: string): UpdateSearchTermActionType {
// Helper functions for search // Helper functions for search
function filterMessages( function advancedFilterMessages(
messages: Array<any>, messages: Array<any>,
filters: AdvancedSearchOptions, filters: AdvancedSearchOptions,
contacts: Array<string> contacts: Array<string>
@ -222,13 +219,12 @@ async function queryConversationsAndContacts(providedQuery: string, options: Sea
const max = searchResults.length; const max = searchResults.length;
for (let i = 0; i < max; i += 1) { for (let i = 0; i < max; i += 1) {
const conversation = searchResults[i]; const conversation = searchResults[i];
const primaryDevice = searchResults[i].id;
if (primaryDevice) { if (conversation.id && conversation.activeAt) {
if (primaryDevice === ourNumber) { if (conversation.id === ourNumber) {
conversations.push(ourNumber); conversations.push(ourNumber);
} else { } else {
conversations.push(primaryDevice); conversations.push(conversation.id);
} }
} else if (conversation.type === ConversationTypeEnum.PRIVATE) { } else if (conversation.type === ConversationTypeEnum.PRIVATE) {
contacts.push(conversation.id); contacts.push(conversation.id);
@ -240,11 +236,14 @@ async function queryConversationsAndContacts(providedQuery: string, options: Sea
} }
// Inject synthetic Note to Self entry if query matches localized 'Note to Self' // Inject synthetic Note to Self entry if query matches localized 'Note to Self'
if (noteToSelf.indexOf(providedQuery.toLowerCase()) !== -1) { if (noteToSelf.indexOf(providedQuery.toLowerCase()) !== -1) {
// ensure that we don't have duplicates in our results const ourConvo = getConversationController().get(ourNumber);
contacts = contacts.filter(id => id !== ourNumber); if (ourConvo && ourConvo.isActive()) {
conversations = conversations.filter(id => id !== ourNumber); // ensure that we don't have duplicates in our results
contacts = contacts.filter(id => id !== ourNumber);
conversations = conversations.filter(id => id !== ourNumber);
contacts.unshift(ourNumber); contacts.unshift(ourNumber);
}
} }
return { conversations, contacts }; return { conversations, contacts };

@ -602,11 +602,6 @@ export const areMoreBottomMessagesBeingFetched = createSelector(
(state: ConversationsStateType): boolean => state.areMoreBottomMessagesBeingFetched || false (state: ConversationsStateType): boolean => state.areMoreBottomMessagesBeingFetched || false
); );
export const getHaveDoneFirstScroll = createSelector(
getConversations,
(state: ConversationsStateType): boolean => state.haveDoneFirstScroll
);
export const getShowScrollButton = createSelector( export const getShowScrollButton = createSelector(
getConversations, getConversations,
(state: ConversationsStateType): boolean => state.showScrollButton || false (state: ConversationsStateType): boolean => state.showScrollButton || false

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save