-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prioritize @ autocomplete results based on recency and thread activity #7506
Prioritize @ autocomplete results based on recency and thread activity #7506
Conversation
import {debounce} from 'lodash'; | ||
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; | ||
import {Platform, SectionList, type SectionListData, type SectionListRenderItemInfo, type StyleProp, type ViewStyle} from 'react-native'; | ||
|
||
import {searchGroupsByName, searchGroupsByNameInChannel, searchGroupsByNameInTeam} from '@actions/local/group'; | ||
import {searchUsers} from '@actions/remote/user'; | ||
import {General} from '@app/constants'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import {General} from '@app/constants'; | |
import {General} from '@constants'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please update the import here
@@ -42,7 +51,7 @@ const getMatchTermForAtMention = (() => { | |||
return (value: string, isSearch: boolean) => { | |||
if (value !== lastValue || isSearch !== lastIsSearch) { | |||
const regex = isSearch ? AT_MENTION_SEARCH_REGEX : AT_MENTION_REGEX; | |||
let term = value.toLowerCase(); | |||
let term = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change? this was changed recently and I on pupose
const database = DatabaseManager.serverDatabases[serverUrl]?.database; | ||
if (!database) { | ||
return []; | ||
} | ||
|
||
return database.get<UserModel>(USER).query( | ||
Q.unsafeSqlQuery(`SELECT DISTINCT u.* FROM User u | ||
INNER JOIN ${CHANNEL_MEMBERSHIP} cm ON cm.user_id=u.id | ||
LEFT JOIN ${CHANNEL} c ON c.id=cm.id AND c.type='${General.DM_CHANNEL}' | ||
LEFT JOIN ${MY_CHANNEL} my | ||
WHERE cm.user_id IN (${`'${memberIds.join("','")}'`}) | ||
ORDER BY my.last_viewed_at DESC`)).fetch(); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap in a try / catch
LEFT JOIN ${CHANNEL} c ON c.id=cm.id AND c.type='${General.DM_CHANNEL}' | ||
LEFT JOIN ${MY_CHANNEL} my |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why I left join? I expect that a DM channel has a Channel
and MyChannel
relation met. So this could be an inner join that should improve the query plan.
const sortedMembersId = sortedMembers.map((e) => e.id); | ||
const membersNoDm = receivedUsers.users.filter((u) => !sortedMembersId.includes(u.id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could should make sortedMembersId
a Set so that the filter is more performant
|
||
const slicedArray = sortedMembers.slice(0, 20); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the slice here before filtering the result?
…utocomplete-resutls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure that after you change the imports that they are sorted correctly
import {debounce} from 'lodash'; | ||
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; | ||
import {Platform, SectionList, type SectionListData, type SectionListRenderItemInfo, type StyleProp, type ViewStyle} from 'react-native'; | ||
|
||
import {searchGroupsByName, searchGroupsByNameInChannel, searchGroupsByNameInTeam} from '@actions/local/group'; | ||
import {searchUsers} from '@actions/remote/user'; | ||
import {General} from '@app/constants'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please update the import here
import {debounce} from 'lodash'; | ||
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; | ||
import {Platform, SectionList, type SectionListData, type SectionListRenderItemInfo, type StyleProp, type ViewStyle} from 'react-native'; | ||
|
||
import {searchGroupsByName, searchGroupsByNameInChannel, searchGroupsByNameInTeam} from '@actions/local/group'; | ||
import {searchUsers} from '@actions/remote/user'; | ||
import {General} from '@app/constants'; | ||
import {logError} from '@app/utils/log'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import {logError} from '@app/utils/log'; | |
import {logError} from '@utils/log'; |
please update the import here
const getUsersFromDMSorted = async (serverUrl: string, memberIds: string[]) => { | ||
try { | ||
const database = DatabaseManager.serverDatabases[serverUrl]?.database; | ||
if (!database) { | ||
return emptyUserlList; | ||
} | ||
|
||
return database.get<UserModel>(USER).query( | ||
Q.unsafeSqlQuery(`SELECT DISTINCT u.* FROM User u | ||
INNER JOIN ${CHANNEL_MEMBERSHIP} cm ON cm.user_id=u.id | ||
INNER JOIN ${CHANNEL} c ON c.id=cm.id AND c.type='${General.DM_CHANNEL}' | ||
INNER JOIN ${MY_CHANNEL} my | ||
WHERE cm.user_id IN (${`'${memberIds.join("','")}'`}) | ||
ORDER BY my.last_viewed_at DESC`)).fetch(); | ||
} catch (error) { | ||
logError('Failed sort members', error); | ||
return emptyUserlList; | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function should be moved to the queries
folder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart of what enahum already said, a few minor comments.
const teamMembers = useMemo( | ||
() => [...usersInChannel, ...usersOutOfChannel], | ||
[usersInChannel, usersOutOfChannel], | ||
() => [...users], | ||
[users], | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is doing nothing, isn't? Shouldn't we be using directly users
?
assets/base/i18n/en.json
Outdated
"settings.about.app.version.title": "App Version:", | ||
"settings.about.app.version.value": "{version} (Build {number})", | ||
"settings.about.button.copyInfo": "Copy info", | ||
"settings.about.build": "{version} (Build {number})", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes seem unrelated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is fine, this is automatically generated.
@enahum Hi, any update? |
@nixusUM please fix the lint problems |
@enahum Hi, I fixed lint problems |
This PR has been automatically labelled "stale" because it hasn't had recent activity. |
@larkox what else is needed for us to merge this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exciting to see this get in, thanks @nixusUM! I'll defer to @yasserfaraazkhan for functionality check, please loop me in as needed if there's concerns.
mattermost#7506) * changed autocomplete results on recency * fixed issues * fixed imports, moved get fucn to queries folder * fixed en.json file * fixed lint promblems --------- Co-authored-by: Ilia Polozov <[email protected]>
Summary
Prioritize @ autocomplete results based on recency and thread activity
Ticket Link
mattermost/mattermost#21235
Checklist
Device Information
This PR was tested on: TECNO P8 Android, Samsung Galaxy S7 Edge Android, iPhone 11 Pro
Screenshots
Release Note