Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Merge eea6cc3 into ad321e6
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomassaro committed Jul 28, 2018
2 parents ad321e6 + eea6cc3 commit 34f458b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/notification/event/notification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ defmodule Helix.Notification.Event.Notification do

publish do

alias HELL.Utils
alias Helix.Account.Model.Account
alias Helix.Cache.Query.Cache, as: CacheQuery
alias Helix.Entity.Query.Entity, as: EntityQuery

@event :notification_added

def generate_payload(event, _socket) do
Expand Down Expand Up @@ -64,8 +69,23 @@ defmodule Helix.Notification.Event.Notification do

defp get_extra_data(%Notification.Account{}),
do: %{}
defp get_extra_data(%Notification.Server{}),
do: %{}
defp get_extra_data(notification = %Notification.Server{}) do
# We have to publish the server information to the Client, so it knows
# where to display the notification.
# If the server belongs to the given account, we publish the raw
# `server_id`. Otherwise, we publish the server's `network_id` and `ip`.
entity = EntityQuery.fetch_by_server(notification.server_id)
account_id = Account.cast_from_entity(entity.entity_id)

if account_id == notification.account_id do
%{server_id: notification.server_id |> to_string()}
else
notification.server_id
|> CacheQuery.from_server_get_nips!()
|> List.first()
|> Utils.stringify_map()
end
end
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/features/file/transfer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ defmodule Helix.Test.Features.File.TransferTest do
assert notification_added_event.data.class == :server
assert notification_added_event.data.code == :file_downloaded

# Notification contains information about which server it took place
assert notification_added_event.data.server_id ==
to_string(gateway.server_id)

# Notification contains required data
notification_data = notification_added_event.data.data
assert notification_data.id == to_string(new_file.file_id)
Expand Down

0 comments on commit 34f458b

Please sign in to comment.