2 Module : Gargantext.Core.Text.List.Social
4 Copyright : (c) CNRS, 2018-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
11 module Gargantext.Core.Text.List.Social
14 import Control.Monad (mzero)
16 import Data.HashMap.Strict (HashMap)
18 import Data.Monoid (mconcat)
19 import Gargantext.API.Ngrams.Tools
20 import Gargantext.API.Ngrams.Types
21 import Gargantext.Core.NodeStory
22 import Gargantext.Core.Text.List.Social.Find
23 import Gargantext.Core.Text.List.Social.History
24 import Gargantext.Core.Text.List.Social.Patch
25 import Gargantext.Core.Text.List.Social.Prelude
26 import Gargantext.Core.Types.Individu
27 import Gargantext.Database.Admin.Types.Node
28 import Gargantext.Database.Prelude
29 import Gargantext.Database.Query.Table.Node.Error
30 import Gargantext.Database.Query.Tree
31 import Gargantext.Database.Schema.Ngrams
32 import Gargantext.Prelude
34 ------------------------------------------------------------------------
35 ------------------------------------------------------------------------
38 -- | FlowSocialListPriority
39 -- Sociological assumption: either private or others (public) first
40 -- This parameter depends on the user choice
42 data FlowSocialListWith = FlowSocialListWithPriority { fslw_priority :: FlowSocialListPriority }
43 | FlowSocialListWithLists { fslw_lists :: [ListId] }
44 instance FromJSON FlowSocialListWith where
45 parseJSON (Object v) = do
47 value <- v .:? "value" .!= []
49 "MyListsFirst" -> pure $ FlowSocialListWithPriority { fslw_priority = MySelfFirst }
50 "OtherListsFirst" -> pure $ FlowSocialListWithPriority { fslw_priority = OthersFirst }
51 "SelectedLists" -> pure $ FlowSocialListWithLists { fslw_lists = v }
52 _ -> pure $ FlowSocialListWithPriority { fslw_priority = MySelfFirst }
55 data FlowSocialListPriority = MySelfFirst | OthersFirst
56 flowSocialListPriority :: FlowSocialListPriority -> [NodeMode]
57 flowSocialListPriority MySelfFirst = [Private{-, Shared, Public -}]
58 flowSocialListPriority OthersFirst = reverse $ flowSocialListPriority MySelfFirst
61 -- | We keep the parents for all ngrams but terms
62 keepAllParents :: NgramsType -> KeepAllParents
63 keepAllParents NgramsTerms = KeepAllParents False
64 keepAllParents _ = KeepAllParents True
67 ------------------------------------------------------------------------
68 flowSocialList :: ( HasNodeStory env err m
73 => Maybe FlowSocialListWith
76 -> FlowCont NgramsTerm FlowListScores
77 -> m (FlowCont NgramsTerm FlowListScores)
78 flowSocialList Nothing u = flowSocialList' MySelfFirst u
79 flowSocialList (Just (FlowSocialListWithPriority p)) u = flowSocialList' p u
80 flowSocialList (Just (FlowSocialListWithLists ls)) _ = getHistoryScores ls History_User
82 flowSocialList' :: ( HasNodeStory env err m
87 => FlowSocialListPriority
89 -> FlowCont NgramsTerm FlowListScores
90 -> m (FlowCont NgramsTerm FlowListScores)
91 flowSocialList' flowPriority user nt flc =
92 mconcat <$> mapM (flowSocialListByMode' user nt flc)
93 (flowSocialListPriority flowPriority)
96 flowSocialListByMode' :: ( HasNodeStory env err m
101 => User -> NgramsType
102 -> FlowCont NgramsTerm FlowListScores
104 -> m (FlowCont NgramsTerm FlowListScores)
105 flowSocialListByMode' user' nt' flc' mode =
106 findListsId user' mode
107 >>= flowSocialListByModeWith nt' flc'
110 flowSocialListByModeWith :: ( HasNodeStory env err m
116 -> FlowCont NgramsTerm FlowListScores
118 -> m (FlowCont NgramsTerm FlowListScores)
119 flowSocialListByModeWith nt'' flc'' listes =
120 getHistoryScores listes History_User nt'' flc''
123 -----------------------------------------------------------------
124 getHistoryScores :: ( HasNodeStory env err m
132 -> FlowCont NgramsTerm FlowListScores
133 -> m (FlowCont NgramsTerm FlowListScores)
134 getHistoryScores lists hist nt fl =
135 addScorePatches nt lists fl <$> getHistory hist nt lists
137 getHistory :: ( HasNodeStory env err m
145 -> m (Map ListId (Map NgramsType [HashMap NgramsTerm NgramsPatch]))
146 getHistory hist nt listes =
147 history hist [nt] listes <$> getRepo' listes