diff --git a/src/handlers/ws_handler.erl b/src/handlers/ws_handler.erl index ef84614..8ff211d 100644 --- a/src/handlers/ws_handler.erl +++ b/src/handlers/ws_handler.erl @@ -38,7 +38,10 @@ websocket_handle({text, Msg}, State) -> try jsx:decode(Msg, [return_maps]) of #{<<"action">> := <<"subscribe">>, <<"calendar_id">> := CalendarId} -> io:format("Subscribe to calendar: ~s~n", [CalendarId]), - NewSubs = [CalendarId | State#state.subscriptions], + NewSubs = case lists:member(CalendarId, State#state.subscriptions) of + true -> State#state.subscriptions; + false -> [CalendarId | State#state.subscriptions] + end, Reply = jsx:encode(#{status => <<"subscribed">>, calendar_id => CalendarId}), io:format("Sending reply: ~s~n", [Reply]), {reply, {text, Reply}, State#state{subscriptions = NewSubs}}; diff --git a/src/logic/logic_calendar.erl b/src/logic/logic_calendar.erl index 44c00ad..c42dfff 100644 --- a/src/logic/logic_calendar.erl +++ b/src/logic/logic_calendar.erl @@ -19,16 +19,17 @@ create_calendar(UserId, Title, Description, Confirmation, Type) -> {ok, User} -> case User#user.status of active -> - % Проверяем подписку для commercial календарей case Type of commercial -> case logic_subscription:can_create_commercial_calendar(UserId) of - true -> ok; - false -> {error, subscription_required} + true -> + core_calendar:create(UserId, Title, Description, Confirmation, Type); + false -> + {error, subscription_required} end; - personal -> ok - end, - core_calendar:create(UserId, Title, Description, Confirmation, Type); + personal -> + core_calendar:create(UserId, Title, Description, Confirmation, Type) + end; _ -> {error, user_inactive} end;