-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notification #214
base: master
Are you sure you want to change the base?
Notification #214
Conversation
@@ -24,6 +25,12 @@ send_test(User, Channel, HolidayDate) -> | |||
{ok, Pid} = supervisor:start_child(remind_router_sup, []), | |||
gen_server:cast(Pid, {send_reminder, User, Channel, HolidayDate, Message, true}). | |||
|
|||
send_message(User, Channel, Message) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you introduce this generic send_message function then send_test should not exist anymore and use the new one to test the reminder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its not possible because send_test
accepts HolidayDate
, and send_message
sets the date internally. Maybe we need something more general like notification_handler
, with a function send(User, Channel, MessageType, Message)
. Where MessageType
can be a reminder, test, notification, or something else in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but what I mean is you should have one send_message
function that takes all the parameters. Then you can have a higher level function like send_reminder
that builds the reminder specficic message and then callssend_message
. send_test
could be removed, I think it's enough to just call the generic send_message
with the test specific message.
@@ -58,7 +58,8 @@ from_json(Req, State = #{is_new := true, | |||
} when is_list(DaysBefore), length(DaysBefore) =< 5 -> | |||
CleanConfig = maps:filter(fun not_empty_value/2, Config), | |||
{ok, _} = db_channel:create(Email, Name, Type, CleanConfig, DaysBefore, Time, TimeZone), | |||
|
|||
{ok, Channel} = db_channel:get(Email, Name), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
db_channel:create already returns the channel. You should understand the previous code before introducing a new line.
@@ -99,6 +100,8 @@ from_json(Req, State = #{is_new := false, | |||
end. | |||
|
|||
delete_resource(Req, State = #{email := Email, name := Name}) -> | |||
{ok, Channel} = db_channel:get(Email, Name), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't necessary, the channel is already part of the State (check the rest of the code).
remind_router:send_message(User, Channel, Msg). | ||
|
||
send_creation_notification(Channel=#{name := Name}, #{user := User}) -> | ||
Msg = <<"Crated a remainder '", Name/binary, "'.">>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-Crated
+Created
I can't figure out why the test of
test output error:
|
Message = <<"This is a holiday reminder: John Doe will be out today.">>, | ||
Reminders = ets_channel:get_reminders(TableId, Email), | ||
true =lists:any( | ||
fun({ReminderEmail, ReminderMessage}) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's more readable to assign the fun to a variable and the pass that to lists:any
UserName = maps:get(name, User), | ||
FinalMessage = <<UserName/binary, ": ", Message/binary>>, | ||
{ok, Pid} = supervisor:start_child(remind_router_sup, []), | ||
gen_server:cast(Pid, {send_reminder, User, Channel, erlang:date(), FinalMessage, true}). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another issue is that right now, the log of sent reminders in the database has a boolean column test
. Now, apart from regular reminders and test reminders, we introduced these notifications. We should probably remove the test column and have a reminder type or something, to properly inform in the log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, i believe that creating a "message type" or something like that would be the most flexible way of doing it.
Should I try to make |
I think you should change the db schema to replace the test boolean for a message type field as discussed. You should also add the send_message function, but don't think you need to rename remind_router or change it's interface other than that (at least don't do it yet, let's see how the code looks after these changes and decide if it needs more refactoring). |
Body), | ||
ok = ktn_task:wait_for_success( | ||
fun() -> | ||
[{Email, _}] = ets_channel:get_reminders(TableId, Email), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has to check that the message text is the one expected
"/api/channels/test_ets"), | ||
ok = ktn_task:wait_for_success( | ||
fun() -> | ||
[{Email, _}, {Email, _}] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
Message = <<"This is a Holiday Ping test: John Doe will be out on holidays.">>, | ||
Reminders = ets_channel:get_reminders(TableId, Email), | ||
true = lists:any( | ||
fun({ReminderEmail,ReminderMessage}) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could do
fun({Email, Message}) -> true;
(_OtherEmail, _OtherMessage) -> false
end
@@ -102,3 +103,37 @@ delete_channel(Config) -> | |||
{ok, 204, _, _} = test_utils:api_request(delete, Token, "/api/channels/my_delete_channel"), | |||
{ok, 404, _, _} = test_utils:api_request(delete, Token, "/api/channels/my_delete_channel"), | |||
ok. | |||
|
|||
create_delete_channel_notification(Config) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you also need to test the edit part: if you add a new target to the channel, the notification should go only to the new one; if you remove one, only the removed should receive the notification.
@hernanex3 add a better title to the PR |
No description provided.