diff --git a/src/app/backend-api.service.ts b/src/app/backend-api.service.ts index 3f8d8e496..9b1deced7 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"; @@ -99,6 +99,7 @@ export class ProfileEntryResponse { Posts?: PostEntryResponse[]; IsReserved?: boolean; IsVerified?: boolean; + IsBlockedByReader?: boolean; } export class User { @@ -716,8 +717,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, }); @@ -1001,17 +1008,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 a4dcaec74..7c6a413cb 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,20 @@
- -
+
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 25c638106..94644bc30 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 @@ -76,17 +76,18 @@ 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 - .BlockPublicKey( + .CreateBlockPublicKeyTxn( this.globalVars.localNode, this.globalVars.loggedInUser.PublicKeyBase58Check, this.profile.PublicKeyBase58Check, - true /* unblock */ + true /* unblock */, + this.globalVars.feeRateBitCloutPerKB * 1e9 ) .subscribe( () => { this.globalVars.logEvent("user : unblock"); + this.profile.IsBlockedByReader = false; }, (err) => { console.log(err); @@ -119,17 +120,19 @@ export class CreatorProfileDetailsComponent { reverseButtons: true, }).then((response: any) => { if (response.isConfirmed) { - 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); @@ -156,7 +159,7 @@ export class CreatorProfileDetailsComponent { } this.loading = true; - this.backendApi.GetSingleProfile(this.globalVars.localNode, "", this.userName).subscribe( + 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."); 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..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 @@ -14,33 +14,32 @@
-
-
- -
-
- -
+
+ +
+
+
-
+ 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..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 @@ -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(); @@ -41,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() { @@ -139,6 +140,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 0f2fe6a30..93723831b 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-dropdown/feed-post-dropdown.component.ts b/src/app/feed/feed-post-dropdown/feed-post-dropdown.component.ts index c9e835c98..747cd9174 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 @@ -39,7 +39,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/feed/feed-post/feed-post.component.html b/src/app/feed/feed-post/feed-post.component.html index d8db7d091..95ab7d941 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 @@
@@ -80,7 +80,8 @@ [postContent]="postContent" (postHidden)="hidePost()" (userBlocked)="blockUser()" - (toggleGlobalFeed)="_addPostToGlobalFeed()" + (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 d19917b37..62a7626c7 100644 --- a/src/app/feed/feed-post/feed-post.component.ts +++ b/src/app/feed/feed-post/feed-post.component.ts @@ -224,16 +224,19 @@ export class FeedPostComponent implements OnInit { }).then((response: any) => { 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 e944c08b5..f73f745c3 100644 --- a/src/app/feed/feed.component.html +++ b/src/app/feed/feed.component.html @@ -66,7 +66,7 @@ [contentShouldLinkToThread]="true" [hideFollowLink]="hideFollowLink()" [showLeftSelectedBorder]="post.IsPinned" - [blocked]="globalVars.hasUserBlockedCreator(post.PosterPublicKeyBase58Check)" + [blocked]="post.ProfileEntryResponse.IsBlockedByReader" (postDeleted)="onPostHidden($event)" (userBlocked)="userBlocked()" > diff --git a/src/app/follow-button/follow-button.component.ts b/src/app/follow-button/follow-button.component.ts index 85748cb6b..f74f7ef08 100644 --- a/src/app/follow-button/follow-button.component.ts +++ b/src/app/follow-button/follow-button.component.ts @@ -36,7 +36,9 @@ export class FollowButtonComponent implements OnInit, OnDestroy { changeRef: ChangeDetectorRef; unfollow(event) { - event.stopPropagation(); + if (event) { + event.stopPropagation(); + } this._toggleFollow(false); } 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 122f288cb..d215c659a 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 @@ -25,7 +25,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)" >
@@ -60,8 +60,9 @@ [showReplyingToContent]="true" [afterCommentCreatedCallback]="prependToSubcommentList.bind(this, item, currentPost)" [blocked]="isPostBlocked(item)" + [enableChangeDetection]="true" (postDeleted)="onPostHidden(item, currentPost, null)" - (userBlocked)="afterUserBlocked($event)" + (userBlocked)="userBlocked($event)" >
@@ -81,7 +82,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..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 @@ -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]; + }, + }); } }