@@ -11,6 +11,10 @@ import { getChannelsByUserAndCommunity } from '../../models/channel';
1111import { isAuthedResolver as requireAuth } from '../../utils/permissions' ;
1212import { events } from 'shared/analytics' ;
1313import { trackQueue } from 'shared/bull/queues' ;
14+ import {
15+ getThreadNotificationStatusForUser ,
16+ updateThreadNotificationStatusForUser ,
17+ } from '../../models/usersThreads' ;
1418
1519type Input = {
1620 input : {
@@ -105,14 +109,41 @@ export default requireAuth(async (_: any, args: Input, ctx: GraphQLContext) => {
105109 communityId ,
106110 user . id
107111 ) ;
112+
108113 const leaveChannelsPromises = allChannelsInCommunity . map ( channel =>
109114 removeMemberInChannel ( channel , user . id )
110115 ) ;
111116
112117 return await Promise . all ( [
113118 removeMemberInCommunity ( communityId , user . id ) ,
114119 ...leaveChannelsPromises ,
115- ] ) . then ( ( ) => community ) ;
120+ ] )
121+ . then ( async ( ) => {
122+ // if the community has a watercooler and the current user has a subscription
123+ // to it, remove the subscription
124+ if ( community . watercoolerId ) {
125+ const threadId = community . watercoolerId ;
126+ const threadNotificationStatus = await getThreadNotificationStatusForUser (
127+ threadId ,
128+ user . id
129+ ) ;
130+ if (
131+ ! threadNotificationStatus ||
132+ ! threadNotificationStatus . receiveNotifications
133+ ) {
134+ return ;
135+ }
136+
137+ return await updateThreadNotificationStatusForUser (
138+ threadId ,
139+ user . id ,
140+ false
141+ ) ;
142+ }
143+
144+ return ;
145+ } )
146+ . then ( ( ) => community ) ;
116147 }
117148
118149 trackQueue . add ( {
0 commit comments