Skip to content

Commit 9a04dd1

Browse files
authored
Ln/support no profile pub key in notifications and get single post (#737)
* Support public key with no profile in notifications and get single post * update condition skipping public keys with no profile
1 parent 47d6400 commit 9a04dd1

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

routes/post.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,9 +1362,7 @@ func (fes *APIServer) GetSinglePost(ww http.ResponseWriter, req *http.Request) {
13621362
pubKeyToProfileEntryResponseMap := make(map[lib.PkMapKey]*ProfileEntryResponse)
13631363
for _, pubKeyBytes := range filteredProfilePubKeyMap {
13641364
profileEntry := utxoView.GetProfileEntryForPublicKey(pubKeyBytes)
1365-
if profileEntry == nil {
1366-
continue
1367-
} else {
1365+
if profileEntry != nil {
13681366
pubKeyToProfileEntryResponseMap[lib.MakePkMapKey(pubKeyBytes)] =
13691367
fes._profileEntryToResponse(profileEntry, utxoView)
13701368
}
@@ -1510,15 +1508,16 @@ func (fes *APIServer) GetSinglePostComments(
15101508
if _, ok := blockedPublicKeys[lib.PkToString(commentEntry.PosterPublicKey, fes.Params)]; !ok && profilePubKeyMap[pkMapKey] == nil {
15111509
profilePubKeyMap[pkMapKey] = commentEntry.PosterPublicKey
15121510
}
1513-
commentProfileEntryResponse, pubKeyKeyExistsInMap := pubKeyToProfileEntryResponseMap[lib.MakePkMapKey(commentEntry.PosterPublicKey)]
1511+
commentProfileEntryResponse, _ := pubKeyToProfileEntryResponseMap[lib.MakePkMapKey(commentEntry.PosterPublicKey)]
15141512
commentAuthorIsCurrentPoster := reflect.DeepEqual(commentEntry.PosterPublicKey, posterPublicKeyBytes)
15151513
// Skip comments that:
15161514
// - Don't have a profile (it was most likely banned). UPDATE: only remove if public key is blacklisted.
15171515
// - Are hidden *AND* don't have comments. Keep hidden posts with comments.
15181516
// - isDeleted (this was already filtered in an earlier stage and should never be true)
15191517
// - Skip comment is it's by the poster of the single post we are fetching and the currentPoster is blocked by
15201518
// the reader
1521-
if (commentProfileEntryResponse == nil && !pubKeyKeyExistsInMap) || commentEntry.IsDeleted() ||
1519+
_, pubKeyExistsInMap := profilePubKeyMap[lib.MakePkMapKey(commentEntry.PosterPublicKey)]
1520+
if (commentProfileEntryResponse == nil && !pubKeyExistsInMap) || commentEntry.IsDeleted() ||
15221521
(commentEntry.IsHidden && commentEntry.CommentCount == 0) ||
15231522
(commentAuthorIsCurrentPoster && isCurrentPosterBlocked) {
15241523
continue
@@ -1544,6 +1543,7 @@ func (fes *APIServer) GetSinglePostComments(
15441543
sort.Slice(commentEntryResponseList, func(ii, jj int) bool {
15451544
iiCommentEntryResponse := commentEntryResponseList[ii]
15461545
jjCommentEntryResponse := commentEntryResponseList[jj]
1546+
15471547
// If the poster of ii is the poster of the main post and jj is not, ii should be first.
15481548
iiIsPoster := iiCommentEntryResponse.PostEntryResponse.PosterPublicKeyBase58Check == postEntryResponse.PosterPublicKeyBase58Check
15491549
jjIsPoster := jjCommentEntryResponse.PostEntryResponse.PosterPublicKeyBase58Check == postEntryResponse.PosterPublicKeyBase58Check

routes/user.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,7 +2297,7 @@ func (fes *APIServer) GetNotifications(ww http.ResponseWriter, req *http.Request
22972297
// heavy lifting.
22982298
postEntryResponses := make(map[string]*PostEntryResponse)
22992299

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

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

2321-
// Filter out responses if profile entry is missing and is required
2322-
if profileEntryRequired && profileEntryResponse == nil {
2323-
postEntryResponses[postHashHex] = nil
2324-
return
2325-
}
2326-
23272321
postEntryResponse, err := fes._postEntryToResponse(postEntry, false, fes.Params, utxoView, userPublicKeyBytes, 2)
23282322
if err != nil {
23292323
return
@@ -2349,26 +2343,26 @@ func (fes *APIServer) GetNotifications(ww http.ResponseWriter, req *http.Request
23492343
postAssociationMetadata := txnMeta.Metadata.CreatePostAssociationTxindexMetadata
23502344

23512345
if postMetadata != nil {
2352-
addPostForHash(postMetadata.PostHashBeingModifiedHex, userPublicKeyBytes, true)
2353-
addPostForHash(postMetadata.ParentPostHashHex, userPublicKeyBytes, true)
2346+
addPostForHash(postMetadata.PostHashBeingModifiedHex, userPublicKeyBytes)
2347+
addPostForHash(postMetadata.ParentPostHashHex, userPublicKeyBytes)
23542348
} else if likeMetadata != nil {
2355-
addPostForHash(likeMetadata.PostHashHex, userPublicKeyBytes, true)
2349+
addPostForHash(likeMetadata.PostHashHex, userPublicKeyBytes)
23562350
} else if transferCreatorCoinMetadata != nil {
23572351
if transferCreatorCoinMetadata.PostHashHex != "" {
2358-
addPostForHash(transferCreatorCoinMetadata.PostHashHex, userPublicKeyBytes, true)
2352+
addPostForHash(transferCreatorCoinMetadata.PostHashHex, userPublicKeyBytes)
23592353
}
23602354
} else if nftBidMetadata != nil {
2361-
addPostForHash(nftBidMetadata.NFTPostHashHex, userPublicKeyBytes, true)
2355+
addPostForHash(nftBidMetadata.NFTPostHashHex, userPublicKeyBytes)
23622356
} else if acceptNFTBidMetadata != nil {
2363-
addPostForHash(acceptNFTBidMetadata.NFTPostHashHex, userPublicKeyBytes, true)
2357+
addPostForHash(acceptNFTBidMetadata.NFTPostHashHex, userPublicKeyBytes)
23642358
} else if nftTransferMetadata != nil {
2365-
addPostForHash(nftTransferMetadata.NFTPostHashHex, userPublicKeyBytes, false)
2359+
addPostForHash(nftTransferMetadata.NFTPostHashHex, userPublicKeyBytes)
23662360
} else if createNFTMetadata != nil {
2367-
addPostForHash(createNFTMetadata.NFTPostHashHex, userPublicKeyBytes, true)
2361+
addPostForHash(createNFTMetadata.NFTPostHashHex, userPublicKeyBytes)
23682362
} else if updateNFTMetadata != nil {
2369-
addPostForHash(updateNFTMetadata.NFTPostHashHex, userPublicKeyBytes, true)
2363+
addPostForHash(updateNFTMetadata.NFTPostHashHex, userPublicKeyBytes)
23702364
} else if postAssociationMetadata != nil {
2371-
addPostForHash(postAssociationMetadata.PostHashHex, userPublicKeyBytes, false)
2365+
addPostForHash(postAssociationMetadata.PostHashHex, userPublicKeyBytes)
23722366
} else if basicTransferMetadata != nil {
23732367
txnOutputs := txnMeta.Metadata.TxnOutputs
23742368
for _, output := range txnOutputs {
@@ -2380,7 +2374,7 @@ func (fes *APIServer) GetNotifications(ww http.ResponseWriter, req *http.Request
23802374
})
23812375
}
23822376
if basicTransferMetadata.PostHashHex != "" {
2383-
addPostForHash(basicTransferMetadata.PostHashHex, userPublicKeyBytes, true)
2377+
addPostForHash(basicTransferMetadata.PostHashHex, userPublicKeyBytes)
23842378
}
23852379
}
23862380

0 commit comments

Comments
 (0)