@@ -39,7 +39,8 @@ export type ShowActionSheetWithOptions = (
39
39
40
40
type HeaderArgs = {
41
41
auth : Auth ,
42
- message : Message | Outbox ,
42
+ stream : string ,
43
+ topic : string ,
43
44
subscriptions : Subscription [ ] ,
44
45
dispatch : Dispatch ,
45
46
_ : GetText ,
@@ -112,25 +113,20 @@ const deleteMessage = async ({ auth, message, dispatch }) => {
112
113
deleteMessage . title = 'Delete message' ;
113
114
deleteMessage . errorMessage = 'Failed to delete message' ;
114
115
115
- const unmuteTopic = async ( { auth, message } ) => {
116
- invariant ( message . type === 'stream' , 'unmuteTopic: got PM' ) ;
117
- await api . unmuteTopic ( auth , streamNameOfStreamMessage ( message ) , message . subject ) ;
116
+ const unmuteTopic = async ( { auth, stream, topic } ) => {
117
+ await api . unmuteTopic ( auth , stream , topic ) ;
118
118
} ;
119
119
unmuteTopic . title = 'Unmute topic' ;
120
120
unmuteTopic . errorMessage = 'Failed to unmute topic' ;
121
121
122
- const muteTopic = async ( { auth, message } ) => {
123
- invariant ( message . type === 'stream' , 'muteTopic: got PM' ) ;
124
- await api . muteTopic ( auth , streamNameOfStreamMessage ( message ) , message . subject ) ;
122
+ const muteTopic = async ( { auth, stream, topic } ) => {
123
+ await api . muteTopic ( auth , stream , topic ) ;
125
124
} ;
126
125
muteTopic . title = 'Mute topic' ;
127
126
muteTopic . errorMessage = 'Failed to mute topic' ;
128
127
129
- const deleteTopic = async ( { auth, message, dispatch, _ } ) => {
130
- invariant ( message . type === 'stream' , 'deleteTopic: got PM' ) ;
131
- const alertTitle = _ ( 'Are you sure you want to delete the topic “{topic}”?' , {
132
- topic : message . subject ,
133
- } ) ;
128
+ const deleteTopic = async ( { auth, stream, topic, dispatch, _ } ) => {
129
+ const alertTitle = _ ( 'Are you sure you want to delete the topic “{topic}”?' , { topic } ) ;
134
130
const AsyncAlert = async ( ) : Promise < boolean > =>
135
131
new Promise ( ( resolve , reject ) => {
136
132
Alert . alert (
@@ -156,25 +152,23 @@ const deleteTopic = async ({ auth, message, dispatch, _ }) => {
156
152
) ;
157
153
} ) ;
158
154
if ( await AsyncAlert ( ) ) {
159
- await dispatch ( deleteMessagesForTopic ( streamNameOfStreamMessage ( message ) , message . subject ) ) ;
155
+ await dispatch ( deleteMessagesForTopic ( stream , topic ) ) ;
160
156
}
161
157
} ;
162
158
deleteTopic . title = 'Delete topic' ;
163
159
deleteTopic . errorMessage = 'Failed to delete topic' ;
164
160
165
- const unmuteStream = async ( { auth, message, subscriptions } ) => {
166
- invariant ( message . type === 'stream' , 'unmuteStream: got PM' ) ;
167
- const sub = subscriptions . find ( x => x . name === streamNameOfStreamMessage ( message ) ) ;
161
+ const unmuteStream = async ( { auth, stream, subscriptions } ) => {
162
+ const sub = subscriptions . find ( x => x . name === stream ) ;
168
163
if ( sub ) {
169
164
await api . toggleMuteStream ( auth , sub . stream_id , false ) ;
170
165
}
171
166
} ;
172
167
unmuteStream . title = 'Unmute stream' ;
173
168
unmuteStream . errorMessage = 'Failed to unmute stream' ;
174
169
175
- const muteStream = async ( { auth, message, subscriptions } ) => {
176
- invariant ( message . type === 'stream' , 'muteStream: got PM' ) ;
177
- const sub = subscriptions . find ( x => x . name === streamNameOfStreamMessage ( message ) ) ;
170
+ const muteStream = async ( { auth, stream, subscriptions } ) => {
171
+ const sub = subscriptions . find ( x => x . name === stream ) ;
178
172
if ( sub ) {
179
173
await api . toggleMuteStream ( auth , sub . stream_id , true ) ;
180
174
}
@@ -409,7 +403,8 @@ export const showHeaderActionSheet = ({
409
403
await pressedButton ( {
410
404
...backgroundData ,
411
405
...callbacks ,
412
- message,
406
+ stream : streamNameOfStreamMessage ( message ) ,
407
+ topic : message . subject ,
413
408
} ) ;
414
409
} catch (err) {
415
410
Alert . alert ( callbacks . _ ( pressedButton . errorMessage ) , err . message ) ;
0 commit comments