return followers collection
This commit is contained in:
		
							parent
							
								
									75a26715d0
								
							
						
					
					
						commit
						0db710272a
					
				
					 4 changed files with 57 additions and 10 deletions
				
			
		|  | @ -80,7 +80,9 @@ routes db detailsFile = | |||
|   , -- Followers | ||||
|     Twain.get (Fedi.matchFollowers $ unsafePerformIO $ fetchUserDetails detailsFile) do | ||||
|       details <- liftIO $ fetchUserDetails detailsFile | ||||
|       Fedi.handleFollowers details | ||||
|       followers <- liftIO db.getFollowers | ||||
|         <&> map (\follower -> T.unpack follower.actorId) | ||||
|       Fedi.handleFollowers details followers | ||||
|   , -- Following | ||||
|     Twain.get (Fedi.matchFollowing $ unsafePerformIO $ fetchUserDetails detailsFile) do | ||||
|       details <- liftIO $ fetchUserDetails detailsFile | ||||
|  |  | |||
|  | @ -15,16 +15,57 @@ matchFollowers :: UserDetails -> Twain.PathPattern | |||
| matchFollowers details = | ||||
|   fromString ("/" <> details.username <> "/followers") | ||||
| 
 | ||||
| handleFollowers :: UserDetails -> Twain.ResponderM b | ||||
| handleFollowers details = do | ||||
| handleFollowers :: UserDetails -> [Url] -> Twain.ResponderM b | ||||
| handleFollowers details items = do | ||||
|   isPage <- Twain.queryParamMaybe "page" | ||||
|   let | ||||
|     collection :: Collection () | ||||
|     collection = | ||||
|       emptyUnorderedCollection | ||||
|       { id = Just $ ObjectId $ actorUrl details <> "/followers" | ||||
|     followersUrl = | ||||
|       "https://" | ||||
|         <> details.domain | ||||
|         <> "/" | ||||
|         <> details.username | ||||
|         <> "/followers" | ||||
|     response = | ||||
|       case isPage of | ||||
|         Just True -> | ||||
|           let | ||||
|             empty = emptyOrderedCollectionPage followersUrl | ||||
|             content :: FollowersPage | ||||
|             content = | ||||
|               empty | ||||
|                 { id = Just $ ObjectId $ followersUrl <> "?page=true" | ||||
|                 , summary = Just $ fromString $ details.username <> "'s followers" | ||||
|                 , otype = | ||||
|                     empty.otype | ||||
|                       { ctype = | ||||
|                           empty.otype.ctype | ||||
|                             { partOf = followersUrl | ||||
|                             , porderedItems = items | ||||
|                             } | ||||
|   Twain.send $ jsonLD (A.encode collection) | ||||
|                       } | ||||
|                 } | ||||
|           in | ||||
|             A.encode content | ||||
|         _ -> | ||||
|           let | ||||
|             content :: Followers | ||||
|             content = | ||||
|               emptyOrderedCollection | ||||
|                 { id = Just $ ObjectId followersUrl | ||||
|                 , summary = Just $ fromString $ details.username <> "'s followers" | ||||
|                 , otype = | ||||
|                     emptyOrderedCollection.otype | ||||
|                       { ctype = | ||||
|                           emptyOrderedCollection.otype.ctype | ||||
|                             { orderedItems = items | ||||
|                             } | ||||
|                       , first = Just $ followersUrl <> "?page=true" | ||||
|                       , last = Just $ followersUrl <> "?page=true" | ||||
|                       } | ||||
|                 } | ||||
|           in | ||||
|             A.encode content | ||||
|   Twain.send $ jsonLD response | ||||
| 
 | ||||
| -- * Following | ||||
| 
 | ||||
|  |  | |||
|  | @ -34,6 +34,7 @@ handleOutbox details items = do | |||
|             content = | ||||
|               empty | ||||
|                 { id = Just $ ObjectId $ outboxUrl <> "?page=true" | ||||
|                 , summary = Just $ fromString $ details.username <> "'s notes" | ||||
|                 , otype = | ||||
|                     empty.otype | ||||
|                       { ctype = | ||||
|  |  | |||
|  | @ -535,6 +535,9 @@ type Outbox = OrderedCollection AnyActivity | |||
| 
 | ||||
| type OutboxPage = OrderedCollectionPage AnyActivity | ||||
| 
 | ||||
| type Followers = OrderedCollection Url | ||||
| type FollowersPage = OrderedCollectionPage Url | ||||
| 
 | ||||
| data CollectionType t | ||||
|   = CollectionType | ||||
|   { ctype :: t | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue