Skip to content
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

Merged

Conversation

nixusUM
Copy link
Contributor

@nixusUM nixusUM commented Aug 16, 2023

Summary

Prioritize @ autocomplete results based on recency and thread activity

Ticket Link

mattermost/mattermost#21235

Checklist

  • Added or updated unit tests (required for all new features)
  • Has UI changes
  • Includes text changes and localization file updates
  • Have tested against the 5 core themes to ensure consistency between them.

Device Information

This PR was tested on: TECNO P8 Android, Samsung Galaxy S7 Edge Android, iPhone 11 Pro

Screenshots

image

Release Note

Changed prioritize @ autocomplete results based on recency and thread activity

@mattermost-build
Copy link
Contributor

Hello @nixusUM,

Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here.

@nixusUM nixusUM marked this pull request as ready for review August 16, 2023 16:38
@larkox larkox requested a review from enahum August 17, 2023 12:08
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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import {General} from '@app/constants';
import {General} from '@constants';

Copy link
Contributor

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;
Copy link
Contributor

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

app/components/autocomplete/at_mention/at_mention.tsx Outdated Show resolved Hide resolved
Comment on lines 234 to 246
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();
};
Copy link
Contributor

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

Comment on lines 242 to 243
LEFT JOIN ${CHANNEL} c ON c.id=cm.id AND c.type='${General.DM_CHANNEL}'
LEFT JOIN ${MY_CHANNEL} my
Copy link
Contributor

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.

Comment on lines 309 to 310
const sortedMembersId = sortedMembers.map((e) => e.id);
const membersNoDm = receivedUsers.users.filter((u) => !sortedMembersId.includes(u.id));
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor

@enahum enahum left a 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';
Copy link
Contributor

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import {logError} from '@app/utils/log';
import {logError} from '@utils/log';

please update the import here

Comment on lines 234 to 252
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;
}
};
Copy link
Contributor

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

@enahum enahum requested a review from larkox August 18, 2023 13:07
@enahum enahum added 2: Dev Review Requires review by a core commiter 2: PM Review Requires review by a product manager 3: QA Review Requires review by a QA tester labels Aug 18, 2023
Copy link
Contributor

@larkox larkox left a 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.

Comment on lines 338 to 341
const teamMembers = useMemo(
() => [...usersInChannel, ...usersOutOfChannel],
[usersInChannel, usersOutOfChannel],
() => [...users],
[users],
);
Copy link
Contributor

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?

"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})",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes seem unrelated.

Copy link
Contributor

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.

@nixusUM nixusUM requested review from larkox and enahum August 23, 2023 08:19
@nixusUM nixusUM requested a review from larkox August 25, 2023 06:03
@nixusUM
Copy link
Contributor Author

nixusUM commented Aug 30, 2023

@enahum Hi, any update?

@enahum enahum removed the 2: Dev Review Requires review by a core commiter label Aug 30, 2023
@enahum
Copy link
Contributor

enahum commented Aug 30, 2023

@nixusUM please fix the lint problems

@larkox larkox requested a review from esethna August 31, 2023 08:22
@nixusUM
Copy link
Contributor Author

nixusUM commented Sep 4, 2023

@enahum Hi, I fixed lint problems

@mattermost-build
Copy link
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

@enahum
Copy link
Contributor

enahum commented Apr 30, 2024

@larkox what else is needed for us to merge this PR?

@larkox
Copy link
Contributor

larkox commented May 3, 2024

@enahum Nothing from my side I think. We are still missing @esethna review (I guess mostly to verify this is the expected behavior) and QA review. I will start the QA review process while we wait for the other review.

@esethna esethna removed the 2: PM Review Requires review by a product manager label May 3, 2024
Copy link

@esethna esethna left a 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.

@larkox larkox added 4: Reviews Complete All reviewers have approved the pull request and removed Lifecycle/1:stale 3: QA Review Requires review by a QA tester labels May 6, 2024
@larkox larkox merged commit 105073c into mattermost:main May 6, 2024
2 checks passed
@amyblais amyblais added this to the v2.17.0 milestone May 6, 2024
cyrusjc pushed a commit to cyrusjc/mattermost-mobile that referenced this pull request May 18, 2024
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request Contributor release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants