Skip to content

Commit ec1ba3c

Browse files
committed
mute: Drop muted_topics events when obsolete
This avoids clobbering the state of topics that have newer types of policies.
1 parent 8e19bdb commit ec1ba3c

File tree

2 files changed

+28
-42
lines changed

2 files changed

+28
-42
lines changed

src/mute/__tests__/muteModel-test.js

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -150,52 +150,25 @@ describe('reducer', () => {
150150
initialState,
151151
);
152152
});
153+
});
153154

154-
describe('redundantly after EVENT_MUTED_TOPICS', () => {
155-
// The server may send both muted_topics events and user_topic events,
156-
// because we don't set event_types in our /register request:
157-
// https://github.com/zulip/zulip/pull/21251#issuecomment-1133466148
158-
// So we may get one of these after a muted_topics event has already
159-
// set the new state.
160-
//
161-
// (Or we might get user_topic first and then muted_topics, but that
162-
// doesn't require any testing of its own -- when handling the
163-
// muted_topics event it doesn't matter what the previous state was.)
164-
165-
test('add', () => {
166-
check(
167-
makeMuteState([[eg.stream, 'topic']]),
168-
makeUserTopic(eg.stream, 'topic', UserTopicVisibilityPolicy.Muted),
169-
makeMuteState([[eg.stream, 'topic']]),
170-
);
171-
});
172-
173-
test('remove, leaving others in stream', () => {
174-
check(
175-
makeMuteState([[eg.stream, 'topic']]),
176-
makeUserTopic(eg.stream, 'other topic', UserTopicVisibilityPolicy.None),
177-
makeMuteState([[eg.stream, 'topic']]),
178-
);
179-
});
155+
describe('EVENT_MUTED_TOPICS (legacy)', () => {
156+
const action = deepFreeze({
157+
type: EVENT_MUTED_TOPICS,
158+
id: -1,
159+
muted_topics: [[eg.stream.name, 'topic']],
160+
});
180161

181-
test('remove, as last in stream', () => {
182-
check(
183-
makeMuteState([]),
184-
makeUserTopic(eg.stream, 'topic', UserTopicVisibilityPolicy.None),
185-
makeMuteState([]),
186-
);
187-
});
162+
test('ignored when on a current server', () => {
163+
expect(reducer(initialState, action, eg.plusReduxState)).toEqual(initialState);
188164
});
189-
});
190165

191-
describe('EVENT_MUTED_TOPICS (legacy)', () => {
192-
test('appends and test a new muted topic', () => {
193-
const action = deepFreeze({
194-
type: EVENT_MUTED_TOPICS,
195-
id: -1,
196-
muted_topics: [[eg.stream.name, 'topic']],
166+
test('sets the state, when on an old server lacking user_topic', () => {
167+
const globalState = eg.reduxStatePlus({
168+
// TODO(server-6.0): We'll drop this muted_topics event type entirely.
169+
accounts: [{ ...eg.plusReduxState.accounts[0], zulipFeatureLevel: 133 }],
197170
});
198-
expect(reducer(initialState, action, eg.plusReduxState)).toEqual(
171+
expect(reducer(initialState, action, globalState)).toEqual(
199172
makeMuteState([[eg.stream, 'topic']]),
200173
);
201174
});

src/mute/muteModel.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { getStreamsByName } from '../subscriptions/subscriptionSelectors';
1414
import * as logging from '../utils/logging';
1515
import DefaultMap from '../utils/DefaultMap';
1616
import { updateAndPrune } from '../immutableUtils';
17+
import { getZulipFeatureLevel } from '../account/accountsSelectors';
1718

1819
//
1920
//
@@ -119,8 +120,20 @@ export const reducer = (
119120
getStreamsByName(globalState),
120121
);
121122

122-
case EVENT_MUTED_TOPICS:
123+
case EVENT_MUTED_TOPICS: {
124+
if (getZulipFeatureLevel(globalState) >= 134) {
125+
// TODO(server-6.0): Drop this muted_topics event type entirely.
126+
// This event type is obsoleted by `user_topic`, so we can ignore it.
127+
//
128+
// The server sends both types of events, because we
129+
// don't set event_types in our /register request:
130+
// https://github.com/zulip/zulip/pull/21251#issuecomment-1133466148
131+
// But if we interpreted the muted_topics events as usual,
132+
// we'd throw away all policies other than None or Muted.
133+
return state;
134+
}
123135
return convertLegacy(action.muted_topics, getStreamsByName(globalState));
136+
}
124137

125138
case EVENT: {
126139
const { event } = action;

0 commit comments

Comments
 (0)