@@ -3,7 +3,11 @@ import type { GraphQLContext } from '../../';
33import UserError from '../../utils/UserError' ;
44import { getThread , moveThread } from '../../models/thread' ;
55import { getUserPermissionsInCommunity } from '../../models/usersCommunities' ;
6- import { getChannels } from '../../models/channel' ;
6+ import { getChannelById } from '../../models/channel' ;
7+ import {
8+ getCommunityById ,
9+ setPinnedThreadInCommunity ,
10+ } from '../../models/community' ;
711import { isAuthedResolver as requireAuth } from '../../utils/permissions' ;
812import { events } from 'shared/analytics' ;
913import { trackQueue } from 'shared/bull/queues' ;
@@ -18,6 +22,7 @@ export default requireAuth(async (_: any, args: Input, ctx: GraphQLContext) => {
1822 const { threadId, channelId } = args ;
1923
2024 const thread = await getThread ( threadId ) ;
25+
2126 if ( ! thread ) {
2227 trackQueue . add ( {
2328 userId : user . id ,
@@ -65,7 +70,11 @@ export default requireAuth(async (_: any, args: Input, ctx: GraphQLContext) => {
6570 ) ;
6671 }
6772
68- const [ newChannel ] = await getChannels ( [ channelId ] ) ;
73+ const [ newChannel , community ] = await Promise . all ( [
74+ getChannelById ( channelId ) ,
75+ getCommunityById ( thread . communityId ) ,
76+ ] ) ;
77+
6978 if ( newChannel . communityId !== thread . communityId ) {
7079 trackQueue . add ( {
7180 userId : user . id ,
@@ -81,6 +90,16 @@ export default requireAuth(async (_: any, args: Input, ctx: GraphQLContext) => {
8190 ) ;
8291 }
8392
93+ // if the thread is being moved into a private channel, make sure it is not pinned
94+ // in the community
95+ if (
96+ newChannel . isPrivate &&
97+ community . pinnedThreadId &&
98+ thread . id === community . pinnedThreadId
99+ ) {
100+ await setPinnedThreadInCommunity ( thread . communityId , null , user . id ) ;
101+ }
102+
84103 return moveThread ( threadId , channelId , user . id ) . then ( res => {
85104 if ( res ) return res ;
86105
0 commit comments