MOD Avancement sur le passage à JSON
[euphorik.git] / modules / erl / euphorik_protocole.erl
index dba48e2..7e80308 100755 (executable)
@@ -41,6 +41,10 @@ nouveau_user_login(Action) ->
    
 \r
 % Un utilisateur se logge.
+login([{login, Login}, {password, Password}]) ->
+   {ok, User} = euphorik_minichat:user_by_login_password(Login, Password),
+   
+   
 login(Action) ->
    case xmerl_xpath:string("cookie", Action) of
       [#xmlElement{content = [#xmlText{value = Cookie}]}] ->
@@ -83,7 +87,7 @@ profile(Action) ->
             Email = case xmerl_xpath:string("email", Action) of [#xmlElement{content = [#xmlText{value = E}]}] -> E; _ -> undefined end,
             Css = case xmerl_xpath:string("css", Action) of [#xmlElement{content = [#xmlText{value = C}]}] -> C; _ -> undefined end,
             Page_principale = case xmerl_xpath:string("pagePrincipale", Action) of [#xmlElement{content = [#xmlText{value = P3}]}] -> list_to_integer(P3); _ -> undefined end,
-            Conversations = lists:foldl(
+            Conversations = lists:foldr(
                fun(Conv, Acc) ->
                   [#xmlElement{content = [#xmlText{value = Id_racine_str}]}] = xmerl_xpath:string("racine", Conv),
                   [#xmlElement{content = [#xmlText{value = Page_conv_str}]}] = xmerl_xpath:string("page", Conv), 
@@ -130,17 +134,7 @@ refreshMessage(Action) ->
                      _ -> inconnu
                   end;
                _ -> inconnu
-            end,
-            % extraction des conversations en [{id, page}, ..]
-            % Obsolète : obtenu depuis la table 'user'
-            %~ Conversations = lists:map(
-               %~ fun(Conv) ->
-                  %~ [#xmlElement{content = [#xmlText{value = Id_racine_str}]}] = xmerl_xpath:string("racine", Conv),
-                  %~ [#xmlElement{content = [#xmlText{value = Page_conv_str}]}] = xmerl_xpath:string("page", Conv), 
-                  %~ {erlang:list_to_integer(Id_racine_str, 36), erlang:list_to_integer(Page_conv_str)}
-               %~ end,
-               %~ xmerl_xpath:string("conversation", Action)
-            %~ ),\r
+            end,\r
             % accrochez-vous ca va siouxer ;)
             [{reponse, [{name, "refreshMessages"}],\r
                lists:map(\r
@@ -178,7 +172,12 @@ refreshMessage(Action) ->
                         ]
                      }\r
                   end,
-                  euphorik_minichat_conversation:conversations(User#user.conversations, Nb_message, Dernier_id, User#user.page_principale)\r
+                  euphorik_minichat_conversation:conversations(
+                     if User =/= inconnu -> User#user.conversations; true -> [] end,
+                     Nb_message,
+                     Dernier_id,
+                     if User =/= inconnu -> User#user.page_principale; true -> 1 end
+                  )\r
                )
             }];
          _ ->