Skip to content

Commit

Permalink
Send member_added message after invite
Browse files Browse the repository at this point in the history
This is required for chobby to know who's in the party since there is no
`GET party` as in the web client
  • Loading branch information
geekingfrog committed Feb 24, 2025
1 parent 335ea44 commit 2e9eb73
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
3 changes: 2 additions & 1 deletion lib/teiserver/account/servers/party_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ defmodule Teiserver.Account.PartyServer do
%{
channel: "teiserver_client_messages:#{userid}",
event: :party_invite,
party_id: party.id
party_id: party.id,
members: party.members
}
)

Expand Down
8 changes: 7 additions & 1 deletion lib/teiserver/protocols/spring/spring_party_in.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ defmodule Teiserver.Protocols.Spring.PartyIn do
state
end

def handle_event(%{event: :party_invite, party_id: party_id}, state) do
def handle_event(%{event: :party_invite, party_id: party_id, members: members}, state) do
SpringOut.reply(:party, :invited_to_party, party_id, message_id(), state)

# the web interface uses a list of parties to get the content. But with
# chobby and spring, we need to let the client know about the members
for uid <- members, username <- [Account.get_username_by_id(uid)], not is_nil(username) do
SpringOut.reply(:party, :member_added, {party_id, username}, message_id(), state)
end
end

def handle_event(%{event: :added_to_party, party_id: party_id}, state) do
Expand Down
20 changes: 11 additions & 9 deletions test/teiserver/protocols/spring/spring_party_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ defmodule Teiserver.Protocols.Spring.SpringPartyTest do
{:ok, socket1: socket1, user1: user1, socket2: socket2, user2: user2}
end

test "online player", %{socket1: sock1, socket2: sock2, user2: user2} do
test "online player", %{socket1: sock1, socket2: sock2, user2: user2} = ctx do
party_id = create_party!(sock1)
invite_to_party!(sock1, party_id, user2.name)

assert {"s.party.invited_to_party", [^party_id, _], _} =
_recv_until(sock2) |> parse_in_message()
[ok, joined] = _recv_until(sock2) |> parse_in_messages()
assert {"s.party.invited_to_party", [^party_id, _], _} = ok
assert {"s.party.joined_party", [^party_id, username1], _} = joined
assert username1 == ctx.user1.name
end

test "invalid player", %{socket1: sock1} do
Expand Down Expand Up @@ -72,9 +74,9 @@ defmodule Teiserver.Protocols.Spring.SpringPartyTest do

party_id = create_party!(socket1)
invite_to_party!(socket1, party_id, user2.name)

assert {"s.party.invited_to_party", [^party_id, _], _} =
_recv_until(socket2) |> parse_in_message()
# absorb the message and the "added_to_party" message. Assume this
# works as it is tested in another test
_recv_until(socket2)

{:ok, socket1: socket1, user1: user1, socket2: socket2, user2: user2, party_id: party_id}
end
Expand Down Expand Up @@ -117,9 +119,9 @@ defmodule Teiserver.Protocols.Spring.SpringPartyTest do

party_id = create_party!(socket1)
invite_to_party!(socket1, party_id, user2.name)

assert {"s.party.invited_to_party", [^party_id, _], _} =
_recv_until(socket2) |> parse_in_message()
# absorb the message and the "added_to_party" message. Assume this
# works as it is tested in another test
_recv_until(socket2)

accept_invite!(socket2, party_id)

Expand Down

0 comments on commit 2e9eb73

Please sign in to comment.