From: Dessalines Date: Mon, 15 Mar 2021 18:09:31 +0000 (-0400) Subject: user_ -> person table migration. X-Git-Url: http://these/git/%22https:/image.com/%7BprofileRss%7D?a=commitdiff_plain;h=440fda9d51385c1eef38f6c1e0e6ed931b12b915;p=lemmy-ui.git user_ -> person table migration. --- diff --git a/package.json b/package.json index 96fd0c2..ef7b088 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "eslint": "^7.20.0", "eslint-plugin-prettier": "^3.3.1", "husky": "^5.1.0", - "lemmy-js-client": "0.10.0-rc.1", + "lemmy-js-client": "0.10.0-rc.5", "lint-staged": "^10.5.4", "mini-css-extract-plugin": "^1.3.8", "node-fetch": "^2.6.1", diff --git a/src/server/index.tsx b/src/server/index.tsx index bb0ac3a..748494c 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -67,7 +67,7 @@ server.get("/*", async (req, res) => { ? req.headers["accept-language"].split(",")[0] : "en"; let lang = site.my_user - ? site.my_user.lang == "browser" + ? site.my_user.local_user.lang == "browser" ? acceptLang : "en" : acceptLang; diff --git a/src/shared/components/admin-settings.tsx b/src/shared/components/admin-settings.tsx index accefe1..0836a16 100644 --- a/src/shared/components/admin-settings.tsx +++ b/src/shared/components/admin-settings.tsx @@ -23,7 +23,7 @@ import { } from "../utils"; import autosize from "autosize"; import { SiteForm } from "./site-form"; -import { UserListing } from "./user-listing"; +import { PersonListing } from "./person-listing"; import { HtmlTags } from "./html-tags"; import { Spinner } from "./icon"; import { i18n } from "../i18next"; @@ -135,7 +135,7 @@ export class AdminSettings extends Component { @@ -150,7 +150,7 @@ export class AdminSettings extends Component {
    {this.state.siteRes.banned.map(banned => (
  • - +
  • ))}
