Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions routes/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -1362,9 +1362,7 @@ func (fes *APIServer) GetSinglePost(ww http.ResponseWriter, req *http.Request) {
pubKeyToProfileEntryResponseMap := make(map[lib.PkMapKey]*ProfileEntryResponse)
for _, pubKeyBytes := range filteredProfilePubKeyMap {
profileEntry := utxoView.GetProfileEntryForPublicKey(pubKeyBytes)
if profileEntry == nil {
continue
} else {
if profileEntry != nil {
pubKeyToProfileEntryResponseMap[lib.MakePkMapKey(pubKeyBytes)] =
fes._profileEntryToResponse(profileEntry, utxoView)
}
Expand Down Expand Up @@ -1510,15 +1508,16 @@ func (fes *APIServer) GetSinglePostComments(
if _, ok := blockedPublicKeys[lib.PkToString(commentEntry.PosterPublicKey, fes.Params)]; !ok && profilePubKeyMap[pkMapKey] == nil {
profilePubKeyMap[pkMapKey] = commentEntry.PosterPublicKey
}
commentProfileEntryResponse, pubKeyKeyExistsInMap := pubKeyToProfileEntryResponseMap[lib.MakePkMapKey(commentEntry.PosterPublicKey)]
commentProfileEntryResponse, _ := pubKeyToProfileEntryResponseMap[lib.MakePkMapKey(commentEntry.PosterPublicKey)]
commentAuthorIsCurrentPoster := reflect.DeepEqual(commentEntry.PosterPublicKey, posterPublicKeyBytes)
// Skip comments that:
// - Don't have a profile (it was most likely banned). UPDATE: only remove if public key is blacklisted.
// - Are hidden *AND* don't have comments. Keep hidden posts with comments.
// - isDeleted (this was already filtered in an earlier stage and should never be true)
// - Skip comment is it's by the poster of the single post we are fetching and the currentPoster is blocked by
// the reader
if (commentProfileEntryResponse == nil && !pubKeyKeyExistsInMap) || commentEntry.IsDeleted() ||
_, pubKeyExistsInMap := profilePubKeyMap[lib.MakePkMapKey(commentEntry.PosterPublicKey)]
if (commentProfileEntryResponse == nil && !pubKeyExistsInMap) || commentEntry.IsDeleted() ||
(commentEntry.IsHidden && commentEntry.CommentCount == 0) ||
(commentAuthorIsCurrentPoster && isCurrentPosterBlocked) {
continue
Expand All @@ -1544,6 +1543,7 @@ func (fes *APIServer) GetSinglePostComments(
sort.Slice(commentEntryResponseList, func(ii, jj int) bool {
iiCommentEntryResponse := commentEntryResponseList[ii]
jjCommentEntryResponse := commentEntryResponseList[jj]

// If the poster of ii is the poster of the main post and jj is not, ii should be first.
iiIsPoster := iiCommentEntryResponse.PostEntryResponse.PosterPublicKeyBase58Check == postEntryResponse.PosterPublicKeyBase58Check
jjIsPoster := jjCommentEntryResponse.PostEntryResponse.PosterPublicKeyBase58Check == postEntryResponse.PosterPublicKeyBase58Check
Expand Down
30 changes: 12 additions & 18 deletions routes/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2297,7 +2297,7 @@ func (fes *APIServer) GetNotifications(ww http.ResponseWriter, req *http.Request
// heavy lifting.
postEntryResponses := make(map[string]*PostEntryResponse)

addPostForHash := func(postHashHex string, readerPK []byte, profileEntryRequired bool) {
addPostForHash := func(postHashHex string, readerPK []byte) {
// If we already have the post entry response in the map, just return
if _, exists := postEntryResponses[postHashHex]; exists || postHashHex == "" {
return
Expand All @@ -2318,12 +2318,6 @@ func (fes *APIServer) GetNotifications(ww http.ResponseWriter, req *http.Request

profileEntryResponse := profileEntryResponses[lib.PkToString(postEntry.PosterPublicKey, fes.Params)]

// Filter out responses if profile entry is missing and is required
if profileEntryRequired && profileEntryResponse == nil {
postEntryResponses[postHashHex] = nil
return
}

postEntryResponse, err := fes._postEntryToResponse(postEntry, false, fes.Params, utxoView, userPublicKeyBytes, 2)
if err != nil {
return
Expand All @@ -2349,26 +2343,26 @@ func (fes *APIServer) GetNotifications(ww http.ResponseWriter, req *http.Request
postAssociationMetadata := txnMeta.Metadata.CreatePostAssociationTxindexMetadata

if postMetadata != nil {
addPostForHash(postMetadata.PostHashBeingModifiedHex, userPublicKeyBytes, true)
addPostForHash(postMetadata.ParentPostHashHex, userPublicKeyBytes, true)
addPostForHash(postMetadata.PostHashBeingModifiedHex, userPublicKeyBytes)
addPostForHash(postMetadata.ParentPostHashHex, userPublicKeyBytes)
} else if likeMetadata != nil {
addPostForHash(likeMetadata.PostHashHex, userPublicKeyBytes, true)
addPostForHash(likeMetadata.PostHashHex, userPublicKeyBytes)
} else if transferCreatorCoinMetadata != nil {
if transferCreatorCoinMetadata.PostHashHex != "" {
addPostForHash(transferCreatorCoinMetadata.PostHashHex, userPublicKeyBytes, true)
addPostForHash(transferCreatorCoinMetadata.PostHashHex, userPublicKeyBytes)
}
} else if nftBidMetadata != nil {
addPostForHash(nftBidMetadata.NFTPostHashHex, userPublicKeyBytes, true)
addPostForHash(nftBidMetadata.NFTPostHashHex, userPublicKeyBytes)
} else if acceptNFTBidMetadata != nil {
addPostForHash(acceptNFTBidMetadata.NFTPostHashHex, userPublicKeyBytes, true)
addPostForHash(acceptNFTBidMetadata.NFTPostHashHex, userPublicKeyBytes)
} else if nftTransferMetadata != nil {
addPostForHash(nftTransferMetadata.NFTPostHashHex, userPublicKeyBytes, false)
addPostForHash(nftTransferMetadata.NFTPostHashHex, userPublicKeyBytes)
} else if createNFTMetadata != nil {
addPostForHash(createNFTMetadata.NFTPostHashHex, userPublicKeyBytes, true)
addPostForHash(createNFTMetadata.NFTPostHashHex, userPublicKeyBytes)
} else if updateNFTMetadata != nil {
addPostForHash(updateNFTMetadata.NFTPostHashHex, userPublicKeyBytes, true)
addPostForHash(updateNFTMetadata.NFTPostHashHex, userPublicKeyBytes)
} else if postAssociationMetadata != nil {
addPostForHash(postAssociationMetadata.PostHashHex, userPublicKeyBytes, false)
addPostForHash(postAssociationMetadata.PostHashHex, userPublicKeyBytes)
} else if basicTransferMetadata != nil {
txnOutputs := txnMeta.Metadata.TxnOutputs
for _, output := range txnOutputs {
Expand All @@ -2380,7 +2374,7 @@ func (fes *APIServer) GetNotifications(ww http.ResponseWriter, req *http.Request
})
}
if basicTransferMetadata.PostHashHex != "" {
addPostForHash(basicTransferMetadata.PostHashHex, userPublicKeyBytes, true)
addPostForHash(basicTransferMetadata.PostHashHex, userPublicKeyBytes)
}
}

Expand Down