Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(push): scope read clears to the enrolled cohort (#2935)

Hampus963ffc555010
diff --git a/fluxer_gateway/src/gateway/fluxer_gateway_config.erl b/fluxer_gateway/src/gateway/fluxer_gateway_config.erl
index f33bfe2f1..6ec671df4 100644
--- a/fluxer_gateway/src/gateway/fluxer_gateway_config.erl
+++ b/fluxer_gateway/src/gateway/fluxer_gateway_config.erl
@@ -81,6 +81,9 @@ env_gateway_base_config() ->
<<"push_clear_notifications_enabled">> => env_bool(
"FLUXER_GATEWAY_PUSH_CLEAR_NOTIFICATIONS_ENABLED", true
),
+ <<"push_enrolled_clear_notifications_enabled">> => env_bool(
+ "FLUXER_GATEWAY_PUSH_ENROLLED_CLEAR_NOTIFICATIONS_ENABLED", true
+ ),
<<"push_endpoint_guard_enabled">> => env_bool(
"FLUXER_GATEWAY_PUSH_ENDPOINT_GUARD_ENABLED", true
),
@@ -259,6 +262,9 @@ build_push_config(Service, Public) ->
push_clear_notifications_enabled => get_bool(
Service, <<"push_clear_notifications_enabled">>, true
),
+ push_enrolled_clear_notifications_enabled => get_bool(
+ Service, <<"push_enrolled_clear_notifications_enabled">>, true
+ ),
push_endpoint_guard_enabled => get_bool(
Service, <<"push_endpoint_guard_enabled">>, true
),
diff --git a/fluxer_gateway/src/push/push.erl b/fluxer_gateway/src/push/push.erl
index f5f9f46ee..52a422abf 100644
--- a/fluxer_gateway/src/push/push.erl
+++ b/fluxer_gateway/src/push/push.erl
@@ -246,7 +246,9 @@ clear_channel_notifications(UserId, ChannelId, MessageId) ->
-spec clear_for_enrolment(boolean(), integer(), integer(), integer()) -> ok.
clear_for_enrolment(true, UserId, ChannelId, MessageId) ->
ok = push_outbox:truncate_read(UserId, ChannelId, MessageId),
- cast_clear_if_enabled(clear_notifications_enabled(), UserId, ChannelId, MessageId);
+ cast_clear_if_enabled(
+ enrolled_clear_notifications_enabled(), UserId, ChannelId, MessageId
+ );
clear_for_enrolment(false, UserId, ChannelId, MessageId) ->
cast_clear_if_enabled(clear_notifications_enabled(), UserId, ChannelId, MessageId).
@@ -256,6 +258,13 @@ cast_clear_if_enabled(true, UserId, ChannelId, MessageId) ->
cast_clear_if_enabled(false, _UserId, _ChannelId, _MessageId) ->
ok.
+-spec enrolled_clear_notifications_enabled() -> boolean().
+enrolled_clear_notifications_enabled() ->
+ case persistent_term:get(push_enrolled_clear_notifications_enabled, undefined) of
+ OperatorChoice when is_boolean(OperatorChoice) -> OperatorChoice;
+ _ -> env_boolean(push_enrolled_clear_notifications_enabled, true)
+ end.
+
-spec clear_notifications_enabled() -> boolean().
clear_notifications_enabled() ->
case persistent_term:get(push_clear_notifications_enabled, undefined) of
diff --git a/fluxer_gateway/test/push_tests.erl b/fluxer_gateway/test/push_tests.erl
index d7bd49eb0..efbbe4483 100644
--- a/fluxer_gateway/test/push_tests.erl
+++ b/fluxer_gateway/test/push_tests.erl
@@ -47,6 +47,25 @@ a_clear_is_dropped_only_after_the_retry_budget_is_spent_test() ->
meck:unload(push_dispatcher)
end.
+an_enrolled_user_gets_clears_while_the_fleet_switch_is_off_test() ->
+ erase_persistent_term(push_noop),
+ erase_persistent_term(push_enrolled_clear_notifications_enabled),
+ persistent_term:put(push_clear_notifications_enabled, false),
+ try
+ ?assertEqual(ok, push:clear_channel_notifications(1, 2, 3))
+ after
+ erase_persistent_term(push_clear_notifications_enabled)
+ end.
+
+the_cohort_switch_can_be_turned_off_on_its_own_test() ->
+ erase_persistent_term(push_noop),
+ persistent_term:put(push_enrolled_clear_notifications_enabled, false),
+ try
+ ?assertEqual(ok, push:clear_channel_notifications(1, 2, 3))
+ after
+ erase_persistent_term(push_enrolled_clear_notifications_enabled)
+ end.
+
push_owner_key_prefers_first_recipient_test() ->
?assertEqual(
42,