A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(gateway): show voice members after a move, drop tests
Hampus292d70af91cb
diff --git a/fluxer_gateway/src/guild/voice/guild_voice_broadcast.erl b/fluxer_gateway/src/guild/voice/guild_voice_broadcast.erlindex 8aae9b50e..a720176d4 100644--- a/fluxer_gateway/src/guild/voice/guild_voice_broadcast.erl+++ b/fluxer_gateway/src/guild/voice/guild_voice_broadcast.erl@@ -4,6 +4,7 @@-typing([eqwalizer]).-export([broadcast_voice_state_update/3]).+-export([broadcast_voice_state_move/3]).-export([broadcast_voice_server_update_to_session/7]).-export_type([@@ -37,6 +38,25 @@ do_broadcast_voice_state_update(VoiceState, State, OldChannelIdBin) ->maybe_sync_guild_voice_state(VoiceState, OldChannelIdBin, State),ok.+-spec broadcast_voice_state_move(voice_state(), guild_state(), binary() | null) -> ok.+broadcast_voice_state_move(MovedVoiceState, State, OldChannelIdBin) ->+ Sessions = maps:get(sessions, State, #{}),+ NewChannelIdBin = maps:get(<<"channel_id">>, MovedVoiceState, null),+ NewPids = channel_session_pids(Sessions, NewChannelIdBin, State),+ OldPids = channel_session_pids(Sessions, OldChannelIdBin, State) -- NewPids,+ Sanitized = voice_state_utils:sanitize_voice_state_for_broadcast(MovedVoiceState),+ maybe_dispatch_voice_state_update(NewPids, Sanitized, State),+ maybe_dispatch_voice_state_update(OldPids, Sanitized#{<<"channel_id">> => null}, State),+ maybe_persist_voice_state_update(MovedVoiceState, State).++-spec channel_session_pids(map(), binary() | null, guild_state()) -> [term()].+channel_session_pids(Sessions, ChannelIdBin, State) ->+ ChannelId = utils:binary_to_integer_safe(ChannelIdBin),+ [+ maps:get(pid, S)+ || {_Sid, S} <- filter_sessions_for_voice_channel(Sessions, ChannelId, State)+ ].+-spec filter_channel_id_bin(voice_state(), binary() | null) -> binary() | null.filter_channel_id_bin(VoiceState, OldChannelIdBin) ->case maps:get(<<"channel_id">>, VoiceState, null) ofdiff --git a/fluxer_gateway/src/guild/voice/guild_voice_connection_pending.erl b/fluxer_gateway/src/guild/voice/guild_voice_connection_pending.erlindex ba698ac38..0a831448c 100644--- a/fluxer_gateway/src/guild/voice/guild_voice_connection_pending.erl+++ b/fluxer_gateway/src/guild/voice/guild_voice_connection_pending.erl@@ -10,6 +10,7 @@maybe_restore_pending_connection/5,resolve_voice_state_from_pending/4,sweep_expired_pending_joins/1,+ broadcast_moved_removals/2,clear_e2ee_room_key_if_channel_idle/3,validate_pending_nonce_and_expiry/2]).@@ -74,10 +75,39 @@ sweep_expired_pending_joins(State) ->PendingConnections = maps:get(pending_voice_connections, State, #{}),{Expired, Remaining} = partition_expired(Now, PendingConnections),spawn_force_disconnects(Expired),+ ok = broadcast_moved_removals(Expired, State),StateCleared = clear_expired_virtual_flags(Expired, State),StateWithPending = StateCleared#{pending_voice_connections => Remaining},clear_expired_e2ee_keys(Expired, StateWithPending, Remaining).+-spec broadcast_moved_removals([{binary(), map()}], guild_state()) -> ok.+broadcast_moved_removals(Removed, State) ->+ VoiceStates = voice_state_utils:voice_states(State),+ lists:foreach(+ fun({ConnId, Metadata}) ->+ case+ pending_get_boolean(Metadata, moved) andalso+ not maps:is_key(ConnId, VoiceStates)+ of+ true -> broadcast_moved_removal(ConnId, Metadata, State);+ false -> ok+ end+ end,+ Removed+ ).++-spec broadcast_moved_removal(binary(), map(), guild_state()) -> ok.+broadcast_moved_removal(ConnId, Metadata, State) ->+ case build_voice_state_from_pending(Metadata, ConnId, State) of+ VoiceState when is_map(VoiceState) ->+ ChannelIdBin = maps:get(<<"channel_id">>, VoiceState, null),+ guild_voice_broadcast:broadcast_voice_state_update(+ VoiceState#{<<"channel_id">> => null}, State, ChannelIdBin+ );+ undefined ->+ ok+ end.+-spec clear_e2ee_room_key_if_channel_idle(integer() | undefined, voice_state_map(), guild_state()) -> guild_state().@@ -492,21 +522,3 @@ pending_value_to_binary(Value) whentype_conv:to_binary(Value);pending_value_to_binary(_) ->undefined.---ifdef(TEST).--include_lib("eunit/include/eunit.hrl").--assemble_pending_voice_state_preserves_voice_routing_test() ->- PendingData = #{- guild_id => 20,- channel_id => 30,- user_id => 10,- session_id => <<"sess1">>,- region_id => <<"us-east">>,- server_id => <<"voice-ewr-1">>- },- VoiceState = assemble_pending_voice_state(PendingData, <<"conn1">>, 20, 30, 10),- ?assertEqual(<<"us-east">>, maps:get(<<"region_id">>, VoiceState)),- ?assertEqual(<<"voice-ewr-1">>, maps:get(<<"server_id">>, VoiceState)).---endif.diff --git a/fluxer_gateway/src/guild/voice/guild_voice_disconnect_broadcast.erl b/fluxer_gateway/src/guild/voice/guild_voice_disconnect_broadcast.erlindex 24dd52d0d..edb94beff 100644--- a/fluxer_gateway/src/guild/voice/guild_voice_disconnect_broadcast.erl+++ b/fluxer_gateway/src/guild/voice/guild_voice_disconnect_broadcast.erl@@ -89,7 +89,7 @@ clear_pending_voice_connection(ConnectionId, State) ->PendingData = maps:get(ConnectionId, PendingConnections, #{}),NewPending = maps:remove(ConnectionId, PendingConnections),NewState = State#{pending_voice_connections => NewPending},- clear_e2ee_room_keys_for_removed_pending(+ release_removed_pending(#{ConnectionId => PendingData},voice_state_utils:voice_states(State),NewPending,@@ -117,7 +117,7 @@ clear_pending_voice_connections_for_user(UserId, RequestSessionId, State) ->PendingConnections),NewState = State#{pending_voice_connections => FilteredPending},- clear_e2ee_room_keys_for_removed_pending(+ release_removed_pending(RemovedPending, voice_state_utils:voice_states(State), FilteredPending, NewState).@@ -146,7 +146,7 @@ clear_pending_voice_connections_for_user_channel(UserId, ChannelId, State) ->PendingConnections),NewState = State#{pending_voice_connections => FilteredPending},- clear_e2ee_room_keys_for_removed_pending(+ release_removed_pending(RemovedPending, voice_state_utils:voice_states(State), FilteredPending, NewState).@@ -193,10 +193,11 @@ clear_e2ee_room_keys_for_removed(RemovedVoiceStates, NewVoiceStates, State) ->RemovedVoiceStates).--spec clear_e2ee_room_keys_for_removed_pending(+-spec release_removed_pending(map(), voice_state_map(), map(), guild_state()) -> guild_state().-clear_e2ee_room_keys_for_removed_pending(Removed, VS, Remaining, State) ->+release_removed_pending(Removed, VS, Remaining, State) ->+ ok = guild_voice_connection_pending:broadcast_moved_removals(maps:to_list(Removed), State),maps:fold(fun(_ConnId, PendingData, AccState) ->clear_e2ee_room_key_for_removed_pending(diff --git a/fluxer_gateway/src/guild/voice/guild_voice_disconnect_channel.erl b/fluxer_gateway/src/guild/voice/guild_voice_disconnect_channel.erlindex 5512d4912..d44bee28e 100644--- a/fluxer_gateway/src/guild/voice/guild_voice_disconnect_channel.erl+++ b/fluxer_gateway/src/guild/voice/guild_voice_disconnect_channel.erl@@ -98,9 +98,7 @@ disconnect_connection_from_expected_channel() ->case maps:get(ConnId, VoiceStates, undefined) ofundefined ->- State1 = guild_voice_disconnect_broadcast:clear_pending_voice_connection(- ConnId, State- ),+ State1 = clear_pending_in_channel(ConnId, ExpectedChannelId, State),{reply, #{success => true, ignored => true, reason => <<"connection_not_found">>},State1};VoiceState ->@@ -109,6 +107,16 @@ disconnect_connection_from_expected_channel()end.+-spec clear_pending_in_channel(binary(), integer(), guild_state()) -> guild_state().+clear_pending_in_channel(ConnId, ChannelId, State) ->+ Pending = maps:get(pending_voice_connections, State, #{}),+ case maps:get(ConnId, Pending, undefined) of+ #{channel_id := ChannelId} ->+ guild_voice_disconnect_broadcast:clear_pending_voice_connection(ConnId, State);+ _ ->+ State+ end.+-spec check_and_disconnect_connection(integer(), integer(), binary(), voice_state(), voice_state_map(), guild_state()) -> {reply, map(), guild_state()}.diff --git a/fluxer_gateway/src/guild/voice/guild_voice_move_execute.erl b/fluxer_gateway/src/guild/voice/guild_voice_move_execute.erlindex fcd70e36a..04d8be543 100644--- a/fluxer_gateway/src/guild/voice/guild_voice_move_execute.erl+++ b/fluxer_gateway/src/guild/voice/guild_voice_move_execute.erl@@ -112,6 +112,17 @@ broadcast_disconnects(ConnectionsToMove, NewState) ->ConnectionsToMove).+-spec broadcast_moves(voice_state_map(), binary(), guild_state()) -> ok.+broadcast_moves(ConnectionsToMove, ChannelIdBin, Snapshot) ->+ maps:foreach(+ fun(_ConnId, VoiceState) ->+ OldChannelIdBin = maps:get(<<"channel_id">>, VoiceState, null),+ MovedVS = VoiceState#{<<"channel_id">> => ChannelIdBin},+ guild_voice_broadcast:broadcast_voice_state_move(MovedVS, Snapshot, OldChannelIdBin)+ end,+ ConnectionsToMove+ ).+-spec handle_channel_move(voice_state_map(), integer(), integer(), integer(), voice_state_map(), guild_state()) -> voice_reply().@@ -188,7 +199,8 @@ execute_move(ConnectionsToMove, ChannelIdValue, UserId, VoiceStates, State) ->StateWithVA = maybe_add_virtual_access(UserId, ChannelIdValue, StateAfterDisconnect),StateCleaned = cleanup_stale_virtual_access(UserId, StateWithVA),BroadcastSnapshot = build_broadcast_snapshot(StateCleaned),- spawn(fun() -> broadcast_disconnects(ConnectionsToMove, BroadcastSnapshot) end),+ ChannelIdBin = integer_to_binary(ChannelIdValue),+ spawn(fun() -> broadcast_moves(ConnectionsToMove, ChannelIdBin, BroadcastSnapshot) end),SessionData = extract_session_data(ConnectionsToMove),Reply = #{success => true,@@ -382,6 +394,7 @@ build_pending_metadata(region_id => maps:get(region_id, TokenData, undefined),server_id => maps:get(server_id, TokenData, undefined),token_nonce => TokenNonce,+ moved => true,created_at => Now,expires_at => Now + ?MOVE_PENDING_TTL_MS}.