import {
AddAdminResponse,
BanPersonResponse,
+ BlockPersonResponse,
CommentResponse,
CommentView,
- CommunityFollowerView,
CommunityView,
GetComments,
GetCommentsResponse,
- GetFollowedCommunitiesResponse,
GetPosts,
GetPostsResponse,
GetSiteResponse,
setupTippy,
showLocal,
toast,
+ updatePersonBlock,
wsClient,
wsJsonToRes,
wsSubscribe,
import { SiteForm } from "./site-form";
interface HomeState {
- subscribedCommunities: CommunityFollowerView[];
trendingCommunities: CommunityView[];
siteRes: GetSiteResponse;
showEditSite: boolean;
private isoData = setIsoData(this.context);
private subscription: Subscription;
private emptyState: HomeState = {
- subscribedCommunities: [],
trendingCommunities: [],
siteRes: this.isoData.site_res,
showEditSite: false,
this.state.comments = this.isoData.routeData[0].comments;
}
this.state.trendingCommunities = this.isoData.routeData[1].communities;
- if (UserService.Instance.localUserView) {
- this.state.subscribedCommunities =
- this.isoData.routeData[2].communities;
- }
this.state.loading = false;
} else {
this.fetchTrendingCommunities();
this.fetchData();
- if (UserService.Instance.localUserView) {
- WebSocketService.Instance.send(
- wsClient.getFollowedCommunities({
- auth: authField(),
- })
- );
- }
}
setupTippy();
// TODO figure out auth default_listingType, default_sort_type
let type_: ListingType = pathSplit[5]
? ListingType[pathSplit[5]]
- : UserService.Instance.localUserView
+ : UserService.Instance.myUserInfo
? Object.values(ListingType)[
- UserService.Instance.localUserView.local_user.default_listing_type
+ UserService.Instance.myUserInfo.local_user_view.local_user
+ .default_listing_type
]
: ListingType.Local;
let sort: SortType = pathSplit[7]
? SortType[pathSplit[7]]
- : UserService.Instance.localUserView
+ : UserService.Instance.myUserInfo
? Object.values(SortType)[
- UserService.Instance.localUserView.local_user.default_sort_type
+ UserService.Instance.myUserInfo.local_user_view.local_user
+ .default_sort_type
]
: SortType.Active;
};
promises.push(req.client.listCommunities(trendingCommunitiesForm));
- if (req.auth) {
- promises.push(req.client.getFollowedCommunities({ auth: req.auth }));
- }
-
return promises;
}
return (
<div class="row">
<div class="col-12">
- {UserService.Instance.localUserView &&
- this.state.subscribedCommunities.length > 0 && (
+ {UserService.Instance.myUserInfo &&
+ UserService.Instance.myUserInfo.follows.length > 0 && (
<button
class="btn btn-secondary d-inline-block mb-2 mr-3"
onClick={linkEvent(this, this.handleShowSubscribedMobile)}
</div>
</div>
- {UserService.Instance.localUserView &&
- this.state.subscribedCommunities.length > 0 && (
+ {UserService.Instance.myUserInfo &&
+ UserService.Instance.myUserInfo.follows.length > 0 && (
<div class="card border-secondary mb-3">
<div class="card-body">{this.subscribedCommunities()}</div>
</div>
</T>
</h5>
<ul class="list-inline mb-0">
- {this.state.subscribedCommunities.map(cfv => (
+ {UserService.Instance.myUserInfo.follows.map(cfv => (
<li class="list-inline-item d-inline-block">
<CommunityLink community={cfv.community} />
</li>
<Icon icon="rss" classes="text-muted small" />
</a>
)}
- {UserService.Instance.localUserView &&
+ {UserService.Instance.myUserInfo &&
this.state.listingType == ListingType.Subscribed && (
<a
href={`/feeds/front/${UserService.Instance.auth}.xml?sort=${this.state.sort}`}
get canAdmin(): boolean {
return (
- UserService.Instance.localUserView &&
+ UserService.Instance.myUserInfo &&
this.state.siteRes.admins
.map(a => a.person.id)
- .includes(UserService.Instance.localUserView.person.id)
+ .includes(UserService.Instance.myUserInfo.local_user_view.person.id)
);
}
wsClient.communityJoin({ community_id: 0 })
);
this.fetchData();
- } else if (op == UserOperation.GetFollowedCommunities) {
- let data = wsJsonToRes<GetFollowedCommunitiesResponse>(msg).data;
- this.state.subscribedCommunities = data.communities;
- this.setState(this.state);
} else if (op == UserOperation.ListCommunities) {
let data = wsJsonToRes<ListCommunitiesResponse>(msg).data;
this.state.trendingCommunities = data.communities;
let nsfwCheck =
!nsfw ||
(nsfw &&
- UserService.Instance.localUserView &&
- UserService.Instance.localUserView.local_user.show_nsfw);
+ UserService.Instance.myUserInfo &&
+ UserService.Instance.myUserInfo.local_user_view.local_user.show_nsfw);
// Only push these if you're on the first page, and you pass the nsfw check
if (this.state.page == 1 && nsfwCheck) {
// If you're on subscribed, only push it if you're subscribed.
if (this.state.listingType == ListingType.Subscribed) {
if (
- this.state.subscribedCommunities
+ UserService.Instance.myUserInfo.follows
.map(c => c.community.id)
.includes(data.post_view.community.id)
) {
this.state.posts.unshift(data.post_view);
if (
- UserService.Instance.localUserView?.local_user
+ UserService.Instance.myUserInfo?.local_user_view.local_user
.show_new_post_notifs
) {
notifyPost(data.post_view, this.context.router);
if (data.post_view.post.local) {
this.state.posts.unshift(data.post_view);
if (
- UserService.Instance.localUserView?.local_user
+ UserService.Instance.myUserInfo?.local_user_view.local_user
.show_new_post_notifs
) {
notifyPost(data.post_view, this.context.router);
} else {
this.state.posts.unshift(data.post_view);
if (
- UserService.Instance.localUserView?.local_user.show_new_post_notifs
+ UserService.Instance.myUserInfo?.local_user_view.local_user
+ .show_new_post_notifs
) {
notifyPost(data.post_view, this.context.router);
}
// If you're on subscribed, only push it if you're subscribed.
if (this.state.listingType == ListingType.Subscribed) {
if (
- this.state.subscribedCommunities
+ UserService.Instance.myUserInfo.follows
.map(c => c.community.id)
.includes(data.comment_view.community.id)
) {
let data = wsJsonToRes<CommentResponse>(msg).data;
createCommentLikeRes(data.comment_view, this.state.comments);
this.setState(this.state);
+ } else if (op == UserOperation.BlockPerson) {
+ let data = wsJsonToRes<BlockPersonResponse>(msg).data;
+ updatePersonBlock(data);
}
}
}