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
name LIKE $name OR
profileName LIKE $profileName
)
) AND active_at IS NOT NULL AND active_at > 0
ORDER BY id ASC
LIMIT $limit`
)

@ -17,7 +17,6 @@ import {
resetOldTopMessageId,
showScrollToBottomButton,
SortedMessageModelProps,
updateHaveDoneFirstScroll,
} from '../../state/ducks/conversations';
import { StateType } from '../../state/reducer';
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,
});
this.props.messageContainerRef.current?.scrollBy({ top: -50 });
if (options?.isLoadMoreTop) {
// reset the oldTopInRedux so that a refresh/new message does not scroll us back here again
window.inboxStore?.dispatch(resetOldTopMessageId());

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

@ -13,7 +13,6 @@ import {
import {
areMoreBottomMessagesBeingFetched,
areMoreTopMessagesBeingFetched,
getHaveDoneFirstScroll,
getLoadedMessagesLength,
getMostRecentMessageId,
getOldestMessageId,
@ -63,7 +62,6 @@ export const ReadableMessage = (props: ReadableMessageProps) => {
const selectedConversationKey = useSelector(getSelectedConversationKey);
const loadedMessagesLength = useSelector(getLoadedMessagesLength);
const haveDoneFirstScroll = useSelector(getHaveDoneFirstScroll);
const mostRecentMessageId = useSelector(getMostRecentMessageId);
const oldestMessageId = useSelector(getOldestMessageId);
const youngestMessageId = useSelector(getYoungestMessageId);
@ -74,14 +72,6 @@ export const ReadableMessage = (props: ReadableMessageProps) => {
const onVisible = useCallback(
// tslint:disable-next-line: cyclomatic-complexity
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
if (mostRecentMessageId === messageId) {
// make sure the app is focused, because we mark message as read here
@ -137,7 +127,6 @@ export const ReadableMessage = (props: ReadableMessageProps) => {
},
[
selectedConversationKey,
haveDoneFirstScroll,
mostRecentMessageId,
oldestMessageId,
fetchingTopMore,
@ -158,8 +147,8 @@ export const ReadableMessage = (props: ReadableMessageProps) => {
className={className}
as="div"
threshold={0.5}
delay={haveDoneFirstScroll && isAppFocused ? 100 : 200}
onChange={haveDoneFirstScroll && isAppFocused ? onVisible : noop}
delay={isAppFocused ? 100 : 200}
onChange={isAppFocused ? onVisible : noop}
triggerOnce={false}
trackVisibility={true}
key={`inview-msg-${messageId}`}

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

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

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

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

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