@ -115,6 +115,7 @@ type writestore interface {
DispersePosts ( userID int64 , postIDs [ ] string ) ( * [ ] ClaimPostResult , error )
ClaimPosts ( cfg * config . Config , userID int64 , collAlias string , posts * [ ] ClaimPostRequest ) ( * [ ] ClaimPostResult , error )
GetPostLikeCounts ( postID string ) ( int64 , error )
GetPostsCount ( c * CollectionObj , includeFuture bool )
GetPosts ( cfg * config . Config , c * Collection , page int , includeFuture , forceRecentFirst , includePinned bool ) ( * [ ] PublicPost , error )
GetAllPostsTaggedIDs ( c * Collection , tag string , includeFuture bool ) ( [ ] string , error )
@ -1174,6 +1175,12 @@ func (db *datastore) GetPost(id string, collectionID int64) (*PublicPost, error)
return nil , ErrPostUnpublished
}
// Get additional information needed before processing post data
p . LikeCount , err = db . GetPostLikeCounts ( p . ID )
if err != nil {
return nil , err
}
res := p . processPost ( )
if ownerName . Valid {
res . Owner = & PublicUser { Username : ownerName . String }
@ -1236,6 +1243,18 @@ func (db *datastore) GetPostProperty(id string, collectionID int64, property str
return res , nil
}
func ( db * datastore ) GetPostLikeCounts ( postID string ) ( int64 , error ) {
var count int64
err := db . QueryRow ( "SELECT COUNT(*) FROM remote_likes WHERE post_id = ?" , postID ) . Scan ( & count )
switch {
case err == sql . ErrNoRows :
count = 0
case err != nil :
return 0 , err
}
return count , nil
}
// GetPostsCount modifies the CollectionObj to include the correct number of
// standard (non-pinned) posts. It will return future posts if `includeFuture`
// is true.