diff --git a/src/shared/components/app.tsx b/src/shared/components/app.tsx index 6f49e2c..262e4b5 100644 --- a/src/shared/components/app.tsx +++ b/src/shared/components/app.tsx @@ -26,7 +26,7 @@ export class App extends Component { <>
- + {siteRes && siteRes.site_view && this.props.siteRes.site_view.site.icon && ( diff --git a/src/shared/components/comment-form.tsx b/src/shared/components/comment-form.tsx index 5c21b2d..2677594 100644 --- a/src/shared/components/comment-form.tsx +++ b/src/shared/components/comment-form.tsx @@ -68,7 +68,7 @@ export class CommentForm extends Component { render() { return (
- {UserService.Instance.user ? ( + {UserService.Instance.localUserView ? ( { let op = wsUserOp(msg); // Only do the showing and hiding if logged in - if (UserService.Instance.user) { + if (UserService.Instance.localUserView) { if ( op == UserOperation.CreateComment || op == UserOperation.EditComment diff --git a/src/shared/components/comment-node.tsx b/src/shared/components/comment-node.tsx index 6b5fc0e..c6ba1a5 100644 --- a/src/shared/components/comment-node.tsx +++ b/src/shared/components/comment-node.tsx @@ -5,18 +5,18 @@ import { DeleteComment, RemoveComment, MarkCommentAsRead, - MarkUserMentionAsRead, + MarkPersonMentionAsRead, SaveComment, BanFromCommunity, - BanUser, + BanPerson, CommunityModeratorView, - UserViewSafe, + PersonViewSafe, AddModToCommunity, AddAdmin, TransferCommunity, TransferSite, CommentView, - UserMentionView, + PersonMentionView, } from "lemmy-js-client"; import { CommentNode as CommentNodeI, BanType } from "../interfaces"; import { WebSocketService, UserService } from "../services"; @@ -34,7 +34,7 @@ import moment from "moment"; import { MomentTime } from "./moment-time"; import { CommentForm } from "./comment-form"; import { CommentNodes } from "./comment-nodes"; -import { UserListing } from "./user-listing"; +import { PersonListing } from "./person-listing"; import { CommunityLink } from "./community-link"; import { Icon, Spinner } from "./icon"; import { i18n } from "../i18next"; @@ -74,7 +74,7 @@ interface CommentNodeProps { markable?: boolean; showContext?: boolean; moderators: CommunityModeratorView[]; - admins: UserViewSafe[]; + admins: PersonViewSafe[]; // TODO is this necessary, can't I get it from the node itself? postCreatorId?: number; showCommunity?: boolean; @@ -156,7 +156,7 @@ export class CommentNode extends Component { >
- + {this.isMod && ( @@ -270,7 +270,7 @@ export class CommentNode extends Component { )} )} - {UserService.Instance.user && !this.props.viewOnly && ( + {UserService.Instance.localUserView && !this.props.viewOnly && ( <>
@@ -142,9 +142,9 @@ export class CreatePrivateMessage extends Component< this.state.loading = false; this.setState(this.state); return; - } else if (op == UserOperation.GetUserDetails) { - let data = wsJsonToRes(msg).data; - this.state.recipient = data.user_view; + } else if (op == UserOperation.GetPersonDetails) { + let data = wsJsonToRes(msg).data; + this.state.recipient = data.person_view; this.state.loading = false; this.setState(this.state); } diff --git a/src/shared/components/image-upload-form.tsx b/src/shared/components/image-upload-form.tsx index fb9c9ca..b8b94c2 100644 --- a/src/shared/components/image-upload-form.tsx +++ b/src/shared/components/image-upload-form.tsx @@ -65,7 +65,7 @@ export class ImageUploadForm extends Component< accept="image/*,video/*" name={this.id} class="d-none" - disabled={!UserService.Instance.user} + disabled={!UserService.Instance.localUserView} onChange={linkEvent(this, this.handleImageUpload)} /> diff --git a/src/shared/components/inbox.tsx b/src/shared/components/inbox.tsx index 5c7f798..677d905 100644 --- a/src/shared/components/inbox.tsx +++ b/src/shared/components/inbox.tsx @@ -6,16 +6,16 @@ import { SortType, GetReplies, GetRepliesResponse, - GetUserMentions, - GetUserMentionsResponse, - UserMentionResponse, + GetPersonMentions, + GetPersonMentionsResponse, + PersonMentionResponse, CommentResponse, PrivateMessageView, GetPrivateMessages, PrivateMessagesResponse, PrivateMessageResponse, SiteView, - UserMentionView, + PersonMentionView, } from "lemmy-js-client"; import { WebSocketService, UserService } from "../services"; import { @@ -62,7 +62,7 @@ enum ReplyEnum { type ReplyType = { id: number; type_: ReplyEnum; - view: CommentView | PrivateMessageView | UserMentionView; + view: CommentView | PrivateMessageView | PersonMentionView; published: string; }; @@ -70,7 +70,7 @@ interface InboxState { unreadOrAll: UnreadOrAll; messageType: MessageType; replies: CommentView[]; - mentions: UserMentionView[]; + mentions: PersonMentionView[]; messages: PrivateMessageView[]; combined: ReplyType[]; sort: SortType; @@ -101,7 +101,7 @@ export class Inbox extends Component { this.state = this.emptyState; this.handleSortChange = this.handleSortChange.bind(this); - if (!UserService.Instance.user && isBrowser()) { + if (!UserService.Instance.localUserView && isBrowser()) { toast(i18n.t("not_logged_in"), "danger"); this.context.router.history.push(`/login`); } @@ -128,9 +128,9 @@ export class Inbox extends Component { } get documentTitle(): string { - return `@${UserService.Instance.user.name} ${i18n.t("inbox")} - ${ - this.state.site_view.site.name - }`; + return `@${UserService.Instance.localUserView.person.name} ${i18n.t( + "inbox" + )} - ${this.state.site_view.site.name}`; } render() { @@ -307,9 +307,9 @@ export class Inbox extends Component { }; } - mentionToReplyType(r: UserMentionView): ReplyType { + mentionToReplyType(r: PersonMentionView): ReplyType { return { - id: r.user_mention.id, + id: r.person_mention.id, type_: ReplyEnum.Mention, view: r, published: r.comment.published, @@ -359,7 +359,7 @@ export class Inbox extends Component { return ( {
{this.state.mentions.map(umv => ( { }; promises.push(req.client.getReplies(repliesForm)); - let userMentionsForm: GetUserMentions = { + let personMentionsForm: GetPersonMentions = { sort: SortType.New, unread_only: true, page: 1, limit: fetchLimit, auth: req.auth, }; - promises.push(req.client.getUserMentions(userMentionsForm)); + promises.push(req.client.getPersonMentions(personMentionsForm)); let privateMessagesForm: GetPrivateMessages = { unread_only: true, @@ -521,14 +521,16 @@ export class Inbox extends Component { }; WebSocketService.Instance.send(wsClient.getReplies(repliesForm)); - let userMentionsForm: GetUserMentions = { + let personMentionsForm: GetPersonMentions = { sort: this.state.sort, unread_only: this.state.unreadOrAll == UnreadOrAll.Unread, page: this.state.page, limit: fetchLimit, auth: authField(), }; - WebSocketService.Instance.send(wsClient.getUserMentions(userMentionsForm)); + WebSocketService.Instance.send( + wsClient.getPersonMentions(personMentionsForm) + ); let privateMessagesForm: GetPrivateMessages = { unread_only: this.state.unreadOrAll == UnreadOrAll.Unread, @@ -579,8 +581,8 @@ export class Inbox extends Component { window.scrollTo(0, 0); this.setState(this.state); setupTippy(); - } else if (op == UserOperation.GetUserMentions) { - let data = wsJsonToRes(msg).data; + } else if (op == UserOperation.GetPersonMentions) { + let data = wsJsonToRes(msg).data; this.state.mentions = data.mentions; this.state.combined = this.buildCombined(); this.sendUnreadCount(); @@ -698,48 +700,49 @@ export class Inbox extends Component { this.sendUnreadCount(); this.setState(this.state); setupTippy(); - } else if (op == UserOperation.MarkUserMentionAsRead) { - let data = wsJsonToRes(msg).data; + } else if (op == UserOperation.MarkPersonMentionAsRead) { + let data = wsJsonToRes(msg).data; // TODO this might not be correct, it might need to use the comment id let found = this.state.mentions.find( - c => c.user_mention.id == data.user_mention_view.user_mention.id + c => c.person_mention.id == data.person_mention_view.person_mention.id ); if (found) { let combinedView = this.state.combined.find( - i => i.id == data.user_mention_view.user_mention.id - ).view as UserMentionView; + i => i.id == data.person_mention_view.person_mention.id + ).view as PersonMentionView; found.comment.content = combinedView.comment.content = - data.user_mention_view.comment.content; + data.person_mention_view.comment.content; found.comment.updated = combinedView.comment.updated = - data.user_mention_view.comment.updated; + data.person_mention_view.comment.updated; found.comment.removed = combinedView.comment.removed = - data.user_mention_view.comment.removed; + data.person_mention_view.comment.removed; found.comment.deleted = combinedView.comment.deleted = - data.user_mention_view.comment.deleted; + data.person_mention_view.comment.deleted; found.counts.upvotes = combinedView.counts.upvotes = - data.user_mention_view.counts.upvotes; + data.person_mention_view.counts.upvotes; found.counts.downvotes = combinedView.counts.downvotes = - data.user_mention_view.counts.downvotes; + data.person_mention_view.counts.downvotes; found.counts.score = combinedView.counts.score = - data.user_mention_view.counts.score; + data.person_mention_view.counts.score; // If youre in the unread view, just remove it from the list if ( this.state.unreadOrAll == UnreadOrAll.Unread && - data.user_mention_view.user_mention.read + data.person_mention_view.person_mention.read ) { this.state.mentions = this.state.mentions.filter( - r => r.user_mention.id !== data.user_mention_view.user_mention.id + r => + r.person_mention.id !== data.person_mention_view.person_mention.id ); this.state.combined = this.state.combined.filter( - r => r.id !== data.user_mention_view.user_mention.id + r => r.id !== data.person_mention_view.person_mention.id ); } else { // TODO test to make sure these mentions are getting marked as read - found.user_mention.read = combinedView.user_mention.read = - data.user_mention_view.user_mention.read; + found.person_mention.read = combinedView.person_mention.read = + data.person_mention_view.person_mention.read; } } this.sendUnreadCount(); @@ -747,18 +750,26 @@ export class Inbox extends Component { } else if (op == UserOperation.CreateComment) { let data = wsJsonToRes(msg).data; - if (data.recipient_ids.includes(UserService.Instance.user.id)) { + if ( + data.recipient_ids.includes( + UserService.Instance.localUserView.local_user.id + ) + ) { this.state.replies.unshift(data.comment_view); this.state.combined.unshift(this.replyToReplyType(data.comment_view)); this.setState(this.state); - } else if (data.comment_view.creator.id == UserService.Instance.user.id) { + } else if ( + data.comment_view.creator.id == + UserService.Instance.localUserView.person.id + ) { // TODO this seems wrong, you should be using form_id toast(i18n.t("reply_sent")); } } else if (op == UserOperation.CreatePrivateMessage) { let data = wsJsonToRes(msg).data; if ( - data.private_message_view.recipient.id == UserService.Instance.user.id + data.private_message_view.recipient.id == + UserService.Instance.localUserView.person.id ) { this.state.messages.unshift(data.private_message_view); this.state.combined.unshift( @@ -785,13 +796,13 @@ export class Inbox extends Component { unreadCount(): number { return ( this.state.replies.filter(r => !r.comment.read).length + - this.state.mentions.filter(r => !r.user_mention.read).length + + this.state.mentions.filter(r => !r.person_mention.read).length + this.state.messages.filter( r => - UserService.Instance.user && + UserService.Instance.localUserView && !r.private_message.read && - // TODO also seems very strang and wrong - r.creator.id !== UserService.Instance.user.id + // TODO also seems very strange and wrong + r.creator.id !== UserService.Instance.localUserView.person.id ).length ); } diff --git a/src/shared/components/listing-type-select.tsx b/src/shared/components/listing-type-select.tsx index c576e9b..695211e 100644 --- a/src/shared/components/listing-type-select.tsx +++ b/src/shared/components/listing-type-select.tsx @@ -42,7 +42,11 @@ export class ListingTypeSelect extends Component< diff --git a/src/shared/components/main.tsx b/src/shared/components/main.tsx index c6b2052..ba34ed4 100644 --- a/src/shared/components/main.tsx +++ b/src/shared/components/main.tsx @@ -21,7 +21,7 @@ import { GetCommentsResponse, CommentResponse, AddAdminResponse, - BanUserResponse, + BanPersonResponse, } from "lemmy-js-client"; import { DataType, InitialFetchRequest } from "../interfaces"; import { WebSocketService, UserService } from "../services"; @@ -31,7 +31,7 @@ import { SortSelect } from "./sort-select"; import { ListingTypeSelect } from "./listing-type-select"; import { DataTypeSelect } from "./data-type-select"; import { SiteForm } from "./site-form"; -import { UserListing } from "./user-listing"; +import { PersonListing } from "./person-listing"; import { CommunityLink } from "./community-link"; import { BannerIconHeader } from "./banner-icon-header"; import { Icon, Spinner } from "./icon"; @@ -130,14 +130,14 @@ export class Main extends Component { this.state.comments = this.isoData.routeData[0].comments; } this.state.trendingCommunities = this.isoData.routeData[1].communities; - if (UserService.Instance.user) { + if (UserService.Instance.localUserView) { this.state.subscribedCommunities = this.isoData.routeData[2].communities; } this.state.loading = false; } else { this.fetchTrendingCommunities(); this.fetchData(); - if (UserService.Instance.user) { + if (UserService.Instance.localUserView) { WebSocketService.Instance.send( wsClient.getFollowedCommunities({ auth: authField(), @@ -194,15 +194,17 @@ export class Main extends Component { // TODO figure out auth default_listingType, default_sort_type let type_: ListingType = pathSplit[5] ? ListingType[pathSplit[5]] - : UserService.Instance.user + : UserService.Instance.localUserView ? Object.values(ListingType)[ - UserService.Instance.user.default_listing_type + UserService.Instance.localUserView.local_user.default_listing_type ] : ListingType.Local; let sort: SortType = pathSplit[7] ? SortType[pathSplit[7]] - : UserService.Instance.user - ? Object.values(SortType)[UserService.Instance.user.default_sort_type] + : UserService.Instance.localUserView + ? Object.values(SortType)[ + UserService.Instance.localUserView.local_user.default_sort_type + ] : SortType.Active; let page = pathSplit[9] ? Number(pathSplit[9]) : 1; @@ -294,7 +296,7 @@ export class Main extends Component {
- {UserService.Instance.user && + {UserService.Instance.localUserView && this.state.subscribedCommunities.length > 0 && (
{this.subscribedCommunities()}
@@ -413,7 +415,7 @@ export class Main extends Component {
  • {i18n.t("admins")}:
  • {this.state.siteRes.admins.map(av => (
  • - +
  • ))} @@ -609,7 +611,7 @@ export class Main extends Component { )} - {UserService.Instance.user && + {UserService.Instance.localUserView && this.state.listingType == ListingType.Subscribed && ( { get canAdmin(): boolean { return ( - UserService.Instance.user && + UserService.Instance.localUserView && this.state.siteRes.admins - .map(a => a.user.id) - .includes(UserService.Instance.user.id) + .map(a => a.person.id) + .includes(UserService.Instance.localUserView.person.id) ); } @@ -755,8 +757,8 @@ export class Main extends Component { let nsfwCheck = !nsfw || (nsfw && - UserService.Instance.user && - UserService.Instance.user.show_nsfw); + UserService.Instance.localUserView && + UserService.Instance.localUserView.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) { @@ -801,23 +803,23 @@ export class Main extends Component { let data = wsJsonToRes(msg).data; this.state.siteRes.admins = data.admins; this.setState(this.state); - } else if (op == UserOperation.BanUser) { - let data = wsJsonToRes(msg).data; + } else if (op == UserOperation.BanPerson) { + let data = wsJsonToRes(msg).data; let found = this.state.siteRes.banned.find( - u => (u.user.id = data.user_view.user.id) + p => (p.person.id = data.person_view.person.id) ); // Remove the banned if its found in the list, and the action is an unban if (found && !data.banned) { this.state.siteRes.banned = this.state.siteRes.banned.filter( - i => i.user.id !== data.user_view.user.id + i => i.person.id !== data.person_view.person.id ); } else { - this.state.siteRes.banned.push(data.user_view); + this.state.siteRes.banned.push(data.person_view); } this.state.posts - .filter(p => p.creator.id == data.user_view.user.id) + .filter(p => p.creator.id == data.person_view.person.id) .forEach(p => (p.creator.banned = data.banned)); this.setState(this.state); diff --git a/src/shared/components/markdown-textarea.tsx b/src/shared/components/markdown-textarea.tsx index 1aaf4db..0acfc4c 100644 --- a/src/shared/components/markdown-textarea.tsx +++ b/src/shared/components/markdown-textarea.tsx @@ -206,7 +206,9 @@ export class MarkdownTextArea extends Component<
    @@ -332,7 +332,7 @@ export class Modlog extends Component { return [ {ma.mod_add.removed ? "Removed " : "Appointed "} , - + , as an admin , ]; @@ -353,7 +353,7 @@ export class Modlog extends Component { - + {this.renderModlogType(i)} diff --git a/src/shared/components/navbar.tsx b/src/shared/components/navbar.tsx index 9577a63..cedccb4 100644 --- a/src/shared/components/navbar.tsx +++ b/src/shared/components/navbar.tsx @@ -6,8 +6,8 @@ import { UserOperation, GetReplies, GetRepliesResponse, - GetUserMentions, - GetUserMentionsResponse, + GetPersonMentions, + GetPersonMentionsResponse, GetPrivateMessages, PrivateMessagesResponse, SortType, @@ -174,7 +174,8 @@ export class Navbar extends Component { // TODO class active corresponding to current page navbar() { - let user = UserService.Instance.user || this.props.site_res.my_user; + let localUserView = + UserService.Instance.localUserView || this.props.site_res.my_user; return (