Skip to content

Commit f30bd01

Browse files
committed
notif [nfc]: Have tryStopNotifications take an Account object
Like its friend sendPushToken, which makes the api.savePushToken request. This prepares for a fix for #3469, "Removing account from list doesn't stop notifications", following the approach Greg outlined at #3469 (comment) .
1 parent dacce82 commit f30bd01

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/account-info/ProfileScreen.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import { tryStopNotifications } from '../notification/notifTokens';
1616
import AccountDetails from './AccountDetails';
1717
import { getRealm } from '../directSelectors';
1818
import { getOwnUser, getOwnUserId } from '../users/userSelectors';
19-
import { getAuth, getIdentity, getZulipFeatureLevel } from '../account/accountsSelectors';
19+
import { getAuth, getAccount, getZulipFeatureLevel } from '../account/accountsSelectors';
2020
import { useNavigation } from '../react-navigation';
2121
import { showConfirmationDialog } from '../utils/info';
2222
import { OfflineNoticePlaceholder } from '../boot/OfflineNoticeProvider';
2323
import { getUserStatus } from '../user-statuses/userStatusesModel';
2424
import SwitchRow from '../common/SwitchRow';
2525
import * as api from '../api';
26+
import { identityOfAccount } from '../account/accountMisc';
2627

2728
const styles = createStyleSheet({
2829
buttonRow: {
@@ -94,7 +95,8 @@ function SwitchAccountButton(props: {||}) {
9495
function LogoutButton(props: {||}) {
9596
const dispatch = useDispatch();
9697
const _ = useContext(TranslationContext);
97-
const identity = useSelector(getIdentity);
98+
const account = useSelector(getAccount);
99+
const identity = identityOfAccount(account);
98100
return (
99101
<ZulipButton
100102
style={styles.button}
@@ -109,7 +111,7 @@ function LogoutButton(props: {||}) {
109111
values: { email: identity.email, realmUrl: identity.realm.toString() },
110112
},
111113
onPressConfirm: () => {
112-
dispatch(tryStopNotifications());
114+
dispatch(tryStopNotifications(account));
113115
dispatch(logout());
114116
},
115117
_,

src/notification/notifTokens.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import type {
1717
} from '../types';
1818
import type { JSONable } from '../utils/jsonable';
1919
import * as api from '../api';
20-
import { getAuth } from '../selectors';
2120
import { getGlobalSession, getAccounts } from '../directSelectors';
2221
import { identityOfAccount, authOfAccount, identityOfAuth } from '../account/accountMisc';
2322
import { getAccount } from '../account/accountsSelectors';
@@ -230,9 +229,17 @@ export const handleDeviceToken =
230229
// your account, including notifications, even when you don't have the
231230
// device in your possession. That's zulip/zulip#17939.
232231
export const tryStopNotifications =
233-
(): ThunkAction<Promise<void>> => async (dispatch, getState) => {
234-
const auth = getAuth(getState());
235-
const { ackedPushToken } = getAccount(getState());
232+
(account: Account): GlobalThunkAction<Promise<void>> & ThunkAction<Promise<void>> =>
233+
// Why both GlobalThunkAction and ThunkAction? Well, this function is
234+
// per-account... but whereas virtually all our other per-account code is
235+
// implicitly about the active account, this is about a specific account
236+
// it's explicitly passed. That makes it equally legitimate to call from
237+
// per-account or global code.
238+
// TODO(#5006): Once we have per-account states for all accounts, make
239+
// this an ordinary per-account action.
240+
async dispatch => {
241+
const auth = authOfAccount(account);
242+
const { ackedPushToken } = account;
236243
if (ackedPushToken !== null) {
237244
dispatch(unackPushToken(identityOfAuth(auth)));
238245
try {

0 commit comments

Comments
 (0)