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

Showing properly channel association in DMs and GMs #3529

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions server/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/mattermost/focalboard/server/services/permissions"
"github.com/mattermost/focalboard/server/utils"

mmModel "github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/shared/mlog"
)

Expand Down Expand Up @@ -2389,8 +2390,10 @@ func (a *API) handleGetChannel(w http.ResponseWriter, r *http.Request) {
)

if channel.TeamId != teamID {
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
return
if channel.Type != mmModel.ChannelTypeDirect && channel.Type != mmModel.ChannelTypeGroup {
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
return
}
}

data, err := json.Marshal(channel)
Expand Down
30 changes: 28 additions & 2 deletions webapp/src/components/shareBoard/channelPermissionsRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Menu from '../../widgets/menu'
import {createBoard} from '../../blocks/board'
import {useAppSelector} from '../../store/hooks'
import {getCurrentBoard} from '../../store/boards'
import {getBoardUsers} from '../../store/users'
import {Channel} from '../../store/channels'
import {Utils} from '../../utils'
import mutator from '../../mutator'
Expand All @@ -24,9 +25,14 @@ import ConfirmationDialogBox from "../confirmationDialogBox"

import BoardPermissionGate from '../permissions/boardPermissionGate'

const ChannelPermissionsRow = (): JSX.Element => {
type Props = {
teammateNameDisplay: string,
}

const ChannelPermissionsRow = (props: Props): JSX.Element => {
const intl = useIntl()
const board = useAppSelector(getCurrentBoard)
const users = useAppSelector(getBoardUsers)
const [linkedChannel, setLinkedChannel] = useState<Channel|null>(null)
const [showUnlinkChannelConfirmation, setShowUnlinkChannelConfirmation] = useState<boolean>(false)

Expand Down Expand Up @@ -72,15 +78,35 @@ const ChannelPermissionsRow = (): JSX.Element => {
/>
)

const getDMName = () => {
const userIds = linkedChannel.name.split("__")
if (userIds.length !== 2) {
Utils.logError('Invalid DM channel name, unable to get user ids')
}
let result = Utils.getUserDisplayName(users[userIds[0]], props.teammateNameDisplay)
result += ", "
result += Utils.getUserDisplayName(users[userIds[1]], props.teammateNameDisplay)
return result
}

return (
<div className='user-item channel-item'>
{showUnlinkChannelConfirmation && confirmationDialog}
<div className='user-item__content'>
<span className='user-item__img'>
{linkedChannel.type === 'P' && <PrivateIcon/>}
{linkedChannel.type === 'O' && <PublicIcon/>}
{linkedChannel.type === 'D' && <PrivateIcon/>}
{linkedChannel.type === 'G' && <PrivateIcon/>}
</span>
<div className='ml-3'><strong>{linkedChannel.display_name}</strong></div>
{linkedChannel.type === 'D' && (
<div className='ml-3'>
<strong>
{getDMName()}
</strong>
</div>
)}
{linkedChannel.type !== 'D' && <div className='ml-3'><strong>{linkedChannel.display_name}</strong></div>}
</div>
<div>
<BoardPermissionGate permissions={[Permission.ManageBoardRoles]}>
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/shareBoard/shareBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export default function ShareBoardDialog(props: Props): JSX.Element {
</BoardPermissionGate>
<div className='user-items'>
<TeamPermissionsRow/>
<ChannelPermissionsRow/>
<ChannelPermissionsRow teammateNameDisplay={me?.props?.teammateNameDisplay || clientConfig.teammateNameDisplay}/>

{boardUsers.map((user) => {
if (!members[user.id]) {
Expand Down