Skip to content
Browse files

Made some changes to how stuff works.

  • Loading branch information...
1 parent 3d2dba0 commit c892abeb1cadd748306a9a5e350f7cf4ae1104bd @schleyfox committed Apr 29, 2009
Showing with 25 additions and 11 deletions.
  1. +15 −7 src/chats_server.erl
  2. +8 −4 src/pages/web_index.erl
  3. +2 −0 src/user.erl
View
22 src/chats_server.erl
@@ -2,7 +2,7 @@
-behaviour(gen_server).
--export([start/0, add_user/2, remove_user/2, send_message/2, list_users/0]).
+-export([start/0, add_user/2, remove_user/2, send_message/2, list_users/0, list_user_pids/0]).
-include_lib("src/models.hrl").
@@ -27,12 +27,19 @@ send_message(User, Message) ->
list_users() ->
gen_server:call(chats_server, list_users).
+list_user_pids() ->
+ gen_server:call(chats_server, list_user_pids).
+
init([]) ->
{ok, #state{active_users=dict:new()}}.
handle_call(list_users, _From, State) ->
- {reply, dict:fetch_keys(State#state.active_users), State};
+ NewState = refresh_active_users(State),
+ {reply, dict:fetch_keys(NewState#state.active_users), NewState};
+handle_call(list_user_pids, _From, State) ->
+ NewState = refresh_active_users(State),
+ {reply, NewState#state.active_users, NewState};
handle_call(_Request, _From, State) ->
Reply = ok,
@@ -42,7 +49,11 @@ handle_call(_Request, _From, State) ->
handle_cast({message, User, Message}, State) ->
send_message_to_all_users(User, Message,
users_to_pids(State#state.active_users)),
- {noreply, refresh_active_users(State)};
+ case NewState = refresh_active_users(State) of
+ State -> refresh_all_buddy_lists(NewState);
+ _ -> false
+ end,
+ {noreply, NewState};
% Add User
handle_cast({add_user, User, Pid}, State) ->
@@ -73,10 +84,7 @@ refresh_active_users(State) ->
active_users=
dict:filter(
fun(_, [V]) ->
- try is_process_alive(V)
- catch
- error:_ -> false
- end
+ is_process_alive(V)
end,
State#state.active_users)}.
View
12 src/pages/web_index.erl
@@ -12,10 +12,14 @@ title() ->
body() ->
authentication:requires_login(fun() ->
Body = [
- #panel {id=buddyList},
- #panel {id=chatHistory, class=chat_history },
- #textbox {id=messageTextBox, next=sendButton},
- #button {id=sendButton, text="Talk", postback=chat}
+ #panel {style="width: 600px;", body = [
+ #panel {id=buddyList, style="background-color: #222; float: left; width: 120px; height: 320px; text-align: left; padding: 5px 5px 5px 5px; vertical-align: top;"},
+ #panel{ body = [
+ #panel {id=chatHistory, class=chat_history, style="height: 300px; overflow: auto;" },
+ #textbox {id=messageTextBox, next=sendButton, style="width:300px;"},
+ #button {id=sendButton, text="Talk", postback=chat}
+ ]}
+ ]}
],
Pid = wf:comet(fun() -> listen_for_events() end),
chats_server:add_user(authentication:current_user(), Pid),
View
2 src/user.erl
@@ -49,6 +49,8 @@ hash_password(Password) ->
{erlang:md5(Password ++ Salt), Salt}.
create_salt() ->
+ {A1, A2, A3} = now(),
+ random:seed(A1, A2, A3),
lists:map(fun(_Elem) ->
random:uniform(127-33)+33
end,

0 comments on commit c892abe

Please sign in to comment.
Something went wrong with that request. Please try again.