{"action":"created","comment":{"url":"https://api.github.com/repos/WWWcool/erlChat/pulls/comments/212765191","pull_request_review_id":149455214,"id":212765191,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxMjc2NTE5MQ==","diff_hunk":"@@ -0,0 +1,127 @@\n+-module(client_local).\n+\n+-export([send_cb/1]).\n+-export([connect/2]).\n+-export([disconnect/0]).\n+-export([select_room/1]).\n+-export([send_message/1]).\n+\n+-export([start_link/0, stop/0]).\n+-export([init/1, terminate/2, handle_call/3, handle_cast/2]).\n+\n+-behavior(gen_server).\n+\n+-define(EMPTY, \"Empty\").\n+\n+-record(cl_context, {server = undefined, name, state, msgBuffer = []}).\n+-record(en_cl_states, {offline, online}).\n+-record(user_init, {name, module, send_cb}).\n+\n+-type connect_params() :: server:connect_params().\n+\n+%% Exported Client Functions %% Operation & Maintenance API\n+start_link() ->\n+    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).\n+\n+stop() -> gen_server:cast(?MODULE, stop).\n+\n+%% Callback Functions\n+init(_) ->\n+    {ok, init_client()}.\n+\n+terminate(_Reason, _State) -> ok.\n+\n+handle_cast(stop, State) -> {stop, normal, State};\n+handle_cast(_, #cl_context{state = #en_cl_states.offline} = State) ->\n+    {noreply, State};\n+handle_cast({send_cb, Message}, State) ->\n+    io:format(\"Receive message - ~p~n\",[Message]),\n+    {noreply, message_append(State, Message)}.\n+\n+handle_call({connect, {Server, Name}}, {_From, _}, State) ->\n+    try Server:try_to_connect(#user_init{   name = Name,\n+                                            module = ?MODULE,\n+                                            send_cb = send_cb}) of\n+        {error, Replay} ->\n+            error_handler({server_error, Replay}, State);\n+        _ ->\n+            ServerReplay = Server:get_rooms(),\n+            %?Print(\"ServerReplay = ~p~n\",[ServerReplay], #en_trace_level.debug),\n+            case ServerReplay of\n+            %case Server:get_rooms() of\n+                {error, Replay} -> error_handler({server_error, Replay}, State);\n+                _ ->\n+                    NewState = State#cl_context{  name = Name,\n+                                                        server = Server,\n+                                                        state = #en_cl_states.online},\n+                    {reply, ok, NewState}\n+            end\n+    catch\n+        error:Error -> error_handler({error, Error}, State)\n+    end;\n+\n+handle_call(_, _, #cl_context{state = #en_cl_states.offline} = State) ->\n+    {reply, {error, not_connected}, State};\n+\n+handle_call(disconnect, {_From, _}, State) ->\n+    try (State#cl_context.server):disconnect() of\n+        {error, Replay} -> error_handler({server_error, Replay}, State);\n+        _ -> {reply, ok, init_client()}\n+    catch\n+        error:Error -> error_handler({error, Error}, State)\n+    end;\n+\n+handle_call({select_room, Room}, {_From, _}, State) ->\n+    try (State#cl_context.server):goto_room(Room) of\n+        {error, Replay} -> error_handler({server_error, Replay}, State);\n+        _ -> {reply, ok, State}\n+    catch\n+        error:Error -> error_handler({error, Error}, State)\n+    end;\n+\n+handle_call({send_message, Message}, {_From, _}, State) ->\n+    try (State#cl_context.server):send_message(Message) of\n+        {error, Replay} -> error_handler({server_error, Replay}, State);\n+        _ -> {reply, ok, State}\n+    catch\n+        error:Error -> error_handler({error, Error}, State)\n+    end.\n+\n+%% Client API\n+send_cb(Message) ->\n+    gen_server:cast(?MODULE, {send_cb, Message}).\n+\n+connect(Server, Name) ->\n+    gen_server:call(?MODULE, {connect, {Server, Name}}).\n+\n+disconnect() ->\n+    gen_server:call(?MODULE, disconnect).\n+\n+select_room(Room) ->\n+    gen_server:call(?MODULE, {select_room, Room}).\n+\n+send_message(Message) ->\n+    gen_server:call(?MODULE, {send_message, Message}).\n+\n+%% Utils\n+init_client() -> #cl_context{name = ?EMPTY, state = #en_cl_states.offline}.","path":"apps/chat_server/src/client_local.erl","position":107,"original_position":107,"commit_id":"5f71ade1da8c637b7c2cb9301fde07c840de3fef","original_commit_id":"5f71ade1da8c637b7c2cb9301fde07c840de3fef","user":{"login":"ciiol","id":425290,"node_id":"MDQ6VXNlcjQyNTI5MA==","avatar_url":"https://avatars2.githubusercontent.com/u/425290?v=4","gravatar_id":"","url":"https://api.github.com/users/ciiol","html_url":"https://github.com/ciiol","followers_url":"https://api.github.com/users/ciiol/followers","following_url":"https://api.github.com/users/ciiol/following{/other_user}","gists_url":"https://api.github.com/users/ciiol/gists{/gist_id}","starred_url":"https://api.github.com/users/ciiol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ciiol/subscriptions","organizations_url":"https://api.github.com/users/ciiol/orgs","repos_url":"https://api.github.com/users/ciiol/repos","events_url":"https://api.github.com/users/ciiol/events{/privacy}","received_events_url":"https://api.github.com/users/ciiol/received_events","type":"User","site_admin":false},"body":"В качестве пустого имени лучше использовать атом, например `undefined`","created_at":"2018-08-24T22:00:39Z","updated_at":"2018-08-24T22:03:05Z","html_url":"https://github.com/WWWcool/erlChat/pull/1#discussion_r212765191","pull_request_url":"https://api.github.com/repos/WWWcool/erlChat/pulls/1","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/WWWcool/erlChat/pulls/comments/212765191"},"html":{"href":"https://github.com/WWWcool/erlChat/pull/1#discussion_r212765191"},"pull_request":{"href":"https://api.github.com/repos/WWWcool/erlChat/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/WWWcool/erlChat/pulls/1","id":210670358,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEwNjcwMzU4","html_url":"https://github.com/WWWcool/erlChat/pull/1","diff_url":"https://github.com/WWWcool/erlChat/pull/1.diff","patch_url":"https://github.com/WWWcool/erlChat/pull/1.patch","issue_url":"https://api.github.com/repos/WWWcool/erlChat/issues/1","number":1,"state":"open","locked":false,"title":"Work","user":{"login":"WWWcool","id":8044981,"node_id":"MDQ6VXNlcjgwNDQ5ODE=","avatar_url":"https://avatars2.githubusercontent.com/u/8044981?v=4","gravatar_id":"","url":"https://api.github.com/users/WWWcool","html_url":"https://github.com/WWWcool","followers_url":"https://api.github.com/users/WWWcool/followers","following_url":"https://api.github.com/users/WWWcool/following{/other_user}","gists_url":"https://api.github.com/users/WWWcool/gists{/gist_id}","starred_url":"https://api.github.com/users/WWWcool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WWWcool/subscriptions","organizations_url":"https://api.github.com/users/WWWcool/orgs","repos_url":"https://api.github.com/users/WWWcool/repos","events_url":"https://api.github.com/users/WWWcool/events{/privacy}","received_events_url":"https://api.github.com/users/WWWcool/received_events","type":"User","site_admin":false},"body":"some work on erl chat ","created_at":"2018-08-24T08:16:35Z","updated_at":"2018-08-24T22:03:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"51ff227bbf6cc7325376274d221dc99efeaae886","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/WWWcool/erlChat/pulls/1/commits","review_comments_url":"https://api.github.com/repos/WWWcool/erlChat/pulls/1/comments","review_comment_url":"https://api.github.com/repos/WWWcool/erlChat/pulls/comments{/number}","comments_url":"https://api.github.com/repos/WWWcool/erlChat/issues/1/comments","statuses_url":"https://api.github.com/repos/WWWcool/erlChat/statuses/5f71ade1da8c637b7c2cb9301fde07c840de3fef","head":{"label":"WWWcool:work","ref":"work","sha":"5f71ade1da8c637b7c2cb9301fde07c840de3fef","user":{"login":"WWWcool","id":8044981,"node_id":"MDQ6VXNlcjgwNDQ5ODE=","avatar_url":"https://avatars2.githubusercontent.com/u/8044981?v=4","gravatar_id":"","url":"https://api.github.com/users/WWWcool","html_url":"https://github.com/WWWcool","followers_url":"https://api.github.com/users/WWWcool/followers","following_url":"https://api.github.com/users/WWWcool/following{/other_user}","gists_url":"https://api.github.com/users/WWWcool/gists{/gist_id}","starred_url":"https://api.github.com/users/WWWcool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WWWcool/subscriptions","organizations_url":"https://api.github.com/users/WWWcool/orgs","repos_url":"https://api.github.com/users/WWWcool/repos","events_url":"https://api.github.com/users/WWWcool/events{/privacy}","received_events_url":"https://api.github.com/users/WWWcool/received_events","type":"User","site_admin":false},"repo":{"id":145962453,"node_id":"MDEwOlJlcG9zaXRvcnkxNDU5NjI0NTM=","name":"erlChat","full_name":"WWWcool/erlChat","owner":{"login":"WWWcool","id":8044981,"node_id":"MDQ6VXNlcjgwNDQ5ODE=","avatar_url":"https://avatars2.githubusercontent.com/u/8044981?v=4","gravatar_id":"","url":"https://api.github.com/users/WWWcool","html_url":"https://github.com/WWWcool","followers_url":"https://api.github.com/users/WWWcool/followers","following_url":"https://api.github.com/users/WWWcool/following{/other_user}","gists_url":"https://api.github.com/users/WWWcool/gists{/gist_id}","starred_url":"https://api.github.com/users/WWWcool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WWWcool/subscriptions","organizations_url":"https://api.github.com/users/WWWcool/orgs","repos_url":"https://api.github.com/users/WWWcool/repos","events_url":"https://api.github.com/users/WWWcool/events{/privacy}","received_events_url":"https://api.github.com/users/WWWcool/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/WWWcool/erlChat","description":null,"fork":false,"url":"https://api.github.com/repos/WWWcool/erlChat","forks_url":"https://api.github.com/repos/WWWcool/erlChat/forks","keys_url":"https://api.github.com/repos/WWWcool/erlChat/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WWWcool/erlChat/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WWWcool/erlChat/teams","hooks_url":"https://api.github.com/repos/WWWcool/erlChat/hooks","issue_events_url":"https://api.github.com/repos/WWWcool/erlChat/issues/events{/number}","events_url":"https://api.github.com/repos/WWWcool/erlChat/events","assignees_url":"https://api.github.com/repos/WWWcool/erlChat/assignees{/user}","branches_url":"https://api.github.com/repos/WWWcool/erlChat/branches{/branch}","tags_url":"https://api.github.com/repos/WWWcool/erlChat/tags","blobs_url":"https://api.github.com/repos/WWWcool/erlChat/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WWWcool/erlChat/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WWWcool/erlChat/git/refs{/sha}","trees_url":"https://api.github.com/repos/WWWcool/erlChat/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WWWcool/erlChat/statuses/{sha}","languages_url":"https://api.github.com/repos/WWWcool/erlChat/languages","stargazers_url":"https://api.github.com/repos/WWWcool/erlChat/stargazers","contributors_url":"https://api.github.com/repos/WWWcool/erlChat/contributors","subscribers_url":"https://api.github.com/repos/WWWcool/erlChat/subscribers","subscription_url":"https://api.github.com/repos/WWWcool/erlChat/subscription","commits_url":"https://api.github.com/repos/WWWcool/erlChat/commits{/sha}","git_commits_url":"https://api.github.com/repos/WWWcool/erlChat/git/commits{/sha}","comments_url":"https://api.github.com/repos/WWWcool/erlChat/comments{/number}","issue_comment_url":"https://api.github.com/repos/WWWcool/erlChat/issues/comments{/number}","contents_url":"https://api.github.com/repos/WWWcool/erlChat/contents/{+path}","compare_url":"https://api.github.com/repos/WWWcool/erlChat/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WWWcool/erlChat/merges","archive_url":"https://api.github.com/repos/WWWcool/erlChat/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WWWcool/erlChat/downloads","issues_url":"https://api.github.com/repos/WWWcool/erlChat/issues{/number}","pulls_url":"https://api.github.com/repos/WWWcool/erlChat/pulls{/number}","milestones_url":"https://api.github.com/repos/WWWcool/erlChat/milestones{/number}","notifications_url":"https://api.github.com/repos/WWWcool/erlChat/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WWWcool/erlChat/labels{/name}","releases_url":"https://api.github.com/repos/WWWcool/erlChat/releases{/id}","deployments_url":"https://api.github.com/repos/WWWcool/erlChat/deployments","created_at":"2018-08-24T08:09:17Z","updated_at":"2018-08-24T08:12:28Z","pushed_at":"2018-08-24T15:03:47Z","git_url":"git://github.com/WWWcool/erlChat.git","ssh_url":"git@github.com:WWWcool/erlChat.git","clone_url":"https://github.com/WWWcool/erlChat.git","svn_url":"https://github.com/WWWcool/erlChat","homepage":null,"size":1466,"stargazers_count":0,"watchers_count":0,"language":"Erlang","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"WWWcool:master","ref":"master","sha":"ef3df381aa4bc67539419d5bcaa23f10f68d4fdc","user":{"login":"WWWcool","id":8044981,"node_id":"MDQ6VXNlcjgwNDQ5ODE=","avatar_url":"https://avatars2.githubusercontent.com/u/8044981?v=4","gravatar_id":"","url":"https://api.github.com/users/WWWcool","html_url":"https://github.com/WWWcool","followers_url":"https://api.github.com/users/WWWcool/followers","following_url":"https://api.github.com/users/WWWcool/following{/other_user}","gists_url":"https://api.github.com/users/WWWcool/gists{/gist_id}","starred_url":"https://api.github.com/users/WWWcool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WWWcool/subscriptions","organizations_url":"https://api.github.com/users/WWWcool/orgs","repos_url":"https://api.github.com/users/WWWcool/repos","events_url":"https://api.github.com/users/WWWcool/events{/privacy}","received_events_url":"https://api.github.com/users/WWWcool/received_events","type":"User","site_admin":false},"repo":{"id":145962453,"node_id":"MDEwOlJlcG9zaXRvcnkxNDU5NjI0NTM=","name":"erlChat","full_name":"WWWcool/erlChat","owner":{"login":"WWWcool","id":8044981,"node_id":"MDQ6VXNlcjgwNDQ5ODE=","avatar_url":"https://avatars2.githubusercontent.com/u/8044981?v=4","gravatar_id":"","url":"https://api.github.com/users/WWWcool","html_url":"https://github.com/WWWcool","followers_url":"https://api.github.com/users/WWWcool/followers","following_url":"https://api.github.com/users/WWWcool/following{/other_user}","gists_url":"https://api.github.com/users/WWWcool/gists{/gist_id}","starred_url":"https://api.github.com/users/WWWcool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WWWcool/subscriptions","organizations_url":"https://api.github.com/users/WWWcool/orgs","repos_url":"https://api.github.com/users/WWWcool/repos","events_url":"https://api.github.com/users/WWWcool/events{/privacy}","received_events_url":"https://api.github.com/users/WWWcool/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/WWWcool/erlChat","description":null,"fork":false,"url":"https://api.github.com/repos/WWWcool/erlChat","forks_url":"https://api.github.com/repos/WWWcool/erlChat/forks","keys_url":"https://api.github.com/repos/WWWcool/erlChat/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WWWcool/erlChat/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WWWcool/erlChat/teams","hooks_url":"https://api.github.com/repos/WWWcool/erlChat/hooks","issue_events_url":"https://api.github.com/repos/WWWcool/erlChat/issues/events{/number}","events_url":"https://api.github.com/repos/WWWcool/erlChat/events","assignees_url":"https://api.github.com/repos/WWWcool/erlChat/assignees{/user}","branches_url":"https://api.github.com/repos/WWWcool/erlChat/branches{/branch}","tags_url":"https://api.github.com/repos/WWWcool/erlChat/tags","blobs_url":"https://api.github.com/repos/WWWcool/erlChat/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WWWcool/erlChat/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WWWcool/erlChat/git/refs{/sha}","trees_url":"https://api.github.com/repos/WWWcool/erlChat/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WWWcool/erlChat/statuses/{sha}","languages_url":"https://api.github.com/repos/WWWcool/erlChat/languages","stargazers_url":"https://api.github.com/repos/WWWcool/erlChat/stargazers","contributors_url":"https://api.github.com/repos/WWWcool/erlChat/contributors","subscribers_url":"https://api.github.com/repos/WWWcool/erlChat/subscribers","subscription_url":"https://api.github.com/repos/WWWcool/erlChat/subscription","commits_url":"https://api.github.com/repos/WWWcool/erlChat/commits{/sha}","git_commits_url":"https://api.github.com/repos/WWWcool/erlChat/git/commits{/sha}","comments_url":"https://api.github.com/repos/WWWcool/erlChat/comments{/number}","issue_comment_url":"https://api.github.com/repos/WWWcool/erlChat/issues/comments{/number}","contents_url":"https://api.github.com/repos/WWWcool/erlChat/contents/{+path}","compare_url":"https://api.github.com/repos/WWWcool/erlChat/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WWWcool/erlChat/merges","archive_url":"https://api.github.com/repos/WWWcool/erlChat/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WWWcool/erlChat/downloads","issues_url":"https://api.github.com/repos/WWWcool/erlChat/issues{/number}","pulls_url":"https://api.github.com/repos/WWWcool/erlChat/pulls{/number}","milestones_url":"https://api.github.com/repos/WWWcool/erlChat/milestones{/number}","notifications_url":"https://api.github.com/repos/WWWcool/erlChat/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WWWcool/erlChat/labels{/name}","releases_url":"https://api.github.com/repos/WWWcool/erlChat/releases{/id}","deployments_url":"https://api.github.com/repos/WWWcool/erlChat/deployments","created_at":"2018-08-24T08:09:17Z","updated_at":"2018-08-24T08:12:28Z","pushed_at":"2018-08-24T15:03:47Z","git_url":"git://github.com/WWWcool/erlChat.git","ssh_url":"git@github.com:WWWcool/erlChat.git","clone_url":"https://github.com/WWWcool/erlChat.git","svn_url":"https://github.com/WWWcool/erlChat","homepage":null,"size":1466,"stargazers_count":0,"watchers_count":0,"language":"Erlang","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/WWWcool/erlChat/pulls/1"},"html":{"href":"https://github.com/WWWcool/erlChat/pull/1"},"issue":{"href":"https://api.github.com/repos/WWWcool/erlChat/issues/1"},"comments":{"href":"https://api.github.com/repos/WWWcool/erlChat/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/WWWcool/erlChat/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/WWWcool/erlChat/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/WWWcool/erlChat/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/WWWcool/erlChat/statuses/5f71ade1da8c637b7c2cb9301fde07c840de3fef"}},"author_association":"OWNER"}}
{"actor":{"display_login":"ciiol"}}