-% coding: utf-8
+% coding: utf-8\r
+% Copyright 2008 Grégory Burri\r
+%\r
+% This file is part of Euphorik.\r
+%\r
+% Euphorik is free software: you can redistribute it and/or modify\r
+% it under the terms of the GNU General Public License as published by\r
+% the Free Software Foundation, either version 3 of the License, or\r
+% (at your option) any later version.\r
+%\r
+% Euphorik is distributed in the hope that it will be useful,\r
+% but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+% GNU General Public License for more details.\r
+%\r
+% You should have received a copy of the GNU General Public License\r
+% along with Euphorik. If not, see <http://www.gnu.org/licenses/>.\r
+%
% Ce module permet la gestion des conversations du minichat d'euphorik.
% Un message (enfant) peut répondre à des messages (ses parents).
% Un message (parent) peut avoir plusieurs réponses (enfants)
% @type Message() = {integer(), [integer()]}
% @type Conversation_detailee() = {[integer()], [integer()], [integer()], bool()}
% @type Conversation = {[Message()] , bool()} bool() : si true alors il y a encore des messages dans les pages suivantes.
+\r
-module(euphorik_minichat_conversation).\r
-export([\r
conversations/4\r
]).
-
-include("euphorik_bd.hrl").
-include_lib("stdlib/include/qlc.hrl").
-
-import(lists, [reverse/1, any/2, map/2, sublist/3, filter/2]).
-import(euphorik_bd, [resultat_transaction/1]).
-import(qlc, [e/1, q/1, keysort/3]).
% Renvoie un tuple {C, X} où C est la conversation complète et X les messages répondant à des mess qui ne font pas partie de la conversation
% Attention : les messages de C et de X sont ordrés du plus grand Id au plus petit.
% @spec conversation([integer()], [integer()], [integer()]) -> {}
-conversation(Messages, [M | Reste], X) ->
- Est_deja_traite = any(fun(E) -> E =:= M end, Messages),
+conversation(Conv, [M | Reste], X) ->
+ Est_deja_traite = any(fun(E) -> E =:= M end, Conv),
if Est_deja_traite ->
- conversation(Messages, Reste, X);
+ conversation(Conv, Reste, X);
true ->
Enfants = enfants(M),
Parents = parents(M),
% un message est dit externe si un de ses parent ne fait pas partie de la conversation ou si un de ses parents fait partie de X
- Est_message_externe = Parents -- Messages =/= [] orelse intersection(Parents, X) =/= [],
- conversation([M | Messages], lists:merge(Reste, Enfants), if Est_message_externe -> [M | X]; true -> X end)
+ Est_message_externe = Parents -- Conv =/= [] orelse intersection(Parents, X) =/= [],
+ conversation([M | Conv], lists:merge(Reste, Enfants), if Est_message_externe -> [M | X]; true -> X end)
end;
conversation(Messages, [], X) ->
{Messages, X}.