From 399a6f847de8f8e507d16c792e5cff3f185e3557 Mon Sep 17 00:00:00 2001 From: lazynina Date: Fri, 30 Apr 2021 18:12:46 -0700 Subject: [PATCH 1/4] Initial check-in for adding blocked users to the chain --- src/app/backend-api.service.ts | 20 ++++++-- .../creator-profile-details.component.html | 13 ++--- .../creator-profile-details.component.ts | 15 ++++-- .../creator-profile-posts.component.html | 50 +++++++++---------- .../creator-profile-posts.component.ts | 16 ++++-- .../creator-profile-top-card.component.html | 8 +-- .../feed/feed-post/feed-post.component.html | 4 +- src/app/feed/feed-post/feed-post.component.ts | 9 ++-- src/app/feed/feed.component.html | 2 +- .../post-thread/post-thread.component.html | 8 +-- .../post-thread/post-thread.component.ts | 29 +++++++++-- 11 files changed, 108 insertions(+), 66 deletions(-) diff --git a/src/app/backend-api.service.ts b/src/app/backend-api.service.ts index ef336ae08..c3cc14dad 100644 --- a/src/app/backend-api.service.ts +++ b/src/app/backend-api.service.ts @@ -27,6 +27,7 @@ export class BackendRoutes { static RoutePathGetMessagesStateless = "/get-messages-stateless"; static RoutePathGetFollowsStateless = "/get-follows-stateless"; static RoutePathCreateFollowTxnStateless = "/create-follow-txn-stateless"; + static RoutePathCreateBlockPublicKeyTxnStateless = "/create-block-public-key-txn-stateless"; static RoutePathCreateLikeStateless = "/create-like-stateless"; static RoutePathBuyOrSellCreatorCoin = "/buy-or-sell-creator-coin-WVAzTWpGOFFnMlBvWXZhTFA4NjNSZGNW"; static RoutePathBuyOrSellCreatorCoinPreview = "/buy-or-sell-creator-coin-preview-WVAzTWpGOFFnMlBvWXZhTFA4NjNSZGNW"; @@ -38,7 +39,6 @@ export class BackendRoutes { static RoutePathGetSinglePost = "/get-single-post"; static RoutePathSendPhoneNumberVerificationText = "/send-phone-number-verification-text"; static RoutePathSubmitPhoneNumberVerificationCode = "/submit-phone-number-verification-code"; - static RoutePathBlockPublicKey = "/block-public-key"; static RoutePathGetBlockTemplate = "/get-block-template"; static RoutePathGetTxn = "/get-txn"; static RoutePathGetIdentities = "/get-identities"; @@ -95,6 +95,7 @@ export class ProfileEntryResponse { Posts?: PostEntryResponse[]; IsReserved?: boolean; IsVerified?: boolean; + IsBlockedByReader?: boolean; } export class User { @@ -707,8 +708,14 @@ export class BackendApiService { AddGlobalFeedBool, }); } - GetSingleProfile(endpoint: string, PublicKeyBase58Check: string, Username: string): Observable { + GetSingleProfile( + endpoint: string, + UserPublicKeyBase58Check: string, + PublicKeyBase58Check: string, + Username: string + ): Observable { return this.post(endpoint, BackendRoutes.RoutePathGetSingleProfile, { + UserPublicKeyBase58Check, PublicKeyBase58Check, Username, }); @@ -963,17 +970,20 @@ export class BackendApiService { return request; } - BlockPublicKey( + CreateBlockPublicKeyTxn( endpoint: string, PublicKeyBase58Check: string, BlockPublicKeyBase58Check: string, - Unblock: boolean = false + Unblock: boolean = false, + MinFeeRateNanosPerKB: number ): Observable { - return this.jwtPost(endpoint, BackendRoutes.RoutePathBlockPublicKey, PublicKeyBase58Check, { + const request = this.post(endpoint, BackendRoutes.RoutePathCreateBlockPublicKeyTxnStateless, { PublicKeyBase58Check, BlockPublicKeyBase58Check, Unblock, + MinFeeRateNanosPerKB, }); + return this.signAndSubmitTransaction(endpoint, request, PublicKeyBase58Check); } // Note that FetchStartIndex < 0 means "fetch me the latest notifications." diff --git a/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.html b/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.html index e131d4178..9988153ac 100644 --- a/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.html +++ b/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.html @@ -67,18 +67,19 @@
- -
+
You have blocked {{ profile.Username }}. Unblock to see their posts.
+ + +
diff --git a/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.ts b/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.ts index 0452015c6..19efdb2ac 100644 --- a/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.ts +++ b/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.ts @@ -69,15 +69,17 @@ export class CreatorProfileDetailsComponent { if (response.isConfirmed) { delete this.globalVars.loggedInUser.BlockedPubKeys[this.profile.PublicKeyBase58Check]; this.backendApi - .BlockPublicKey( + .CreateBlockPublicKeyTxn( this.globalVars.localNode, this.globalVars.loggedInUser.PublicKeyBase58Check, this.profile.PublicKeyBase58Check, - true /* unblock */ + true /* unblock */, + this.globalVars.feeRateBitCloutPerKB ) .subscribe( () => { this.globalVars.logEvent("user : unblock"); + this.profile.IsBlockedByReader = false; }, (err) => { console.log(err); @@ -113,14 +115,17 @@ export class CreatorProfileDetailsComponent { this.globalVars.loggedInUser.BlockedPubKeys[this.profile.PublicKeyBase58Check] = {}; Promise.all([ this.backendApi - .BlockPublicKey( + .CreateBlockPublicKeyTxn( this.globalVars.localNode, this.globalVars.loggedInUser.PublicKeyBase58Check, - this.profile.PublicKeyBase58Check + this.profile.PublicKeyBase58Check, + false, + this.globalVars.feeRateBitCloutPerKB * 1e9 ) .subscribe( () => { this.globalVars.logEvent("user : block"); + this.profile.IsBlockedByReader = true; }, (err) => { console.error(err); @@ -147,7 +152,7 @@ export class CreatorProfileDetailsComponent { } this.loading = true; - this.backendApi.GetSingleProfile(this.globalVars.localNode, "", this.userName).subscribe((res) => { + this.backendApi.GetSingleProfile(this.globalVars.localNode, readerPubKey, "", this.userName).subscribe((res) => { if (!res) { console.log("This profile was not found. It either does not exist or it was deleted."); return; diff --git a/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.html b/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.html index fb0bd529d..7d558c527 100644 --- a/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.html +++ b/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.html @@ -14,33 +14,31 @@
-
-
- -
-
- -
+
+ +
+
+
-
+ diff --git a/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.ts b/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.ts index 5c1127e3f..fc238462e 100644 --- a/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.ts +++ b/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.ts @@ -20,16 +20,19 @@ export class CreatorProfilePostsComponent { datasource: IDatasource> = this.getDatasource(); loadingFirstPage = true; loadingNextPage = false; - pagedKeys = { - 0: "", + initialPagedKeys = { + 0: '', }; + pagedKeys = this.initialPagedKeys; - pagedRequests = { - "-1": new Promise((resolve) => { + initialPagedRequests = { + '-1': new Promise(resolve => { resolve([]); - }), + }) }; + pagedRequests = this.initialPagedRequests; + lastPage = null; @Output() blockUser = new EventEmitter(); @@ -139,6 +142,9 @@ export class CreatorProfilePostsComponent { } userBlocked() { + this.profile.IsBlockedByReader = true; + this.pagedRequests = this.initialPagedRequests; + this.pagedKeys = this.initialPagedKeys; this.blockUser.emit(); } diff --git a/src/app/creator-profile-page/creator-profile-top-card/creator-profile-top-card.component.html b/src/app/creator-profile-page/creator-profile-top-card/creator-profile-top-card.component.html index 143c2f32d..c6e2af7fb 100644 --- a/src/app/creator-profile-page/creator-profile-top-card/creator-profile-top-card.component.html +++ b/src/app/creator-profile-page/creator-profile-top-card/creator-profile-top-card.component.html @@ -15,10 +15,10 @@
@@ -37,7 +37,7 @@ @@ -54,7 +54,7 @@ Unblock diff --git a/src/app/feed/feed-post/feed-post.component.html b/src/app/feed/feed-post/feed-post.component.html index 179ad7cf0..257e93049 100644 --- a/src/app/feed/feed-post/feed-post.component.html +++ b/src/app/feed/feed-post/feed-post.component.html @@ -28,7 +28,7 @@
{ if (response.isConfirmed) { this.backendApi - .BlockPublicKey( + .CreateBlockPublicKeyTxn( this.globalVars.localNode, this.globalVars.loggedInUser.PublicKeyBase58Check, - this.post.PosterPublicKeyBase58Check + this.post.PosterPublicKeyBase58Check, + false, + this.globalVars.feeRateBitCloutPerKB * 1e9 ) .subscribe( () => { this.globalVars.logEvent("user : block"); - this.globalVars.loggedInUser.BlockedPubKeys[this.post.PosterPublicKeyBase58Check] = {}; + this.post.ProfileEntryResponse.IsBlockedByReader = true; this.userBlocked.emit(this.post.PosterPublicKeyBase58Check); + this.ref.detectChanges(); }, (err) => { console.error(err); diff --git a/src/app/feed/feed.component.html b/src/app/feed/feed.component.html index 8984aa484..35bc0cd74 100644 --- a/src/app/feed/feed.component.html +++ b/src/app/feed/feed.component.html @@ -75,7 +75,7 @@ [contentShouldLinkToThread]="true" [showFollowLink]="showFollowLink()" [showLeftSelectedBorder]="post.IsPinned" - [blocked]="globalVars.hasUserBlockedCreator(post.PosterPublicKeyBase58Check)" + [blocked]="post.ProfileEntryResponse.IsBlockedByReader" (postDeleted)="onPostHidden($event)" (userBlocked)="userBlocked()" > diff --git a/src/app/post-thread-page/post-thread/post-thread.component.html b/src/app/post-thread-page/post-thread/post-thread.component.html index ed6502dd4..ce4e583af 100644 --- a/src/app/post-thread-page/post-thread/post-thread.component.html +++ b/src/app/post-thread-page/post-thread/post-thread.component.html @@ -24,7 +24,7 @@ [showThreadConnectionLine]="true" [blocked]="isPostBlocked(parentPost)" (postDeleted)="onPostHidden(currentPost, null, null)" - (userBlocked)="afterUserBlocked($event)" + (userBlocked)="userBlocked($event)" >
@@ -41,7 +41,7 @@ [showLeftSelectedBorder]="true" [blocked]="isPostBlocked(currentPost)" (postDeleted)="onPostHidden(currentPost, null, null)" - (userBlocked)="afterUserBlocked($event)" + (userBlocked)="userBlocked($event)" >
@@ -61,7 +61,7 @@ [afterCommentCreatedCallback]="prependToSubcommentList.bind(this, item, currentPost)" [blocked]="isPostBlocked(item)" (postDeleted)="onPostHidden(item, currentPost, null)" - (userBlocked)="afterUserBlocked($event)" + (userBlocked)="userBlocked($event)" >
@@ -81,7 +81,7 @@ [afterCommentCreatedCallback]="appendToSubcommentList.bind(this, item, currentPost)" [blocked]="isPostBlocked(subcommentPost)" (postDeleted)="onPostHidden(subcommentPost, item, currentPost)" - (userBlocked)="afterUserBlocked($event)" + (userBlocked)="userBlocked($event)" >
diff --git a/src/app/post-thread-page/post-thread/post-thread.component.ts b/src/app/post-thread-page/post-thread/post-thread.component.ts index 3373b4ec1..c27433b9a 100644 --- a/src/app/post-thread-page/post-thread/post-thread.component.ts +++ b/src/app/post-thread-page/post-thread/post-thread.component.ts @@ -1,7 +1,7 @@ import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from "@angular/core"; import { ActivatedRoute, Router } from "@angular/router"; import { GlobalVarsService } from "../../global-vars.service"; -import { BackendApiService } from "../../backend-api.service"; +import { BackendApiService, PostEntryResponse } from "../../backend-api.service"; import { FeedComponent } from "../../feed/feed.component"; import { Datasource, IDatasource, IAdapter } from "ngx-ui-scroll"; import { ToastrService } from "ngx-toastr"; @@ -323,11 +323,30 @@ export class PostThreadComponent { this.datasource.adapter.reset(); } - isPostBlocked(post: any): boolean { - return this.globalVars.hasUserBlockedCreator(post.PosterPublicKeyBase58Check); + isPostBlocked(post: PostEntryResponse): boolean { + return post.ProfileEntryResponse.IsBlockedByReader; } - afterUserBlocked(blockedPubKey: any) { - this.globalVars.loggedInUser.BlockedPubKeys[blockedPubKey] = {}; + async userBlocked(posterPublicKey: string): Promise { + for (const post of this.currentPost.ParentPosts) { + if (post.PosterPublicKeyBase58Check === posterPublicKey) { + post.ProfileEntryResponse.IsBlockedByReader = true; + } + } + if (this.currentPost.PosterPublicKeyBase58Check === posterPublicKey) { + this.currentPost.ProfileEntryResponse.IsBlockedByReader = true; + } + await this.datasource.adapter.relax(); + await this.datasource.adapter.update({ + predicate: ({ $index, data, element}) => { + let currentPost = (data as any) as PostEntryResponse; + console.log(currentPost); + if (currentPost.PosterPublicKeyBase58Check === posterPublicKey) { + currentPost.ProfileEntryResponse.IsBlockedByReader = true; + } + currentPost = _.cloneDeep(currentPost); + return [currentPost]; + } + }); } } From a3b9bf6e05f89c1f51019b639d4f098fbe2ab779 Mon Sep 17 00:00:00 2001 From: lazynina Date: Fri, 30 Apr 2021 18:16:58 -0700 Subject: [PATCH 2/4] resolve linting issues and remove users blocked map --- .../creator-profile-details.component.ts | 2 -- src/app/post-thread-page/post-thread/post-thread.component.ts | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.ts b/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.ts index 19efdb2ac..cef88b7a9 100644 --- a/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.ts +++ b/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.ts @@ -67,7 +67,6 @@ export class CreatorProfileDetailsComponent { }).then((response: any) => { this.userUnblocked.emit(this.profile.PublicKeyBase58Check); if (response.isConfirmed) { - delete this.globalVars.loggedInUser.BlockedPubKeys[this.profile.PublicKeyBase58Check]; this.backendApi .CreateBlockPublicKeyTxn( this.globalVars.localNode, @@ -112,7 +111,6 @@ export class CreatorProfileDetailsComponent { reverseButtons: true, }).then((response: any) => { if (response.isConfirmed) { - this.globalVars.loggedInUser.BlockedPubKeys[this.profile.PublicKeyBase58Check] = {}; Promise.all([ this.backendApi .CreateBlockPublicKeyTxn( diff --git a/src/app/post-thread-page/post-thread/post-thread.component.ts b/src/app/post-thread-page/post-thread/post-thread.component.ts index c27433b9a..074e4825d 100644 --- a/src/app/post-thread-page/post-thread/post-thread.component.ts +++ b/src/app/post-thread-page/post-thread/post-thread.component.ts @@ -338,7 +338,7 @@ export class PostThreadComponent { } await this.datasource.adapter.relax(); await this.datasource.adapter.update({ - predicate: ({ $index, data, element}) => { + predicate: ({ $index, data, element }) => { let currentPost = (data as any) as PostEntryResponse; console.log(currentPost); if (currentPost.PosterPublicKeyBase58Check === posterPublicKey) { @@ -346,7 +346,7 @@ export class PostThreadComponent { } currentPost = _.cloneDeep(currentPost); return [currentPost]; - } + }, }); } } From 8f8f2b288ac4f323910bf214d0992d51f61cfdef Mon Sep 17 00:00:00 2001 From: lazynina Date: Fri, 30 Apr 2021 18:58:45 -0700 Subject: [PATCH 3/4] enable change detection for post thread comments and profile posts so block user dropdown element shows up, fix fee on unblock action --- .../creator-profile-details.component.ts | 2 +- .../creator-profile-posts.component.html | 1 + .../creator-profile-posts/creator-profile-posts.component.ts | 4 +--- .../feed/feed-post-dropdown/feed-post-dropdown.component.ts | 2 +- .../post-thread-page/post-thread/post-thread.component.html | 1 + 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.ts b/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.ts index cef88b7a9..cbf86d4b1 100644 --- a/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.ts +++ b/src/app/creator-profile-page/creator-profile-details/creator-profile-details.component.ts @@ -73,7 +73,7 @@ export class CreatorProfileDetailsComponent { this.globalVars.loggedInUser.PublicKeyBase58Check, this.profile.PublicKeyBase58Check, true /* unblock */, - this.globalVars.feeRateBitCloutPerKB + this.globalVars.feeRateBitCloutPerKB * 1e9 ) .subscribe( () => { diff --git a/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.html b/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.html index 7d558c527..1ecd7c63a 100644 --- a/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.html +++ b/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.html @@ -22,6 +22,7 @@ [post]="post" [afterCommentCreatedCallback]="_prependComment.bind(this, post)" [blocked]="profile.IsBlockedByReader" + [enableChangeDetection]="true" (userBlocked)="userBlocked()" >
diff --git a/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.ts b/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.ts index fc238462e..ea3c4e832 100644 --- a/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.ts +++ b/src/app/creator-profile-page/creator-profile-posts/creator-profile-posts.component.ts @@ -44,9 +44,7 @@ export class CreatorProfilePostsComponent { private cdr: ChangeDetectorRef, private router: Router, private location: Location - ) { - // this.datasource = this.getDatasource(); - } + ) {} // TODO: Cleanup - Create InfiniteScroller class to de-duplicate this logic getDatasource() { diff --git a/src/app/feed/feed-post-dropdown/feed-post-dropdown.component.ts b/src/app/feed/feed-post-dropdown/feed-post-dropdown.component.ts index f08757ebf..921a010d2 100644 --- a/src/app/feed/feed-post-dropdown/feed-post-dropdown.component.ts +++ b/src/app/feed/feed-post-dropdown/feed-post-dropdown.component.ts @@ -31,7 +31,7 @@ export class FeedPostDropdownComponent { // User shouldn't be able to block themselves return ( this.globalVars.loggedInUser?.PublicKeyBase58Check !== this.post.PosterPublicKeyBase58Check && - !this.globalVars.hasUserBlockedCreator(this.post.PosterPublicKeyBase58Check) + !this.post.ProfileEntryResponse.IsBlockedByReader ); } diff --git a/src/app/post-thread-page/post-thread/post-thread.component.html b/src/app/post-thread-page/post-thread/post-thread.component.html index ce4e583af..a6805d5f9 100644 --- a/src/app/post-thread-page/post-thread/post-thread.component.html +++ b/src/app/post-thread-page/post-thread/post-thread.component.html @@ -60,6 +60,7 @@ [showReplyingToContent]="true" [afterCommentCreatedCallback]="prependToSubcommentList.bind(this, item, currentPost)" [blocked]="isPostBlocked(item)" + [enableChangeDetection]="true" (postDeleted)="onPostHidden(item, currentPost, null)" (userBlocked)="userBlocked($event)" > From d02d4cea1e679bfb35464d982e26ccc2a028295d Mon Sep 17 00:00:00 2001 From: lazynina Date: Sun, 9 May 2021 16:36:27 -0700 Subject: [PATCH 4/4] fix event emitting for add to global feed and pin to feed --- src/app/feed/feed-post/feed-post.component.html | 7 ++++--- src/app/feed/feed-post/feed-post.component.ts | 8 ++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/app/feed/feed-post/feed-post.component.html b/src/app/feed/feed-post/feed-post.component.html index 02bafe0fb..95ab7d941 100644 --- a/src/app/feed/feed-post/feed-post.component.html +++ b/src/app/feed/feed-post/feed-post.component.html @@ -80,7 +80,8 @@ [postContent]="postContent" (postHidden)="hidePost()" (userBlocked)="blockUser()" - (toggleGlobalFeed)="_addPostToGlobalFeed()" + (toggleGlobalFeed)="_addPostToGlobalFeed($event)" + (togglePostPin)="_pinPostToGlobalFeed($event)" >
@@ -175,8 +176,8 @@ [postContent]="postContent" (postHidden)="hidePost()" (userBlocked)="blockUser()" - (toggleGlobalFeed)="_addPostToGlobalFeed(event)" - (togglePostPin)="_pinPostToGlobalFeed(event)" + (toggleGlobalFeed)="_addPostToGlobalFeed($event)" + (togglePostPin)="_pinPostToGlobalFeed($event)" > diff --git a/src/app/feed/feed-post/feed-post.component.ts b/src/app/feed/feed-post/feed-post.component.ts index c6ea3ce9b..62a7626c7 100644 --- a/src/app/feed/feed-post/feed-post.component.ts +++ b/src/app/feed/feed-post/feed-post.component.ts @@ -331,9 +331,7 @@ export class FeedPostComponent implements OnInit { _addPostToGlobalFeed(event: any) { // Prevent the post from navigating. - if (event) { - event.stopPropagation(); - } + event.stopPropagation(); this.addingPostToGlobalFeed = true; const postHashHex = this.post.PostHashHex; @@ -367,9 +365,7 @@ export class FeedPostComponent implements OnInit { _pinPostToGlobalFeed(event: any) { // Prevent the post from navigating. - if (event) { - event.stopPropagation(); - } + event.stopPropagation(); this.pinningPost = true; const postHashHex = this._post.PostHashHex;