diff --git a/routes/post.go b/routes/post.go index ad658cd5..55a8240c 100644 --- a/routes/post.go +++ b/routes/post.go @@ -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) } @@ -1510,7 +1508,7 @@ 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. @@ -1518,7 +1516,8 @@ func (fes *APIServer) GetSinglePostComments( // - 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 @@ -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 diff --git a/routes/user.go b/routes/user.go index 88a1e0b9..16d38542 100644 --- a/routes/user.go +++ b/routes/user.go @@ -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 @@ -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 @@ -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 { @@ -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) } }