Merge pull request #3761 from mattermost/mentions-and-guests
Fix @-mentions in boards & for guests
This commit is contained in:
commit
270a110dc1
2 changed files with 27 additions and 8 deletions
|
@ -380,8 +380,8 @@ func (s *MattermostAuthLayer) SearchUsersByTeam(teamID string, searchQuery strin
|
|||
boardsIDs = append(boardsIDs, board.ID)
|
||||
}
|
||||
query = query.
|
||||
Join(s.tablePrefix + "board_members as bm ON bm.UserID = u.ID").
|
||||
Where(sq.Eq{"bm.BoardId": boardsIDs})
|
||||
Join(s.tablePrefix + "board_members as bm ON bm.user_id = u.ID").
|
||||
Where(sq.Eq{"bm.board_id": boardsIDs})
|
||||
}
|
||||
|
||||
rows, err := query.Query()
|
||||
|
@ -860,13 +860,22 @@ func (s *MattermostAuthLayer) GetBoardsForUserAndTeam(userID, teamID string, inc
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: Handle the includePublicBoards
|
||||
|
||||
boardIDs := []string{}
|
||||
for _, m := range members {
|
||||
boardIDs = append(boardIDs, m.BoardID)
|
||||
}
|
||||
|
||||
if includePublicBoards {
|
||||
var boards []*model.Board
|
||||
boards, err = s.SearchBoardsForUserInTeam(teamID, "", userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, b := range boards {
|
||||
boardIDs = append(boardIDs, b.ID)
|
||||
}
|
||||
}
|
||||
|
||||
boards, err := s.Store.GetBoardsInTeamByIds(boardIDs, teamID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -16,7 +16,7 @@ import {debounce} from "lodash"
|
|||
|
||||
import {useAppSelector} from '../../store/hooks'
|
||||
import {IUser} from '../../user'
|
||||
import {getBoardUsersList} from '../../store/users'
|
||||
import {getBoardUsersList, getMe} from '../../store/users'
|
||||
import createLiveMarkdownPlugin from '../live-markdown-plugin/liveMarkdownPlugin'
|
||||
|
||||
import './markdownEditorInput.scss'
|
||||
|
@ -37,6 +37,7 @@ type MentionUser = {
|
|||
name: string
|
||||
avatar: string
|
||||
is_bot: boolean
|
||||
is_guest: boolean
|
||||
displayName: string
|
||||
}
|
||||
|
||||
|
@ -55,20 +56,29 @@ const MarkdownEditorInput = (props: Props): ReactElement => {
|
|||
const board = useAppSelector(getCurrentBoard)
|
||||
const clientConfig = useAppSelector<ClientConfig>(getClientConfig)
|
||||
const ref = useRef<Editor>(null)
|
||||
const me = useAppSelector<IUser|null>(getMe)
|
||||
|
||||
const [suggestions, setSuggestions] = useState<Array<MentionUser>>([])
|
||||
|
||||
const loadSuggestions = async (term: string) => {
|
||||
let users: Array<IUser>
|
||||
|
||||
if (board && board.type === BoardTypeOpen) {
|
||||
if (!me?.is_guest && (board && board.type === BoardTypeOpen)) {
|
||||
users = await octoClient.searchTeamUsers(term)
|
||||
} else {
|
||||
users = boardUsers
|
||||
.filter(user => {
|
||||
// no search term
|
||||
if (!term) return true
|
||||
// does the search term occur anywhere in the display name?
|
||||
return Utils.getUserDisplayName(user, clientConfig.teammateNameDisplay).includes(term)
|
||||
})
|
||||
// first 10 results
|
||||
.slice(0, 10)
|
||||
}
|
||||
|
||||
const mentions = users.map(
|
||||
(user) => ({
|
||||
const mentions: Array<MentionUser> = users.map(
|
||||
(user: IUser): MentionUser => ({
|
||||
name: user.username,
|
||||
avatar: `${imageURLForUser ? imageURLForUser(user.id) : ''}`,
|
||||
is_bot: user.is_bot,
|
||||
|
|
Loading…
Reference in a new issue