@@ -3,7 +3,11 @@ import type { GraphQLContext } from '../../';
3
3
import UserError from '../../utils/UserError' ;
4
4
import { getThread , moveThread } from '../../models/thread' ;
5
5
import { 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' ;
7
11
import { isAuthedResolver as requireAuth } from '../../utils/permissions' ;
8
12
import { events } from 'shared/analytics' ;
9
13
import { trackQueue } from 'shared/bull/queues' ;
@@ -18,6 +22,7 @@ export default requireAuth(async (_: any, args: Input, ctx: GraphQLContext) => {
18
22
const { threadId, channelId } = args ;
19
23
20
24
const thread = await getThread ( threadId ) ;
25
+
21
26
if ( ! thread ) {
22
27
trackQueue . add ( {
23
28
userId : user . id ,
@@ -65,7 +70,11 @@ export default requireAuth(async (_: any, args: Input, ctx: GraphQLContext) => {
65
70
) ;
66
71
}
67
72
68
- const [ newChannel ] = await getChannels ( [ channelId ] ) ;
73
+ const [ newChannel , community ] = await Promise . all ( [
74
+ getChannelById ( channelId ) ,
75
+ getCommunityById ( thread . communityId ) ,
76
+ ] ) ;
77
+
69
78
if ( newChannel . communityId !== thread . communityId ) {
70
79
trackQueue . add ( {
71
80
userId : user . id ,
@@ -81,6 +90,16 @@ export default requireAuth(async (_: any, args: Input, ctx: GraphQLContext) => {
81
90
) ;
82
91
}
83
92
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
+
84
103
return moveThread ( threadId , channelId , user . id ) . then ( res => {
85
104
if ( res ) return res ;
86
105
0 commit comments