fix(push): drop Fluxer badge on self-hosted instances (#3400)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-11 15:56:53 +02:00
1 parent be314788b3
commit af7724dbf6
5 files changed
+104 -20

No files matched your search

@@ -28,6 +28,7 @@ load() ->
env_config() ->
#{
<<"env">> => env_binary("FLUXER_ENV", <<"development">>),
<<"instance">> => #{<<"self_hosted">> => env_bool("FLUXER_SELF_HOSTED", false)},
<<"internal">> => env_internal_config(),
<<"public">> => env_public_config(),
<<"proxy">> => env_proxy_config(),
@@ -147,9 +148,10 @@ build_config(RawConfig) ->
Nats = get_map(RawConfig, [<<"services">>, <<"nats">>]),
Proxy = get_map(RawConfig, [<<"proxy">>]),
Public = get_map(RawConfig, [<<"public">>]),
Instance = get_map(RawConfig, [<<"instance">>]),
lists:foldl(fun maps:merge/2, #{}, [
build_core_config(Service, Internal, Nats, Proxy),
build_push_config(Service, Public),
build_push_config(Service, Public, Instance),
build_sharding_config(Service),
build_http_config(Service),
build_cluster_config(Service, Public),
@@ -176,10 +178,11 @@ build_core_config(Service, Internal, Nats, Proxy) ->
)
}.
-spec build_push_config(map(), map()) -> config().
build_push_config(Service, Public) ->
-spec build_push_config(map(), map(), map()) -> config().
build_push_config(Service, Public, Instance) ->
#{
push_enabled => get_bool(Service, <<"push_enabled">>, true),
self_hosted => get_bool(Instance, <<"self_hosted">>, false),
static_cdn_endpoint => public_endpoint(
get_binary(Service, <<"static_cdn_endpoint">>, <<"http://localhost:8088">>), Public
),
+48 -8
View File
@@ -231,7 +231,7 @@ notification_fields(
),
ChannelIdBin = integer_to_binary(ChannelId),
MessageIdBin = integer_to_binary(MessageId),
#{
with_badge(#{
<<"title">> => push_notification:build_notification_title(
AuthorName, MessageData, GuildId, GuildName, ChannelName
),
@@ -239,14 +239,24 @@ notification_fields(
MessageData, MarkdownContext
),
<<"icon">> => push_notification_format:resolve_author_avatar_url(AuthorData),
<<"badge">> => push_utils:construct_static_asset_url(
<<"marketing/branding/symbol-white.svg">>
),
<<"tag">> => <<"channel:", ChannelIdBin/binary, ":", MessageIdBin/binary>>,
<<"notification_tag">> => <<"channel:", ChannelIdBin/binary>>,
<<"url">> => push_notification_format:build_url(GuildId, ChannelId, MessageId),
<<"image_url">> => nullable(push_notification_format:extract_image_url(MessageData))
}.
}).
-spec with_badge(map()) -> map().
with_badge(Fields) ->
case fluxer_gateway_env:get(self_hosted) of
true ->
Fields;
_ ->
Fields#{
<<"badge">> => push_utils:construct_static_asset_url(
<<"marketing/branding/symbol-white.svg">>
)
}
end.
-spec thread_job_fields(map(), binary() | undefined) -> map().
thread_job_fields(MessageData, ChannelName) ->
@@ -329,9 +339,15 @@ outbox_job(Subject, Job, Body, Meta) ->
-include_lib("eunit/include/eunit.hrl").
with_endpoint_env(Fun) ->
with_endpoint_env(false, Fun).
with_endpoint_env(SelfHosted, Fun) ->
ok = meck:new(fluxer_gateway_env, [passthrough, no_link]),
try
ok = meck:expect(fluxer_gateway_env, get, fun endpoint_env_meck/1),
ok = meck:expect(fluxer_gateway_env, get, fun
(self_hosted) -> SelfHosted;
(Key) -> endpoint_env_meck(Key)
end),
Fun()
after
meck:unload(fluxer_gateway_env)
@@ -397,7 +413,9 @@ encoded_message_job(MessageData, ChannelName) ->
push_notification_format, resolve_author_avatar_url, fun(_) -> <<"icon">> end
),
ok = meck:expect(push_utils, construct_static_asset_url, fun(_) -> <<"badge">> end),
Job = message_job(MessageData, #{}, 5, 6, 7, <<"Guild">>, ChannelName),
Job = with_endpoint_env(fun() ->
message_job(MessageData, #{}, 5, 6, 7, <<"Guild">>, ChannelName)
end),
json:decode(iolist_to_binary(json:encode(Job)))
after
meck:unload(push_utils),
@@ -507,12 +525,34 @@ notification_fields_omit_sensitive_attachment_image_test() ->
Fields = test_notification_fields(MessageData, 123, <<"Server">>, <<"general">>),
?assertEqual(null, maps:get(<<"image_url">>, Fields)).
notification_fields_include_the_fluxer_badge_test() ->
MessageData = #{<<"content">> => <<"Hi">>, <<"mentions">> => []},
Fields = test_notification_fields(MessageData, 123, <<"Server">>, <<"general">>),
?assertEqual(
<<"https://static.example/marketing/branding/symbol-white.svg">>,
maps:get(<<"badge">>, Fields)
).
notification_fields_omit_the_badge_on_self_hosted_instances_test() ->
MessageData = #{<<"content">> => <<"Hi">>, <<"mentions">> => []},
Fields = test_notification_fields(
MessageData, 123, <<"Server">>, <<"general">>, #{}, true
),
?assertNot(maps:is_key(<<"badge">>, Fields)).
test_notification_fields(MessageData, GuildId, GuildName, ChannelName) ->
test_notification_fields(MessageData, GuildId, GuildName, ChannelName, #{}).
test_notification_fields(MessageData, GuildId, GuildName, ChannelName, MarkdownContext) ->
test_notification_fields(
MessageData, GuildId, GuildName, ChannelName, MarkdownContext, false
).
test_notification_fields(
MessageData, GuildId, GuildName, ChannelName, MarkdownContext, SelfHosted
) ->
Author = #{<<"id">> => <<"42">>, <<"username">> => <<"Alice">>, <<"avatar">> => null},
with_endpoint_env(fun() ->
with_endpoint_env(SelfHosted, fun() ->
notification_fields(
MessageData#{<<"author">> => Author},
MarkdownContext,
@@ -74,6 +74,14 @@ blank_env_values_fall_back_to_the_defaults_test() ->
end
).
self_hosted_follows_the_fluxer_self_hosted_env_test() ->
with_env("FLUXER_SELF_HOSTED", "", fun() ->
?assertEqual(false, maps:get(self_hosted, fluxer_gateway_config:load()))
end),
with_env("FLUXER_SELF_HOSTED", "true", fun() ->
?assertEqual(true, maps:get(self_hosted, fluxer_gateway_config:load()))
end).
pinned_guild_ids_reject_non_snowflakes_test() ->
with_env("FLUXER_GATEWAY_PINNED_GUILD_IDS", "1100000000000000001,ab", fun() ->
?assertError({invalid_pinned_guild_id, "ab"}, fluxer_gateway_config:load())