@@ -39,8 +39,8 @@ export type ShowActionSheetWithOptions = (
39
39
40
40
type TopicArgs = {
41
41
auth : Auth ,
42
- stream : string ,
43
42
topic : string ,
43
+ streamId : number ,
44
44
subscriptions : Subscription [ ] ,
45
45
dispatch : Dispatch ,
46
46
_ : GetText ,
@@ -120,34 +120,25 @@ const deleteMessage = async ({ auth, message, dispatch }) => {
120
120
deleteMessage . title = 'Delete message' ;
121
121
deleteMessage . errorMessage = 'Failed to delete message' ;
122
122
123
- const markTopicAsRead = async ( { auth, stream, topic, subscriptions } ) => {
124
- const sub = subscriptions . find ( x => x . name === stream ) ;
125
- if ( sub ) {
126
- await api . markTopicAsRead ( auth , sub . stream_id , topic ) ;
127
- }
123
+ const markTopicAsRead = async ( { auth, streamId, topic } ) => {
124
+ await api . markTopicAsRead ( auth , streamId , topic ) ;
128
125
} ;
129
126
markTopicAsRead . title = 'Mark topic as read' ;
130
127
markTopicAsRead . errorMessage = 'Failed to mark topic as read' ;
131
128
132
- const unmuteTopic = async ( { auth, stream, topic, subscriptions } ) => {
133
- const sub = subscriptions . find ( x => x . name === stream ) ;
134
- if ( sub ) {
135
- await api . setTopicMute ( auth , sub . stream_id , topic , false ) ;
136
- }
129
+ const unmuteTopic = async ( { auth, streamId, topic } ) => {
130
+ await api . setTopicMute ( auth , streamId , topic , false ) ;
137
131
} ;
138
132
unmuteTopic . title = 'Unmute topic' ;
139
133
unmuteTopic . errorMessage = 'Failed to unmute topic' ;
140
134
141
- const muteTopic = async ( { auth, stream, topic, subscriptions } ) => {
142
- const sub = subscriptions . find ( x => x . name === stream ) ;
143
- if ( sub ) {
144
- await api . setTopicMute ( auth , sub . stream_id , topic , true ) ;
145
- }
135
+ const muteTopic = async ( { auth, streamId, topic } ) => {
136
+ await api . setTopicMute ( auth , streamId , topic , true ) ;
146
137
} ;
147
138
muteTopic . title = 'Mute topic' ;
148
139
muteTopic . errorMessage = 'Failed to mute topic' ;
149
140
150
- const deleteTopic = async ( { auth, stream , topic, subscriptions , dispatch, _ } ) => {
141
+ const deleteTopic = async ( { auth, streamId , topic, dispatch, _ } ) => {
151
142
const alertTitle = _ ( 'Are you sure you want to delete the topic “{topic}”?' , { topic } ) ;
152
143
const AsyncAlert = async ( ) : Promise < boolean > =>
153
144
new Promise ( ( resolve , reject ) => {
@@ -174,37 +165,26 @@ const deleteTopic = async ({ auth, stream, topic, subscriptions, dispatch, _ })
174
165
) ;
175
166
} ) ;
176
167
if ( await AsyncAlert ( ) ) {
177
- const sub = subscriptions . find ( x => x . name === stream ) ;
178
- invariant ( sub !== undefined , 'Stream with provided name not found.' ) ;
179
- await dispatch ( deleteMessagesForTopic ( sub . stream_id , topic ) ) ;
168
+ await dispatch ( deleteMessagesForTopic ( streamId , topic ) ) ;
180
169
}
181
170
} ;
182
171
deleteTopic . title = 'Delete topic' ;
183
172
deleteTopic . errorMessage = 'Failed to delete topic' ;
184
173
185
- const unmuteStream = async ( { auth, stream, subscriptions } ) => {
186
- const sub = subscriptions . find ( x => x . name === stream ) ;
187
- if ( sub ) {
188
- await api . setSubscriptionProperty ( auth , sub . stream_id , 'is_muted' , false ) ;
189
- }
174
+ const unmuteStream = async ( { auth, streamId } ) => {
175
+ await api . setSubscriptionProperty ( auth , streamId , 'is_muted' , false ) ;
190
176
} ;
191
177
unmuteStream . title = 'Unmute stream' ;
192
178
unmuteStream . errorMessage = 'Failed to unmute stream' ;
193
179
194
- const muteStream = async ( { auth, stream, subscriptions } ) => {
195
- const sub = subscriptions . find ( x => x . name === stream ) ;
196
- if ( sub ) {
197
- await api . setSubscriptionProperty ( auth , sub . stream_id , 'is_muted' , true ) ;
198
- }
180
+ const muteStream = async ( { auth, streamId } ) => {
181
+ await api . setSubscriptionProperty ( auth , streamId , 'is_muted' , true ) ;
199
182
} ;
200
183
muteStream . title = 'Mute stream' ;
201
184
muteStream . errorMessage = 'Failed to mute stream' ;
202
185
203
- const showStreamSettings = ( { stream, subscriptions } ) => {
204
- const sub = subscriptions . find ( x => x . name === stream ) ;
205
- if ( sub ) {
206
- NavigationService . dispatch ( navigateToStream ( sub . stream_id ) ) ;
207
- }
186
+ const showStreamSettings = ( { streamId } ) => {
187
+ NavigationService . dispatch ( navigateToStream ( streamId ) ) ;
208
188
} ;
209
189
showStreamSettings . title = 'Stream settings' ;
210
190
showStreamSettings . errorMessage = 'Failed to show stream settings' ;
@@ -247,8 +227,8 @@ cancel.errorMessage = 'Failed to hide menu';
247
227
248
228
export const constructTopicActionButtons = ( {
249
229
backgroundData : { mute, subscriptions, ownUser, unreadStreams } ,
250
- stream,
251
230
topic,
231
+ streamId,
252
232
} : { |
253
233
backgroundData : $ReadOnly < {
254
234
mute : MuteState ,
@@ -257,29 +237,29 @@ export const constructTopicActionButtons = ({
257
237
unreadStreams : UnreadStreamsState ,
258
238
...
259
239
} > ,
260
- stream : string ,
240
+ streamId : number ,
261
241
topic : string ,
262
242
| } ) : Button < TopicArgs > [ ] = > {
243
+ const sub = subscriptions . find ( x => x . stream_id === streamId ) ;
244
+ invariant ( sub , 'Subscription with provided stream id does not exist.' ) ;
245
+
263
246
const buttons = [ ] ;
264
247
if ( ownUser . is_admin ) {
265
248
buttons . push ( deleteTopic ) ;
266
249
}
267
- if ( isTopicMuted ( stream , topic , mute ) ) {
250
+ if ( isTopicMuted ( sub . name , topic , mute ) ) {
268
251
buttons . push ( unmuteTopic ) ;
269
252
} else {
270
253
buttons . push ( muteTopic ) ;
271
254
}
272
- const sub = subscriptions . find ( x => x . name === stream ) ;
273
- if ( sub ) {
274
- const unreadCount = unreadStreams . get ( sub . stream_id ) ?. get ( topic ) ?. size ;
275
- if ( unreadCount !== undefined && unreadCount > 0 ) {
276
- buttons . push ( markTopicAsRead ) ;
277
- }
278
- if ( ! sub . in_home_view ) {
279
- buttons . push ( unmuteStream ) ;
280
- } else {
281
- buttons . push ( muteStream ) ;
282
- }
255
+ const unreadCount = unreadStreams . get ( streamId ) ?. get ( topic ) ?. size ;
256
+ if ( unreadCount !== undefined && unreadCount > 0 ) {
257
+ buttons . push ( markTopicAsRead ) ;
258
+ }
259
+ if ( ! sub . in_home_view ) {
260
+ buttons . push ( unmuteStream ) ;
261
+ } else {
262
+ buttons . push ( muteStream ) ;
283
263
}
284
264
buttons . push ( showStreamSettings ) ;
285
265
buttons . push ( cancel ) ;
@@ -420,7 +400,7 @@ export const showTopicActionSheet = ({
420
400
callbacks ,
421
401
backgroundData ,
422
402
topic ,
423
- stream ,
403
+ streamId ,
424
404
} : { |
425
405
showActionSheetWithOptions : ShowActionSheetWithOptions ,
426
406
callbacks : { |
@@ -436,12 +416,15 @@ export const showTopicActionSheet = ({
436
416
unreadStreams : UnreadStreamsState ,
437
417
...
438
418
} > ,
439
- stream : string ,
419
+ streamId : number ,
440
420
topic : string ,
441
421
| } ): void => {
422
+ const sub = backgroundData . subscriptions . find ( x => x . stream_id === streamId ) ;
423
+ invariant ( sub , 'Subscription with provided stream id does not exist.' ) ;
424
+ const stream = sub . name ;
442
425
const buttonList = constructTopicActionButtons ( {
443
426
backgroundData,
444
- stream ,
427
+ streamId ,
445
428
topic,
446
429
} ) ;
447
430
showActionSheetWithOptions (
@@ -453,7 +436,7 @@ export const showTopicActionSheet = ({
453
436
makeButtonCallback ( buttonList , {
454
437
...backgroundData ,
455
438
...callbacks ,
456
- stream ,
439
+ streamId ,
457
440
topic,
458
441
} ) ,
459
442
) ;
0 commit comments