@@ -38,8 +38,8 @@ export type ShowActionSheetWithOptions = (
38
38
39
39
type TopicArgs = {
40
40
auth : Auth ,
41
- stream : string ,
42
41
topic : string ,
42
+ streamId ?: number ,
43
43
subscriptions : Subscription [ ] ,
44
44
dispatch : Dispatch ,
45
45
_ : GetText ,
@@ -119,28 +119,33 @@ const deleteMessage = async ({ auth, message, dispatch }) => {
119
119
deleteMessage . title = 'Delete message' ;
120
120
deleteMessage . errorMessage = 'Failed to delete message' ;
121
121
122
- const markTopicAsRead = async ( { auth, stream, topic, subscriptions } ) => {
123
- const sub = subscriptions . find ( x => x . name === stream ) ;
124
- if ( sub ) {
125
- await api . markTopicAsRead ( auth , sub . stream_id , topic ) ;
122
+ const markTopicAsRead = async ( { auth, streamId, topic, subscriptions } ) => {
123
+ if ( streamId !== undefined ) {
124
+ await api . markTopicAsRead ( auth , streamId , topic ) ;
126
125
}
127
126
} ;
128
127
markTopicAsRead . title = 'Mark topic as read' ;
129
128
markTopicAsRead . errorMessage = 'Failed to mark topic as read' ;
130
129
131
- const unmuteTopic = async ( { auth, stream, topic } ) => {
132
- await api . unmuteTopic ( auth , stream , topic ) ;
130
+ const unmuteTopic = async ( { auth, streamId, topic, subscriptions } ) => {
131
+ const sub = subscriptions . find ( x => x . stream_id === streamId ) ;
132
+ if ( sub ) {
133
+ await api . unmuteTopic ( auth , sub . name , topic ) ;
134
+ }
133
135
} ;
134
136
unmuteTopic . title = 'Unmute topic' ;
135
137
unmuteTopic . errorMessage = 'Failed to unmute topic' ;
136
138
137
- const muteTopic = async ( { auth, stream, topic } ) => {
138
- await api . muteTopic ( auth , stream , topic ) ;
139
+ const muteTopic = async ( { auth, streamId, topic, subscriptions } ) => {
140
+ const sub = subscriptions . find ( x => x . stream_id === streamId ) ;
141
+ if ( sub ) {
142
+ await api . muteTopic ( auth , sub . name , topic ) ;
143
+ }
139
144
} ;
140
145
muteTopic . title = 'Mute topic' ;
141
146
muteTopic . errorMessage = 'Failed to mute topic' ;
142
147
143
- const deleteTopic = async ( { auth, stream , topic, dispatch, _ } ) => {
148
+ const deleteTopic = async ( { auth, streamId , topic, subscriptions , dispatch, _ } ) => {
144
149
const alertTitle = _ ( 'Are you sure you want to delete the topic “{topic}”?' , { topic } ) ;
145
150
const AsyncAlert = async ( ) : Promise < boolean > =>
146
151
new Promise ( ( resolve , reject ) => {
@@ -167,34 +172,34 @@ const deleteTopic = async ({ auth, stream, topic, dispatch, _ }) => {
167
172
) ;
168
173
} ) ;
169
174
if ( await AsyncAlert ( ) ) {
170
- await dispatch ( deleteMessagesForTopic ( stream , topic ) ) ;
175
+ const sub = subscriptions . find ( x => x . stream_id === streamId ) ;
176
+ if ( sub ) {
177
+ await dispatch ( deleteMessagesForTopic ( sub . name , topic ) ) ;
178
+ }
171
179
}
172
180
} ;
173
181
deleteTopic . title = 'Delete topic' ;
174
182
deleteTopic . errorMessage = 'Failed to delete topic' ;
175
183
176
- const unmuteStream = async ( { auth, stream, subscriptions } ) => {
177
- const sub = subscriptions . find ( x => x . name === stream ) ;
178
- if ( sub ) {
179
- await api . toggleMuteStream ( auth , sub . stream_id , false ) ;
184
+ const unmuteStream = async ( { auth, streamId, subscriptions } ) => {
185
+ if ( streamId !== undefined ) {
186
+ await api . toggleMuteStream ( auth , streamId , false ) ;
180
187
}
181
188
} ;
182
189
unmuteStream . title = 'Unmute stream' ;
183
190
unmuteStream . errorMessage = 'Failed to unmute stream' ;
184
191
185
- const muteStream = async ( { auth, stream, subscriptions } ) => {
186
- const sub = subscriptions . find ( x => x . name === stream ) ;
187
- if ( sub ) {
188
- await api . toggleMuteStream ( auth , sub . stream_id , true ) ;
192
+ const muteStream = async ( { auth, streamId, subscriptions } ) => {
193
+ if ( streamId !== undefined ) {
194
+ await api . toggleMuteStream ( auth , streamId , true ) ;
189
195
}
190
196
} ;
191
197
muteStream . title = 'Mute stream' ;
192
198
muteStream . errorMessage = 'Failed to mute stream' ;
193
199
194
- const showStreamSettings = ( { stream, subscriptions } ) => {
195
- const sub = subscriptions . find ( x => x . name === stream ) ;
196
- if ( sub ) {
197
- NavigationService . dispatch ( navigateToStream ( sub . stream_id ) ) ;
200
+ const showStreamSettings = ( { streamId, subscriptions } ) => {
201
+ if ( streamId !== undefined ) {
202
+ NavigationService . dispatch ( navigateToStream ( streamId ) ) ;
198
203
}
199
204
} ;
200
205
showStreamSettings . title = 'Stream settings' ;
@@ -238,8 +243,8 @@ cancel.errorMessage = 'Failed to hide menu';
238
243
239
244
export const constructTopicActionButtons = ( {
240
245
backgroundData : { mute, subscriptions, ownUser, unreadStreams } ,
241
- stream,
242
246
topic,
247
+ streamId,
243
248
} : { |
244
249
backgroundData : $ReadOnly < {
245
250
mute : MuteState ,
@@ -248,29 +253,29 @@ export const constructTopicActionButtons = ({
248
253
unreadStreams : UnreadStreamsState ,
249
254
...
250
255
} > ,
251
- stream : string ,
256
+ streamId ? : number ,
252
257
topic : string ,
253
258
| } ) : Button < TopicArgs > [ ] = > {
259
+ const sub = subscriptions . find ( x => x . stream_id === streamId ) ;
254
260
const buttons = [ ] ;
255
261
if ( ownUser . is_admin ) {
256
262
buttons . push ( deleteTopic ) ;
257
263
}
258
- if ( isTopicMuted ( stream , topic , mute ) ) {
264
+ if ( sub && isTopicMuted ( sub . name , topic , mute ) ) {
259
265
buttons . push ( unmuteTopic ) ;
260
266
} else {
261
267
buttons . push ( muteTopic ) ;
262
268
}
263
- const sub = subscriptions . find ( x => x . name === stream ) ;
264
- if ( sub ) {
265
- const unreadCount = unreadStreams . get ( sub . stream_id ) ?. get ( topic ) ?. size ;
269
+ if ( streamId !== undefined ) {
270
+ const unreadCount = unreadStreams . get ( streamId ) ?. get ( topic ) ?. size ;
266
271
if ( unreadCount !== undefined && unreadCount > 0 ) {
267
272
buttons . push ( markTopicAsRead ) ;
268
273
}
269
- if ( ! sub . in_home_view ) {
270
- buttons . push ( unmuteStream ) ;
271
- } else {
272
- buttons . push ( muteStream ) ;
273
- }
274
+ }
275
+ if ( sub && ! sub . in_home_view ) {
276
+ buttons . push ( unmuteStream ) ;
277
+ } else {
278
+ buttons . push ( muteStream ) ;
274
279
}
275
280
buttons . push ( showStreamSettings ) ;
276
281
buttons . push ( cancel ) ;
@@ -411,7 +416,7 @@ export const showTopicActionSheet = ({
411
416
callbacks ,
412
417
backgroundData ,
413
418
topic ,
414
- stream ,
419
+ streamId ,
415
420
} : { |
416
421
showActionSheetWithOptions : ShowActionSheetWithOptions ,
417
422
callbacks : { |
@@ -427,12 +432,17 @@ export const showTopicActionSheet = ({
427
432
unreadStreams : UnreadStreamsState ,
428
433
...
429
434
} > ,
430
- stream : string ,
435
+ streamId ? : number ,
431
436
topic : string ,
432
437
| } ): void => {
438
+ const sub = backgroundData . subscriptions . find ( x => x . stream_id === streamId ) ;
439
+ if ( sub === undefined ) {
440
+ return ;
441
+ }
442
+ const stream = sub.name;
433
443
const buttonList = constructTopicActionButtons({
434
444
backgroundData ,
435
- stream ,
445
+ streamId ,
436
446
topic ,
437
447
} );
438
448
showActionSheetWithOptions(
@@ -444,7 +454,7 @@ export const showTopicActionSheet = ({
444
454
makeButtonCallback ( buttonList , {
445
455
...backgroundData ,
446
456
...callbacks ,
447
- stream ,
457
+ streamId ,
448
458
topic,
449
459
} ) ,
450
460
) ;
0 commit comments