Merge remote-tracking branch 'upstream/master' into cake-day

This commit is contained in:
Filip785 2020-07-08 17:21:44 +02:00
commit e7b7b0dee3
31 changed files with 512 additions and 161 deletions

2
ansible/VERSION vendored
View file

@ -1 +1 @@
v0.7.12 v0.7.13

View file

@ -12,7 +12,7 @@ services:
restart: always restart: always
lemmy: lemmy:
image: dessalines/lemmy:v0.7.12 image: dessalines/lemmy:v0.7.13
ports: ports:
- "127.0.0.1:8536:8536" - "127.0.0.1:8536:8536"
restart: always restart: always

View file

@ -325,7 +325,7 @@ pub fn markdown_to_html(text: &str) -> String {
pub fn get_ip(conn_info: &ConnectionInfo) -> String { pub fn get_ip(conn_info: &ConnectionInfo) -> String {
conn_info conn_info
.remote_addr() .realip_remote_addr()
.unwrap_or("127.0.0.1:12345") .unwrap_or("127.0.0.1:12345")
.split(':') .split(':')
.next() .next()

View file

@ -1 +1 @@
pub const VERSION: &str = "v0.7.12"; pub const VERSION: &str = "v0.7.13";

View file

@ -74,6 +74,7 @@ interface CommentNodeProps {
showCommunity?: boolean; showCommunity?: boolean;
sort?: CommentSortType; sort?: CommentSortType;
sortType?: SortType; sortType?: SortType;
enableDownvotes: boolean;
} }
export class CommentNode extends Component<CommentNodeProps, CommentNodeState> { export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
@ -287,7 +288,7 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
<span class="ml-1">{this.state.upvotes}</span> <span class="ml-1">{this.state.upvotes}</span>
)} )}
</button> </button>
{WebSocketService.Instance.site.enable_downvotes && ( {this.props.enableDownvotes && (
<button <button
className={`btn btn-link btn-animate ${ className={`btn btn-link btn-animate ${
this.state.my_vote == -1 this.state.my_vote == -1
@ -711,6 +712,7 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
postCreatorId={this.props.postCreatorId} postCreatorId={this.props.postCreatorId}
sort={this.props.sort} sort={this.props.sort}
sortType={this.props.sortType} sortType={this.props.sortType}
enableDownvotes={this.props.enableDownvotes}
/> />
)} )}
{/* A collapsed clearfix */} {/* A collapsed clearfix */}

View file

@ -24,6 +24,7 @@ interface CommentNodesProps {
showCommunity?: boolean; showCommunity?: boolean;
sort?: CommentSortType; sort?: CommentSortType;
sortType?: SortType; sortType?: SortType;
enableDownvotes: boolean;
} }
export class CommentNodes extends Component< export class CommentNodes extends Component<
@ -52,6 +53,7 @@ export class CommentNodes extends Component<
showCommunity={this.props.showCommunity} showCommunity={this.props.showCommunity}
sort={this.props.sort} sort={this.props.sort}
sortType={this.props.sortType} sortType={this.props.sortType}
enableDownvotes={this.props.enableDownvotes}
/> />
))} ))}
</div> </div>

View file

@ -1,5 +1,4 @@
import { Component, linkEvent } from 'inferno'; import { Component, linkEvent } from 'inferno';
import { Link } from 'inferno-router';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { retryWhen, delay, take } from 'rxjs/operators'; import { retryWhen, delay, take } from 'rxjs/operators';
import { import {
@ -11,6 +10,7 @@ import {
ListCommunitiesForm, ListCommunitiesForm,
SortType, SortType,
WebSocketJsonResponse, WebSocketJsonResponse,
GetSiteResponse,
} from '../interfaces'; } from '../interfaces';
import { WebSocketService } from '../services'; import { WebSocketService } from '../services';
import { wsJsonToRes, toast } from '../utils'; import { wsJsonToRes, toast } from '../utils';
@ -47,6 +47,7 @@ export class Communities extends Component<any, CommunitiesState> {
); );
this.refetch(); this.refetch();
WebSocketService.Instance.getSite();
} }
getPageFromProps(props: any): number { getPageFromProps(props: any): number {
@ -57,12 +58,6 @@ export class Communities extends Component<any, CommunitiesState> {
this.subscription.unsubscribe(); this.subscription.unsubscribe();
} }
componentDidMount() {
document.title = `${i18n.t('communities')} - ${
WebSocketService.Instance.site.name
}`;
}
// Necessary for back button for some reason // Necessary for back button for some reason
componentWillReceiveProps(nextProps: any) { componentWillReceiveProps(nextProps: any) {
if (nextProps.history.action == 'POP') { if (nextProps.history.action == 'POP') {
@ -244,6 +239,9 @@ export class Communities extends Component<any, CommunitiesState> {
found.subscribed = data.community.subscribed; found.subscribed = data.community.subscribed;
found.number_of_subscribers = data.community.number_of_subscribers; found.number_of_subscribers = data.community.number_of_subscribers;
this.setState(this.state); this.setState(this.state);
} else if (res.op == UserOperation.GetSite) {
let data = res.data as GetSiteResponse;
document.title = `${i18n.t('communities')} - ${data.site.name}`;
} }
} }
} }

View file

@ -8,7 +8,6 @@ import {
Category, Category,
ListCategoriesResponse, ListCategoriesResponse,
CommunityResponse, CommunityResponse,
GetSiteResponse,
WebSocketJsonResponse, WebSocketJsonResponse,
} from '../interfaces'; } from '../interfaces';
import { WebSocketService } from '../services'; import { WebSocketService } from '../services';
@ -30,13 +29,13 @@ interface CommunityFormProps {
onCancel?(): any; onCancel?(): any;
onCreate?(community: Community): any; onCreate?(community: Community): any;
onEdit?(community: Community): any; onEdit?(community: Community): any;
enableNsfw: boolean;
} }
interface CommunityFormState { interface CommunityFormState {
communityForm: CommunityFormI; communityForm: CommunityFormI;
categories: Array<Category>; categories: Array<Category>;
loading: boolean; loading: boolean;
enable_nsfw: boolean;
} }
export class CommunityForm extends Component< export class CommunityForm extends Component<
@ -56,7 +55,6 @@ export class CommunityForm extends Component<
}, },
categories: [], categories: [],
loading: false, loading: false,
enable_nsfw: null,
}; };
constructor(props: any, context: any) { constructor(props: any, context: any) {
@ -86,7 +84,6 @@ export class CommunityForm extends Component<
); );
WebSocketService.Instance.listCategories(); WebSocketService.Instance.listCategories();
WebSocketService.Instance.getSite();
} }
componentDidMount() { componentDidMount() {
@ -187,7 +184,7 @@ export class CommunityForm extends Component<
</div> </div>
</div> </div>
{this.state.enable_nsfw && ( {this.props.enableNsfw && (
<div class="form-group row"> <div class="form-group row">
<div class="col-12"> <div class="col-12">
<div class="form-check"> <div class="form-check">
@ -303,10 +300,6 @@ export class CommunityForm extends Component<
let data = res.data as CommunityResponse; let data = res.data as CommunityResponse;
this.state.loading = false; this.state.loading = false;
this.props.onEdit(data.community); this.props.onEdit(data.community);
} else if (res.op == UserOperation.GetSite) {
let data = res.data as GetSiteResponse;
this.state.enable_nsfw = data.site.enable_nsfw;
this.setState(this.state);
} }
} }
} }

View file

@ -23,6 +23,8 @@ import {
GetCommentsResponse, GetCommentsResponse,
CommentResponse, CommentResponse,
WebSocketJsonResponse, WebSocketJsonResponse,
GetSiteResponse,
Site,
} from '../interfaces'; } from '../interfaces';
import { WebSocketService } from '../services'; import { WebSocketService } from '../services';
import { PostListings } from './post-listings'; import { PostListings } from './post-listings';
@ -60,6 +62,7 @@ interface State {
dataType: DataType; dataType: DataType;
sort: SortType; sort: SortType;
page: number; page: number;
site: Site;
} }
export class Community extends Component<any, State> { export class Community extends Component<any, State> {
@ -97,6 +100,20 @@ export class Community extends Component<any, State> {
dataType: getDataTypeFromProps(this.props), dataType: getDataTypeFromProps(this.props),
sort: getSortTypeFromProps(this.props), sort: getSortTypeFromProps(this.props),
page: getPageFromProps(this.props), page: getPageFromProps(this.props),
site: {
id: undefined,
name: undefined,
creator_id: undefined,
published: undefined,
creator_name: undefined,
number_of_users: undefined,
number_of_posts: undefined,
number_of_comments: undefined,
number_of_communities: undefined,
enable_downvotes: undefined,
open_registration: undefined,
enable_nsfw: undefined,
},
}; };
constructor(props: any, context: any) { constructor(props: any, context: any) {
@ -119,6 +136,7 @@ export class Community extends Component<any, State> {
name: this.state.communityName ? this.state.communityName : null, name: this.state.communityName ? this.state.communityName : null,
}; };
WebSocketService.Instance.getCommunity(form); WebSocketService.Instance.getCommunity(form);
WebSocketService.Instance.getSite();
} }
componentWillUnmount() { componentWillUnmount() {
@ -174,6 +192,7 @@ export class Community extends Component<any, State> {
moderators={this.state.moderators} moderators={this.state.moderators}
admins={this.state.admins} admins={this.state.admins}
online={this.state.online} online={this.state.online}
enableNsfw={this.state.site.enable_nsfw}
/> />
</div> </div>
</div> </div>
@ -188,6 +207,8 @@ export class Community extends Component<any, State> {
posts={this.state.posts} posts={this.state.posts}
removeDuplicates removeDuplicates
sort={this.state.sort} sort={this.state.sort}
enableDownvotes={this.state.site.enable_downvotes}
enableNsfw={this.state.site.enable_nsfw}
/> />
) : ( ) : (
<CommentNodes <CommentNodes
@ -195,6 +216,7 @@ export class Community extends Component<any, State> {
noIndent noIndent
sortType={this.state.sort} sortType={this.state.sort}
showContext showContext
enableDownvotes={this.state.site.enable_downvotes}
/> />
); );
} }
@ -331,7 +353,7 @@ export class Community extends Component<any, State> {
this.state.moderators = data.moderators; this.state.moderators = data.moderators;
this.state.admins = data.admins; this.state.admins = data.admins;
this.state.online = data.online; this.state.online = data.online;
document.title = `/c/${this.state.community.name} - ${WebSocketService.Instance.site.name}`; document.title = `/c/${this.state.community.name} - ${this.state.site.name}`;
this.setState(this.state); this.setState(this.state);
this.fetchData(); this.fetchData();
} else if (res.op == UserOperation.EditCommunity) { } else if (res.op == UserOperation.EditCommunity) {
@ -399,6 +421,10 @@ export class Community extends Component<any, State> {
let data = res.data as CommentResponse; let data = res.data as CommentResponse;
createCommentLikeRes(data, this.state.comments); createCommentLikeRes(data, this.state.comments);
this.setState(this.state); this.setState(this.state);
} else if (res.op == UserOperation.GetSite) {
let data = res.data as GetSiteResponse;
this.state.site = data.site;
this.setState(this.state);
} }
} }
} }

View file

@ -1,19 +1,44 @@
import { Component } from 'inferno'; import { Component } from 'inferno';
import { Subscription } from 'rxjs';
import { retryWhen, delay, take } from 'rxjs/operators';
import { CommunityForm } from './community-form'; import { CommunityForm } from './community-form';
import { Community } from '../interfaces'; import {
Community,
UserOperation,
WebSocketJsonResponse,
GetSiteResponse,
} from '../interfaces';
import { toast, wsJsonToRes } from '../utils';
import { WebSocketService } from '../services'; import { WebSocketService } from '../services';
import { i18n } from '../i18next'; import { i18n } from '../i18next';
export class CreateCommunity extends Component<any, any> { interface CreateCommunityState {
enableNsfw: boolean;
}
export class CreateCommunity extends Component<any, CreateCommunityState> {
private subscription: Subscription;
private emptyState: CreateCommunityState = {
enableNsfw: null,
};
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
this.handleCommunityCreate = this.handleCommunityCreate.bind(this); this.handleCommunityCreate = this.handleCommunityCreate.bind(this);
this.state = this.emptyState;
this.subscription = WebSocketService.Instance.subject
.pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
.subscribe(
msg => this.parseMessage(msg),
err => console.error(err),
() => console.log('complete')
);
WebSocketService.Instance.getSite();
} }
componentDidMount() { componentWillUnmount() {
document.title = `${i18n.t('create_community')} - ${ this.subscription.unsubscribe();
WebSocketService.Instance.site.name
}`;
} }
render() { render() {
@ -22,7 +47,10 @@ export class CreateCommunity extends Component<any, any> {
<div class="row"> <div class="row">
<div class="col-12 col-lg-6 offset-lg-3 mb-4"> <div class="col-12 col-lg-6 offset-lg-3 mb-4">
<h5>{i18n.t('create_community')}</h5> <h5>{i18n.t('create_community')}</h5>
<CommunityForm onCreate={this.handleCommunityCreate} /> <CommunityForm
onCreate={this.handleCommunityCreate}
enableNsfw={this.state.enableNsfw}
/>
</div> </div>
</div> </div>
</div> </div>
@ -32,4 +60,18 @@ export class CreateCommunity extends Component<any, any> {
handleCommunityCreate(community: Community) { handleCommunityCreate(community: Community) {
this.props.history.push(`/c/${community.name}`); this.props.history.push(`/c/${community.name}`);
} }
parseMessage(msg: WebSocketJsonResponse) {
console.log(msg);
let res = wsJsonToRes(msg);
if (msg.error) {
toast(i18n.t(msg.error), 'danger');
return;
} else if (res.op == UserOperation.GetSite) {
let data = res.data as GetSiteResponse;
this.state.enableNsfw = data.site.enable_nsfw;
this.setState(this.state);
document.title = `${i18n.t('create_community')} - ${data.site.name}`;
}
}
} }

View file

@ -1,19 +1,59 @@
import { Component } from 'inferno'; import { Component } from 'inferno';
import { Subscription } from 'rxjs';
import { retryWhen, delay, take } from 'rxjs/operators';
import { PostForm } from './post-form'; import { PostForm } from './post-form';
import { toast, wsJsonToRes } from '../utils';
import { WebSocketService } from '../services'; import { WebSocketService } from '../services';
import { PostFormParams } from '../interfaces'; import {
UserOperation,
PostFormParams,
WebSocketJsonResponse,
GetSiteResponse,
Site,
} from '../interfaces';
import { i18n } from '../i18next'; import { i18n } from '../i18next';
export class CreatePost extends Component<any, any> { interface CreatePostState {
site: Site;
}
export class CreatePost extends Component<any, CreatePostState> {
private subscription: Subscription;
private emptyState: CreatePostState = {
site: {
id: undefined,
name: undefined,
creator_id: undefined,
published: undefined,
creator_name: undefined,
number_of_users: undefined,
number_of_posts: undefined,
number_of_comments: undefined,
number_of_communities: undefined,
enable_downvotes: undefined,
open_registration: undefined,
enable_nsfw: undefined,
},
};
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
this.handlePostCreate = this.handlePostCreate.bind(this); this.handlePostCreate = this.handlePostCreate.bind(this);
this.state = this.emptyState;
this.subscription = WebSocketService.Instance.subject
.pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
.subscribe(
msg => this.parseMessage(msg),
err => console.error(err),
() => console.log('complete')
);
WebSocketService.Instance.getSite();
} }
componentDidMount() { componentWillUnmount() {
document.title = `${i18n.t('create_post')} - ${ this.subscription.unsubscribe();
WebSocketService.Instance.site.name
}`;
} }
render() { render() {
@ -22,7 +62,12 @@ export class CreatePost extends Component<any, any> {
<div class="row"> <div class="row">
<div class="col-12 col-lg-6 offset-lg-3 mb-4"> <div class="col-12 col-lg-6 offset-lg-3 mb-4">
<h5>{i18n.t('create_post')}</h5> <h5>{i18n.t('create_post')}</h5>
<PostForm onCreate={this.handlePostCreate} params={this.params} /> <PostForm
onCreate={this.handlePostCreate}
params={this.params}
enableDownvotes={this.state.site.enable_downvotes}
enableNsfw={this.state.site.enable_nsfw}
/>
</div> </div>
</div> </div>
</div> </div>
@ -56,4 +101,18 @@ export class CreatePost extends Component<any, any> {
handlePostCreate(id: number) { handlePostCreate(id: number) {
this.props.history.push(`/post/${id}`); this.props.history.push(`/post/${id}`);
} }
parseMessage(msg: WebSocketJsonResponse) {
console.log(msg);
let res = wsJsonToRes(msg);
if (msg.error) {
toast(i18n.t(msg.error), 'danger');
return;
} else if (res.op == UserOperation.GetSite) {
let data = res.data as GetSiteResponse;
this.state.site = data.site;
this.setState(this.state);
document.title = `${i18n.t('create_post')} - ${data.site.name}`;
}
}
} }

View file

@ -1,22 +1,38 @@
import { Component } from 'inferno'; import { Component } from 'inferno';
import { Subscription } from 'rxjs';
import { retryWhen, delay, take } from 'rxjs/operators';
import { PrivateMessageForm } from './private-message-form'; import { PrivateMessageForm } from './private-message-form';
import { WebSocketService } from '../services'; import { WebSocketService } from '../services';
import { PrivateMessageFormParams } from '../interfaces'; import {
import { toast } from '../utils'; UserOperation,
WebSocketJsonResponse,
GetSiteResponse,
PrivateMessageFormParams,
} from '../interfaces';
import { toast, wsJsonToRes } from '../utils';
import { i18n } from '../i18next'; import { i18n } from '../i18next';
export class CreatePrivateMessage extends Component<any, any> { export class CreatePrivateMessage extends Component<any, any> {
private subscription: Subscription;
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
this.handlePrivateMessageCreate = this.handlePrivateMessageCreate.bind( this.handlePrivateMessageCreate = this.handlePrivateMessageCreate.bind(
this this
); );
this.subscription = WebSocketService.Instance.subject
.pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
.subscribe(
msg => this.parseMessage(msg),
err => console.error(err),
() => console.log('complete')
);
WebSocketService.Instance.getSite();
} }
componentDidMount() { componentWillUnmount() {
document.title = `${i18n.t('create_private_message')} - ${ this.subscription.unsubscribe();
WebSocketService.Instance.site.name
}`;
} }
render() { render() {
@ -50,4 +66,18 @@ export class CreatePrivateMessage extends Component<any, any> {
// Navigate to the front // Navigate to the front
this.props.history.push(`/`); this.props.history.push(`/`);
} }
parseMessage(msg: WebSocketJsonResponse) {
console.log(msg);
let res = wsJsonToRes(msg);
if (msg.error) {
toast(i18n.t(msg.error), 'danger');
return;
} else if (res.op == UserOperation.GetSite) {
let data = res.data as GetSiteResponse;
document.title = `${i18n.t('create_private_message')} - ${
data.site.name
}`;
}
}
} }

View file

@ -16,6 +16,7 @@ import {
GetPrivateMessagesForm, GetPrivateMessagesForm,
PrivateMessagesResponse, PrivateMessagesResponse,
PrivateMessageResponse, PrivateMessageResponse,
GetSiteResponse,
} from '../interfaces'; } from '../interfaces';
import { WebSocketService, UserService } from '../services'; import { WebSocketService, UserService } from '../services';
import { import {
@ -56,6 +57,7 @@ interface InboxState {
messages: Array<PrivateMessageI>; messages: Array<PrivateMessageI>;
sort: SortType; sort: SortType;
page: number; page: number;
enableDownvotes: boolean;
} }
export class Inbox extends Component<any, InboxState> { export class Inbox extends Component<any, InboxState> {
@ -68,6 +70,7 @@ export class Inbox extends Component<any, InboxState> {
messages: [], messages: [],
sort: SortType.New, sort: SortType.New,
page: 1, page: 1,
enableDownvotes: undefined,
}; };
constructor(props: any, context: any) { constructor(props: any, context: any) {
@ -85,18 +88,13 @@ export class Inbox extends Component<any, InboxState> {
); );
this.refetch(); this.refetch();
WebSocketService.Instance.getSite();
} }
componentWillUnmount() { componentWillUnmount() {
this.subscription.unsubscribe(); this.subscription.unsubscribe();
} }
componentDidMount() {
document.title = `/u/${UserService.Instance.user.username} ${i18n.t(
'inbox'
)} - ${WebSocketService.Instance.site.name}`;
}
render() { render() {
return ( return (
<div class="container"> <div class="container">
@ -270,6 +268,7 @@ export class Inbox extends Component<any, InboxState> {
noIndent noIndent
markable markable
showContext showContext
enableDownvotes={this.state.enableDownvotes}
/> />
) : ( ) : (
<PrivateMessage privateMessage={i} /> <PrivateMessage privateMessage={i} />
@ -287,6 +286,7 @@ export class Inbox extends Component<any, InboxState> {
noIndent noIndent
markable markable
showContext showContext
enableDownvotes={this.state.enableDownvotes}
/> />
</div> </div>
); );
@ -301,6 +301,7 @@ export class Inbox extends Component<any, InboxState> {
noIndent noIndent
markable markable
showContext showContext
enableDownvotes={this.state.enableDownvotes}
/> />
))} ))}
</div> </div>
@ -522,6 +523,13 @@ export class Inbox extends Component<any, InboxState> {
let data = res.data as CommentResponse; let data = res.data as CommentResponse;
createCommentLikeRes(data, this.state.replies); createCommentLikeRes(data, this.state.replies);
this.setState(this.state); this.setState(this.state);
} else if (res.op == UserOperation.GetSite) {
let data = res.data as GetSiteResponse;
this.state.enableDownvotes = data.site.enable_downvotes;
this.setState(this.state);
document.title = `/u/${UserService.Instance.user.username} ${i18n.t(
'inbox'
)} - ${data.site.name}`;
} }
} }

View file

@ -385,9 +385,7 @@ export class Login extends Component<any, State> {
let data = res.data as GetSiteResponse; let data = res.data as GetSiteResponse;
this.state.enable_nsfw = data.site.enable_nsfw; this.state.enable_nsfw = data.site.enable_nsfw;
this.setState(this.state); this.setState(this.state);
document.title = `${i18n.t('login')} - ${ document.title = `${i18n.t('login')} - ${data.site.name}`;
WebSocketService.Instance.site.name
}`;
} }
} }
} }

View file

@ -418,6 +418,8 @@ export class Main extends Component<any, MainState> {
showCommunity showCommunity
removeDuplicates removeDuplicates
sort={this.state.sort} sort={this.state.sort}
enableDownvotes={this.state.siteRes.site.enable_downvotes}
enableNsfw={this.state.siteRes.site.enable_nsfw}
/> />
) : ( ) : (
<CommentNodes <CommentNodes
@ -426,6 +428,7 @@ export class Main extends Component<any, MainState> {
showCommunity showCommunity
sortType={this.state.sort} sortType={this.state.sort}
showContext showContext
enableDownvotes={this.state.siteRes.site.enable_downvotes}
/> />
); );
} }
@ -617,7 +620,7 @@ export class Main extends Component<any, MainState> {
this.state.siteRes.banned = data.banned; this.state.siteRes.banned = data.banned;
this.state.siteRes.online = data.online; this.state.siteRes.online = data.online;
this.setState(this.state); this.setState(this.state);
document.title = `${WebSocketService.Instance.site.name}`; document.title = `${this.state.siteRes.site.name}`;
} else if (res.op == UserOperation.EditSite) { } else if (res.op == UserOperation.EditSite) {
let data = res.data as SiteResponse; let data = res.data as SiteResponse;
this.state.siteRes.site = data.site; this.state.siteRes.site = data.site;

View file

@ -16,6 +16,7 @@ import {
ModAddCommunity, ModAddCommunity,
ModAdd, ModAdd,
WebSocketJsonResponse, WebSocketJsonResponse,
GetSiteResponse,
} from '../interfaces'; } from '../interfaces';
import { WebSocketService } from '../services'; import { WebSocketService } from '../services';
import { wsJsonToRes, addTypeInfo, fetchLimit, toast } from '../utils'; import { wsJsonToRes, addTypeInfo, fetchLimit, toast } from '../utils';
@ -64,16 +65,13 @@ export class Modlog extends Component<any, ModlogState> {
); );
this.refetch(); this.refetch();
WebSocketService.Instance.getSite();
} }
componentWillUnmount() { componentWillUnmount() {
this.subscription.unsubscribe(); this.subscription.unsubscribe();
} }
componentDidMount() {
document.title = `Modlog - ${WebSocketService.Instance.site.name}`;
}
setCombined(res: GetModlogResponse) { setCombined(res: GetModlogResponse) {
let removed_posts = addTypeInfo(res.removed_posts, 'removed_posts'); let removed_posts = addTypeInfo(res.removed_posts, 'removed_posts');
let locked_posts = addTypeInfo(res.locked_posts, 'locked_posts'); let locked_posts = addTypeInfo(res.locked_posts, 'locked_posts');
@ -434,6 +432,9 @@ export class Modlog extends Component<any, ModlogState> {
this.state.loading = false; this.state.loading = false;
window.scrollTo(0, 0); window.scrollTo(0, 0);
this.setCombined(data); this.setCombined(data);
} else if (res.op == UserOperation.GetSite) {
let data = res.data as GetSiteResponse;
document.title = `Modlog - ${data.site.name}`;
} }
} }
} }

View file

@ -396,9 +396,6 @@ export class Navbar extends Component<any, NavbarState> {
if (data.site && !this.state.siteName) { if (data.site && !this.state.siteName) {
this.state.siteName = data.site.name; this.state.siteName = data.site.name;
this.state.admins = data.admins; this.state.admins = data.admins;
WebSocketService.Instance.site = data.site;
WebSocketService.Instance.admins = data.admins;
this.setState(this.state); this.setState(this.state);
} }
} }

View file

@ -6,6 +6,7 @@ import {
LoginResponse, LoginResponse,
PasswordChangeForm, PasswordChangeForm,
WebSocketJsonResponse, WebSocketJsonResponse,
GetSiteResponse,
} from '../interfaces'; } from '../interfaces';
import { WebSocketService, UserService } from '../services'; import { WebSocketService, UserService } from '../services';
import { wsJsonToRes, capitalizeFirstLetter, toast } from '../utils'; import { wsJsonToRes, capitalizeFirstLetter, toast } from '../utils';
@ -40,18 +41,13 @@ export class PasswordChange extends Component<any, State> {
err => console.error(err), err => console.error(err),
() => console.log('complete') () => console.log('complete')
); );
WebSocketService.Instance.getSite();
} }
componentWillUnmount() { componentWillUnmount() {
this.subscription.unsubscribe(); this.subscription.unsubscribe();
} }
componentDidMount() {
document.title = `${i18n.t('password_change')} - ${
WebSocketService.Instance.site.name
}`;
}
render() { render() {
return ( return (
<div class="container"> <div class="container">
@ -138,14 +134,15 @@ export class PasswordChange extends Component<any, State> {
this.state.loading = false; this.state.loading = false;
this.setState(this.state); this.setState(this.state);
return; return;
} else { } else if (res.op == UserOperation.PasswordChange) {
if (res.op == UserOperation.PasswordChange) { let data = res.data as LoginResponse;
let data = res.data as LoginResponse; this.state = this.emptyState;
this.state = this.emptyState; this.setState(this.state);
this.setState(this.state); UserService.Instance.login(data);
UserService.Instance.login(data); this.props.history.push('/');
this.props.history.push('/'); } else if (res.op == UserOperation.GetSite) {
} let data = res.data as GetSiteResponse;
document.title = `${i18n.t('password_change')} - ${data.site.name}`;
} }
} }
} }

View file

@ -16,7 +16,6 @@ import {
SearchForm, SearchForm,
SearchType, SearchType,
SearchResponse, SearchResponse,
GetSiteResponse,
WebSocketJsonResponse, WebSocketJsonResponse,
} from '../interfaces'; } from '../interfaces';
import { WebSocketService, UserService } from '../services'; import { WebSocketService, UserService } from '../services';
@ -52,6 +51,8 @@ interface PostFormProps {
onCancel?(): any; onCancel?(): any;
onCreate?(id: number): any; onCreate?(id: number): any;
onEdit?(post: Post): any; onEdit?(post: Post): any;
enableNsfw: boolean;
enableDownvotes: boolean;
} }
interface PostFormState { interface PostFormState {
@ -63,7 +64,6 @@ interface PostFormState {
suggestedTitle: string; suggestedTitle: string;
suggestedPosts: Array<Post>; suggestedPosts: Array<Post>;
crossPosts: Array<Post>; crossPosts: Array<Post>;
enable_nsfw: boolean;
} }
export class PostForm extends Component<PostFormProps, PostFormState> { export class PostForm extends Component<PostFormProps, PostFormState> {
@ -87,7 +87,6 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
suggestedTitle: undefined, suggestedTitle: undefined,
suggestedPosts: [], suggestedPosts: [],
crossPosts: [], crossPosts: [],
enable_nsfw: undefined,
}; };
constructor(props: any, context: any) { constructor(props: any, context: any) {
@ -138,7 +137,6 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
}; };
WebSocketService.Instance.listCommunities(listCommunitiesForm); WebSocketService.Instance.listCommunities(listCommunitiesForm);
WebSocketService.Instance.getSite();
} }
componentDidMount() { componentDidMount() {
@ -240,7 +238,12 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
<div class="my-1 text-muted small font-weight-bold"> <div class="my-1 text-muted small font-weight-bold">
{i18n.t('cross_posts')} {i18n.t('cross_posts')}
</div> </div>
<PostListings showCommunity posts={this.state.crossPosts} /> <PostListings
showCommunity
posts={this.state.crossPosts}
enableDownvotes={this.props.enableDownvotes}
enableNsfw={this.props.enableNsfw}
/>
</> </>
)} )}
</div> </div>
@ -265,7 +268,11 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
<div class="my-1 text-muted small font-weight-bold"> <div class="my-1 text-muted small font-weight-bold">
{i18n.t('related_posts')} {i18n.t('related_posts')}
</div> </div>
<PostListings posts={this.state.suggestedPosts} /> <PostListings
posts={this.state.suggestedPosts}
enableDownvotes={this.props.enableDownvotes}
enableNsfw={this.props.enableNsfw}
/>
</> </>
)} )}
</div> </div>
@ -346,7 +353,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
</div> </div>
</div> </div>
)} )}
{this.state.enable_nsfw && ( {this.props.enableNsfw && (
<div class="form-group row"> <div class="form-group row">
<div class="col-sm-10"> <div class="col-sm-10">
<div class="form-check"> <div class="form-check">
@ -631,10 +638,6 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
this.state.crossPosts = data.posts; this.state.crossPosts = data.posts;
} }
this.setState(this.state); this.setState(this.state);
} else if (res.op == UserOperation.GetSite) {
let data = res.data as GetSiteResponse;
this.state.enable_nsfw = data.site.enable_nsfw;
this.setState(this.state);
} }
} }
} }

View file

@ -62,6 +62,8 @@ interface PostListingProps {
showBody?: boolean; showBody?: boolean;
moderators?: Array<CommunityUser>; moderators?: Array<CommunityUser>;
admins?: Array<UserView>; admins?: Array<UserView>;
enableDownvotes: boolean;
enableNsfw: boolean;
} }
export class PostListing extends Component<PostListingProps, PostListingState> { export class PostListing extends Component<PostListingProps, PostListingState> {
@ -116,6 +118,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
post={this.props.post} post={this.props.post}
onEdit={this.handleEditPost} onEdit={this.handleEditPost}
onCancel={this.handleEditCancel} onCancel={this.handleEditCancel}
enableNsfw={this.props.enableNsfw}
enableDownvotes={this.props.enableDownvotes}
/> />
</div> </div>
)} )}
@ -276,7 +280,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
> >
{this.state.score} {this.state.score}
</div> </div>
{WebSocketService.Instance.site.enable_downvotes && ( {this.props.enableDownvotes && (
<button <button
className={`btn-animate btn btn-link p-0 ${ className={`btn-animate btn btn-link p-0 ${
this.state.my_vote == -1 ? 'text-danger' : 'text-muted' this.state.my_vote == -1 ? 'text-danger' : 'text-muted'

View file

@ -11,6 +11,8 @@ interface PostListingsProps {
showCommunity?: boolean; showCommunity?: boolean;
removeDuplicates?: boolean; removeDuplicates?: boolean;
sort?: SortType; sort?: SortType;
enableDownvotes: boolean;
enableNsfw: boolean;
} }
export class PostListings extends Component<PostListingsProps, any> { export class PostListings extends Component<PostListingsProps, any> {
@ -27,6 +29,8 @@ export class PostListings extends Component<PostListingsProps, any> {
<PostListing <PostListing
post={post} post={post}
showCommunity={this.props.showCommunity} showCommunity={this.props.showCommunity}
enableDownvotes={this.props.enableDownvotes}
enableNsfw={this.props.enableNsfw}
/> />
<hr class="my-2" /> <hr class="my-2" />
</> </>

View file

@ -18,7 +18,6 @@ import {
BanUserResponse, BanUserResponse,
AddModToCommunityResponse, AddModToCommunityResponse,
AddAdminResponse, AddAdminResponse,
UserView,
SearchType, SearchType,
SortType, SortType,
SearchForm, SearchForm,
@ -52,12 +51,12 @@ interface PostState {
commentSort: CommentSortType; commentSort: CommentSortType;
community: Community; community: Community;
moderators: Array<CommunityUser>; moderators: Array<CommunityUser>;
admins: Array<UserView>;
online: number; online: number;
scrolled?: boolean; scrolled?: boolean;
scrolled_comment_id?: number; scrolled_comment_id?: number;
loading: boolean; loading: boolean;
crossPosts: Array<PostI>; crossPosts: Array<PostI>;
siteRes: GetSiteResponse;
} }
export class Post extends Component<any, PostState> { export class Post extends Component<any, PostState> {
@ -68,11 +67,29 @@ export class Post extends Component<any, PostState> {
commentSort: CommentSortType.Hot, commentSort: CommentSortType.Hot,
community: null, community: null,
moderators: [], moderators: [],
admins: [],
online: null, online: null,
scrolled: false, scrolled: false,
loading: true, loading: true,
crossPosts: [], crossPosts: [],
siteRes: {
admins: [],
banned: [],
site: {
id: undefined,
name: undefined,
creator_id: undefined,
published: undefined,
creator_name: undefined,
number_of_users: undefined,
number_of_posts: undefined,
number_of_comments: undefined,
number_of_communities: undefined,
enable_downvotes: undefined,
open_registration: undefined,
enable_nsfw: undefined,
},
online: null,
},
}; };
constructor(props: any, context: any) { constructor(props: any, context: any) {
@ -97,6 +114,7 @@ export class Post extends Component<any, PostState> {
id: postId, id: postId,
}; };
WebSocketService.Instance.getPost(form); WebSocketService.Instance.getPost(form);
WebSocketService.Instance.getSite();
} }
componentWillUnmount() { componentWillUnmount() {
@ -180,7 +198,9 @@ export class Post extends Component<any, PostState> {
showBody showBody
showCommunity showCommunity
moderators={this.state.moderators} moderators={this.state.moderators}
admins={this.state.admins} admins={this.state.siteRes.admins}
enableDownvotes={this.state.siteRes.site.enable_downvotes}
enableNsfw={this.state.siteRes.site.enable_nsfw}
/> />
<div className="mb-2" /> <div className="mb-2" />
<CommentForm <CommentForm
@ -269,9 +289,10 @@ export class Post extends Component<any, PostState> {
noIndent noIndent
locked={this.state.post.locked} locked={this.state.post.locked}
moderators={this.state.moderators} moderators={this.state.moderators}
admins={this.state.admins} admins={this.state.siteRes.admins}
postCreatorId={this.state.post.creator_id} postCreatorId={this.state.post.creator_id}
showContext showContext
enableDownvotes={this.state.siteRes.site.enable_downvotes}
/> />
</div> </div>
</div> </div>
@ -284,8 +305,9 @@ export class Post extends Component<any, PostState> {
<Sidebar <Sidebar
community={this.state.community} community={this.state.community}
moderators={this.state.moderators} moderators={this.state.moderators}
admins={this.state.admins} admins={this.state.siteRes.admins}
online={this.state.online} online={this.state.online}
enableNsfw={this.state.siteRes.site.enable_nsfw}
/> />
</div> </div>
); );
@ -336,9 +358,10 @@ export class Post extends Component<any, PostState> {
nodes={nodes} nodes={nodes}
locked={this.state.post.locked} locked={this.state.post.locked}
moderators={this.state.moderators} moderators={this.state.moderators}
admins={this.state.admins} admins={this.state.siteRes.admins}
postCreatorId={this.state.post.creator_id} postCreatorId={this.state.post.creator_id}
sort={this.state.commentSort} sort={this.state.commentSort}
enableDownvotes={this.state.siteRes.site.enable_downvotes}
/> />
</div> </div>
); );
@ -360,10 +383,10 @@ export class Post extends Component<any, PostState> {
this.state.comments = data.comments; this.state.comments = data.comments;
this.state.community = data.community; this.state.community = data.community;
this.state.moderators = data.moderators; this.state.moderators = data.moderators;
this.state.admins = data.admins; this.state.siteRes.admins = data.admins;
this.state.online = data.online; this.state.online = data.online;
this.state.loading = false; this.state.loading = false;
document.title = `${this.state.post.name} - ${WebSocketService.Instance.site.name}`; document.title = `${this.state.post.name} - ${this.state.siteRes.site.name}`;
// Get cross-posts // Get cross-posts
if (this.state.post.url) { if (this.state.post.url) {
@ -450,7 +473,7 @@ export class Post extends Component<any, PostState> {
this.setState(this.state); this.setState(this.state);
} else if (res.op == UserOperation.AddAdmin) { } else if (res.op == UserOperation.AddAdmin) {
let data = res.data as AddAdminResponse; let data = res.data as AddAdminResponse;
this.state.admins = data.admins; this.state.siteRes.admins = data.admins;
this.setState(this.state); this.setState(this.state);
} else if (res.op == UserOperation.Search) { } else if (res.op == UserOperation.Search) {
let data = res.data as SearchResponse; let data = res.data as SearchResponse;
@ -461,15 +484,18 @@ export class Post extends Component<any, PostState> {
this.state.post.duplicates = this.state.crossPosts; this.state.post.duplicates = this.state.crossPosts;
} }
this.setState(this.state); this.setState(this.state);
} else if (res.op == UserOperation.TransferSite) { } else if (
res.op == UserOperation.TransferSite ||
res.op == UserOperation.GetSite
) {
let data = res.data as GetSiteResponse; let data = res.data as GetSiteResponse;
this.state.admins = data.admins; this.state.siteRes = data;
this.setState(this.state); this.setState(this.state);
} else if (res.op == UserOperation.TransferCommunity) { } else if (res.op == UserOperation.TransferCommunity) {
let data = res.data as GetCommunityResponse; let data = res.data as GetCommunityResponse;
this.state.community = data.community; this.state.community = data.community;
this.state.moderators = data.moderators; this.state.moderators = data.moderators;
this.state.admins = data.admins; this.state.siteRes.admins = data.admins;
this.setState(this.state); this.setState(this.state);
} }
} }

View file

@ -1,6 +1,5 @@
import { Component, linkEvent } from 'inferno'; import { Component, linkEvent } from 'inferno';
import { Prompt } from 'inferno-router'; import { Prompt } from 'inferno-router';
import { Link } from 'inferno-router';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { retryWhen, delay, take } from 'rxjs/operators'; import { retryWhen, delay, take } from 'rxjs/operators';
import { import {

View file

@ -15,6 +15,8 @@ import {
PostResponse, PostResponse,
CommentResponse, CommentResponse,
WebSocketJsonResponse, WebSocketJsonResponse,
GetSiteResponse,
Site,
} from '../interfaces'; } from '../interfaces';
import { WebSocketService } from '../services'; import { WebSocketService } from '../services';
import { import {
@ -41,6 +43,7 @@ interface SearchState {
page: number; page: number;
searchResponse: SearchResponse; searchResponse: SearchResponse;
loading: boolean; loading: boolean;
site: Site;
} }
export class Search extends Component<any, SearchState> { export class Search extends Component<any, SearchState> {
@ -58,6 +61,20 @@ export class Search extends Component<any, SearchState> {
users: [], users: [],
}, },
loading: false, loading: false,
site: {
id: undefined,
name: undefined,
creator_id: undefined,
published: undefined,
creator_name: undefined,
number_of_users: undefined,
number_of_posts: undefined,
number_of_comments: undefined,
number_of_communities: undefined,
enable_downvotes: undefined,
open_registration: undefined,
enable_nsfw: undefined,
},
}; };
getSearchQueryFromProps(props: any): string { getSearchQueryFromProps(props: any): string {
@ -94,6 +111,8 @@ export class Search extends Component<any, SearchState> {
() => console.log('complete') () => console.log('complete')
); );
WebSocketService.Instance.getSite();
if (this.state.q) { if (this.state.q) {
this.search(); this.search();
} }
@ -118,12 +137,6 @@ export class Search extends Component<any, SearchState> {
} }
} }
componentDidMount() {
document.title = `${i18n.t('search')} - ${
WebSocketService.Instance.site.name
}`;
}
render() { render() {
return ( return (
<div class="container"> <div class="container">
@ -241,13 +254,19 @@ export class Search extends Component<any, SearchState> {
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
{i.type_ == 'posts' && ( {i.type_ == 'posts' && (
<PostListing post={i.data as Post} showCommunity /> <PostListing
post={i.data as Post}
showCommunity
enableDownvotes={this.state.site.enable_downvotes}
enableNsfw={this.state.site.enable_nsfw}
/>
)} )}
{i.type_ == 'comments' && ( {i.type_ == 'comments' && (
<CommentNodes <CommentNodes
nodes={[{ comment: i.data as Comment }]} nodes={[{ comment: i.data as Comment }]}
locked locked
noIndent noIndent
enableDownvotes={this.state.site.enable_downvotes}
/> />
)} )}
{i.type_ == 'communities' && ( {i.type_ == 'communities' && (
@ -281,6 +300,7 @@ export class Search extends Component<any, SearchState> {
nodes={commentsToFlatNodes(this.state.searchResponse.comments)} nodes={commentsToFlatNodes(this.state.searchResponse.comments)}
locked locked
noIndent noIndent
enableDownvotes={this.state.site.enable_downvotes}
/> />
); );
} }
@ -291,7 +311,12 @@ export class Search extends Component<any, SearchState> {
{this.state.searchResponse.posts.map(post => ( {this.state.searchResponse.posts.map(post => (
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<PostListing post={post} showCommunity /> <PostListing
post={post}
showCommunity
enableDownvotes={this.state.site.enable_downvotes}
enableNsfw={this.state.site.enable_nsfw}
/>
</div> </div>
</div> </div>
))} ))}
@ -455,7 +480,7 @@ export class Search extends Component<any, SearchState> {
this.state.searchResponse = data; this.state.searchResponse = data;
this.state.loading = false; this.state.loading = false;
document.title = `${i18n.t('search')} - ${this.state.q} - ${ document.title = `${i18n.t('search')} - ${this.state.q} - ${
WebSocketService.Instance.site.name this.state.site.name
}`; }`;
window.scrollTo(0, 0); window.scrollTo(0, 0);
this.setState(this.state); this.setState(this.state);
@ -467,6 +492,11 @@ export class Search extends Component<any, SearchState> {
let data = res.data as PostResponse; let data = res.data as PostResponse;
createPostLikeFindRes(data, this.state.searchResponse.posts); createPostLikeFindRes(data, this.state.searchResponse.posts);
this.setState(this.state); this.setState(this.state);
} else if (res.op == UserOperation.GetSite) {
let data = res.data as GetSiteResponse;
this.state.site = data.site;
this.setState(this.state);
document.title = `${i18n.t('search')} - ${data.site.name}`;
} }
} }
} }

View file

@ -19,6 +19,7 @@ interface SidebarProps {
moderators: Array<CommunityUser>; moderators: Array<CommunityUser>;
admins: Array<UserView>; admins: Array<UserView>;
online: number; online: number;
enableNsfw: boolean;
} }
interface SidebarState { interface SidebarState {
@ -53,6 +54,7 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
community={this.props.community} community={this.props.community}
onEdit={this.handleEditCommunity} onEdit={this.handleEditCommunity}
onCancel={this.handleEditCancel} onCancel={this.handleEditCancel}
enableNsfw={this.props.enableNsfw}
/> />
)} )}
</div> </div>

View file

@ -1,8 +1,15 @@
import { Component } from 'inferno'; import { Component } from 'inferno';
import { Subscription } from 'rxjs';
import { retryWhen, delay, take } from 'rxjs/operators';
import { WebSocketService } from '../services'; import { WebSocketService } from '../services';
import {
GetSiteResponse,
WebSocketJsonResponse,
UserOperation,
} from '../interfaces';
import { i18n } from '../i18next'; import { i18n } from '../i18next';
import { T } from 'inferno-i18next'; import { T } from 'inferno-i18next';
import { repoUrl } from '../utils'; import { repoUrl, wsJsonToRes, toast } from '../utils';
interface SilverUser { interface SilverUser {
name: string; name: string;
@ -33,17 +40,28 @@ let silver: Array<SilverUser> = [
// let latinum = []; // let latinum = [];
export class Sponsors extends Component<any, any> { export class Sponsors extends Component<any, any> {
private subscription: Subscription;
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
this.subscription = WebSocketService.Instance.subject
.pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
.subscribe(
msg => this.parseMessage(msg),
err => console.error(err),
() => console.log('complete')
);
WebSocketService.Instance.getSite();
} }
componentDidMount() { componentDidMount() {
document.title = `${i18n.t('sponsors')} - ${
WebSocketService.Instance.site.name
}`;
window.scrollTo(0, 0); window.scrollTo(0, 0);
} }
componentWillUnmount() {
this.subscription.unsubscribe();
}
render() { render() {
return ( return (
<div class="container text-center"> <div class="container text-center">
@ -153,4 +171,16 @@ export class Sponsors extends Component<any, any> {
</div> </div>
); );
} }
parseMessage(msg: WebSocketJsonResponse) {
console.log(msg);
let res = wsJsonToRes(msg);
if (msg.error) {
toast(i18n.t(msg.error), 'danger');
return;
} else if (res.op == UserOperation.GetSite) {
let data = res.data as GetSiteResponse;
document.title = `${i18n.t('sponsors')} - ${data.site.name}`;
}
}
} }

View file

@ -20,6 +20,8 @@ import {
DeleteAccountForm, DeleteAccountForm,
PostResponse, PostResponse,
WebSocketJsonResponse, WebSocketJsonResponse,
GetSiteResponse,
Site,
} from '../interfaces'; } from '../interfaces';
import { WebSocketService, UserService } from '../services'; import { WebSocketService, UserService } from '../services';
import { import {
@ -75,6 +77,7 @@ interface UserState {
deleteAccountLoading: boolean; deleteAccountLoading: boolean;
deleteAccountShowConfirm: boolean; deleteAccountShowConfirm: boolean;
deleteAccountForm: DeleteAccountForm; deleteAccountForm: DeleteAccountForm;
site: Site;
} }
export class User extends Component<any, UserState> { export class User extends Component<any, UserState> {
@ -123,6 +126,20 @@ export class User extends Component<any, UserState> {
deleteAccountForm: { deleteAccountForm: {
password: null, password: null,
}, },
site: {
id: undefined,
name: undefined,
creator_id: undefined,
published: undefined,
creator_name: undefined,
number_of_users: undefined,
number_of_posts: undefined,
number_of_comments: undefined,
number_of_communities: undefined,
enable_downvotes: undefined,
open_registration: undefined,
enable_nsfw: undefined,
},
}; };
constructor(props: any, context: any) { constructor(props: any, context: any) {
@ -149,6 +166,7 @@ export class User extends Component<any, UserState> {
); );
this.refetch(); this.refetch();
WebSocketService.Instance.getSite();
} }
get isCurrentUser() { get isCurrentUser() {
@ -357,6 +375,8 @@ export class User extends Component<any, UserState> {
post={i.data as Post} post={i.data as Post}
admins={this.state.admins} admins={this.state.admins}
showCommunity showCommunity
enableDownvotes={this.state.site.enable_downvotes}
enableNsfw={this.state.site.enable_nsfw}
/> />
) : ( ) : (
<CommentNodes <CommentNodes
@ -364,6 +384,7 @@ export class User extends Component<any, UserState> {
admins={this.state.admins} admins={this.state.admins}
noIndent noIndent
showContext showContext
enableDownvotes={this.state.site.enable_downvotes}
/> />
)} )}
</div> </div>
@ -380,6 +401,7 @@ export class User extends Component<any, UserState> {
admins={this.state.admins} admins={this.state.admins}
noIndent noIndent
showContext showContext
enableDownvotes={this.state.site.enable_downvotes}
/> />
</div> </div>
); );
@ -389,7 +411,13 @@ export class User extends Component<any, UserState> {
return ( return (
<div> <div>
{this.state.posts.map(post => ( {this.state.posts.map(post => (
<PostListing post={post} admins={this.state.admins} showCommunity /> <PostListing
post={post}
admins={this.state.admins}
showCommunity
enableDownvotes={this.state.site.enable_downvotes}
enableNsfw={this.state.site.enable_nsfw}
/>
))} ))}
</div> </div>
); );
@ -680,7 +708,7 @@ export class User extends Component<any, UserState> {
/> />
</div> </div>
</div> </div>
{WebSocketService.Instance.site.enable_nsfw && ( {this.state.site.enable_nsfw && (
<div class="form-group"> <div class="form-group">
<div class="form-check"> <div class="form-check">
<input <input
@ -1117,7 +1145,7 @@ export class User extends Component<any, UserState> {
UserService.Instance.user.show_avatars; UserService.Instance.user.show_avatars;
this.state.userSettingsForm.matrix_user_id = this.state.user.matrix_user_id; this.state.userSettingsForm.matrix_user_id = this.state.user.matrix_user_id;
} }
document.title = `/u/${this.state.user.name} - ${WebSocketService.Instance.site.name}`; document.title = `/u/${this.state.user.name} - ${this.state.site.name}`;
window.scrollTo(0, 0); window.scrollTo(0, 0);
this.setState(this.state); this.setState(this.state);
setupTippy(); setupTippy();
@ -1169,6 +1197,10 @@ export class User extends Component<any, UserState> {
this.state.deleteAccountShowConfirm = false; this.state.deleteAccountShowConfirm = false;
this.setState(this.state); this.setState(this.state);
this.context.router.history.push('/'); this.context.router.history.push('/');
} else if (res.op == UserOperation.GetSite) {
let data = res.data as GetSiteResponse;
this.state.site = data.site;
this.setState(this.state);
} }
} }
} }

View file

@ -25,7 +25,6 @@ import {
TransferSiteForm, TransferSiteForm,
BanUserForm, BanUserForm,
SiteForm, SiteForm,
Site,
UserView, UserView,
GetRepliesForm, GetRepliesForm,
GetUserMentionsForm, GetUserMentionsForm,
@ -57,7 +56,6 @@ export class WebSocketService {
public ws: ReconnectingWebSocket; public ws: ReconnectingWebSocket;
public subject: Observable<any>; public subject: Observable<any>;
public site: Site;
public admins: Array<UserView>; public admins: Array<UserView>;
public banned: Array<UserView>; public banned: Array<UserView>;

2
ui/src/version.ts vendored
View file

@ -1 +1 @@
export const version: string = 'v0.7.12'; export const version: string = 'v0.7.13';

View file

@ -4,13 +4,15 @@
"no_posts": "Inga inlägg.", "no_posts": "Inga inlägg.",
"create_a_post": "Skriv ett inlägg", "create_a_post": "Skriv ett inlägg",
"create_post": "Skapa inlägg", "create_post": "Skapa inlägg",
"number_of_posts": "{{count}} inlägg", "number_of_posts": "{{count}} Inlägg",
"number_of_posts_plural": "{{count}} Inlägg",
"posts": "Inlägg", "posts": "Inlägg",
"related_posts": "Dessa inlägg kan vara relaterade", "related_posts": "Dessa inlägg kan vara relaterade",
"cross_posts": "Den här länken har även publicerats i:", "cross_posts": "Den här länken har även publicerats i:",
"cross_post": "tvärinlägg", "cross_post": "tvärposta",
"comments": "Kommentarer", "comments": "Kommentarer",
"number_of_comments": "{{count}} kommentarer", "number_of_comments": "{{count}} Kommentar",
"number_of_comments_plural": "{{count}} Kommentarer",
"remove_comment": "Radera kommentar", "remove_comment": "Radera kommentar",
"communities": "Gemenskaper", "communities": "Gemenskaper",
"users": "Användare", "users": "Användare",
@ -20,7 +22,8 @@
"subscribed_to_communities": "Prenumererar på <1>gemenskaper</1>", "subscribed_to_communities": "Prenumererar på <1>gemenskaper</1>",
"trending_communities": "Populära <1>gemenskaper</1>", "trending_communities": "Populära <1>gemenskaper</1>",
"list_of_communities": "Lista över gemenskaper", "list_of_communities": "Lista över gemenskaper",
"number_of_communities": "{{count}} gemenskaper", "number_of_communities": "{{count}} Gemenskap",
"number_of_communities_plural": "{{count}} Gemenskaper",
"community_reqs": "gemener, understreck och inga blanksteg.", "community_reqs": "gemener, understreck och inga blanksteg.",
"edit": "redigera", "edit": "redigera",
"reply": "svara", "reply": "svara",
@ -46,33 +49,36 @@
"remove_as_admin": "tag bort som administratör", "remove_as_admin": "tag bort som administratör",
"appoint_as_admin": "lägg till som administratör", "appoint_as_admin": "lägg till som administratör",
"remove": "ta bort", "remove": "ta bort",
"removed": "borttagen", "removed": "borttagen av moderator",
"locked": "låst", "locked": "låst",
"stickied": "fastnålad", "stickied": "fastnålad",
"reason": "Anledning", "reason": "Anledning",
"mark_as_read": "markera som läst", "mark_as_read": "markera som läst",
"mark_as_unread": "markera som oläst", "mark_as_unread": "markera som oläst",
"delete": "radera", "delete": "radera",
"deleted": "raderad", "deleted": "raderad av skapare",
"delete_account": "Ta bort konto", "delete_account": "Ta bort konto",
"delete_account_confirm": "delete_account_confirm": "Varning: den här åtgärden kommer radera alla dina data permanent. Skriv in ditt lösenord för att bekräfta.",
"Varning: den här åtgärden kommer radera alla dina data permanent. Är du säker?",
"restore": "återställ", "restore": "återställ",
"ban": "blockera", "ban": "blockera",
"ban_from_site": "blockera från webbplats", "ban_from_site": "blockera från webbplats",
"unban": "ta bort blockering", "unban": "ta bort blockering",
"unban_from_site": "ta bort blockering från webbplats", "unban_from_site": "ta bort blockering från webbplats",
"banned": "blocerad", "banned": "blockerad",
"save": "spara", "save": "spara",
"unsave": "förkasta", "unsave": "förkasta",
"create": "skapa", "create": "skapa",
"creator": "skapare", "creator": "skapare",
"username": "Användarnamn", "username": "Användarnamn",
"email_or_username": "E-postadress eller användarnamn", "email_or_username": "E-postadress eller användarnamn",
"number_of_users": "{{count}} användare", "number_of_users": "{{count}} Användare",
"number_of_subscribers": "{{count}} prenumeranter", "number_of_users_plural": "{{count}} Användare",
"number_of_points": "{{count}} poäng", "number_of_subscribers": "{{count}} Prenumerant",
"number_online": "{{count}} användare inloggade", "number_of_subscribers_plural": "{{count}} Prenumeranter",
"number_of_points": "{{count}} Poäng",
"number_of_points_plural": "{{count}} Poäng",
"number_online": "{{count}} Användare inloggad",
"number_online_plural": "{{count}} Användare inloggade",
"name": "Namn", "name": "Namn",
"title": "Titel", "title": "Titel",
"category": "Kategori", "category": "Kategori",
@ -108,8 +114,7 @@
"login_sign_up": "Logga in eller skapa konto", "login_sign_up": "Logga in eller skapa konto",
"login": "Logga in", "login": "Logga in",
"sign_up": "Skapa konto", "sign_up": "Skapa konto",
"notifications_error": "notifications_error": "Din webbläsare har inte stöd för skrivbordsaviseringar. Testa Firefox eller Chrome.",
"Din webbläsare har inte stöd för skrivbordsaviseringar. Testa Firefox eller Chrome.",
"unread_messages": "Olästa meddelanden", "unread_messages": "Olästa meddelanden",
"password": "Lösenord", "password": "Lösenord",
"verify_password": "Bekräfta lösenord", "verify_password": "Bekräfta lösenord",
@ -135,11 +140,9 @@
"theme": "Utseende", "theme": "Utseende",
"sponsors": "Sponsorer", "sponsors": "Sponsorer",
"sponsors_of_lemmy": "Lemmys sponsorer", "sponsors_of_lemmy": "Lemmys sponsorer",
"sponsor_message": "sponsor_message": "Lemmy är fri mjukvara med <1>öppen källkod</1>, vilket innebär att ingen reklam, vinstindrivning eller venturekapital förekommer, någonsin. Dina donationer går direkt till att stöda utvecklingen av projektet. Stort tack till följande personer:",
"Lemmy är fri mjukvara med <1>öppen källkod</1>, vilket innebär att ingen reklam, vinstindrivning eller venturekapital förekommer, någonsin. Dina donationer går direkt till att stöda utvecklingen av projektet. Stort tack till följande personer:",
"support_on_patreon": "Stöd på Patreon", "support_on_patreon": "Stöd på Patreon",
"general_sponsors": "general_sponsors": "Allmänna sponsorer är de som donerat mellan 10 och 39 dollar till Lemmy.",
"Allmänna sponsorer är dem som givit mellan 10 och 39\u00a0dollar till Lemmy.",
"crypto": "Kryptovaluta", "crypto": "Kryptovaluta",
"bitcoin": "Bitcoin", "bitcoin": "Bitcoin",
"ethereum": "Ethereum", "ethereum": "Ethereum",
@ -154,16 +157,15 @@
"yes": "ja", "yes": "ja",
"no": "nej", "no": "nej",
"powered_by": "Drivs av", "powered_by": "Drivs av",
"landing_0": "landing_0": "Lemmy är en <1>länksamlare</1> och alternativ till reddit, ämnad att fungera i <2>Fediversumet</2>.<3></3>Lemmy kan drivas av vem som helst, har kommentarstrådar som updateras i realid och är mycket liten (<4>ca 80 kB</4>). Federering med ActivityPub-nätverket är planerat. <5></5>Detta är en <6>väldigt tidig betaversion</6> och många funktioner saknas därför eller är trasiga.<7></7>Föreslå nya funktioner eller anmäl buggar <8>här</8>.<9></9>Skapad i <10>Rust</10>, <11>Actix</11>, <12>Inferno</12> och <13>Typescript</13>.",
"Lemmy är en <1>länksamlare</1> och alternativ till reddit, ämnad att fungera i <2>Fediversumet</2>.<3></3>Lemmy kan drivas av vem som helst, har kommentarstrådar som updateras i realid och är mycket liten (<4>ca 80\u00a0kB</4>). Federering med ActivityPub-nätverket är planerat. <5></5>Detta är en <6>väldigt tidig betaversion</6> och många funktioner saknas därför eller är trasiga.<7></7>Föreslå nya funktioner eller anmäl buggar <8>här</8>.<9></9>Skapad i <10>Rust</10>, <11>Actix</11>, <12>Inferno</12> och <13>Typescript</13>.",
"not_logged_in": "Inte inloggad.", "not_logged_in": "Inte inloggad.",
"community_ban": "Du har blockerats från den här gemenskapen.", "community_ban": "Du har blockerats från den här gemenskapen.",
"site_ban": "Du har blockerats från webbplatsen.", "site_ban": "Du har blockerats från webbplatsen",
"couldnt_create_comment": "Kunde inte skapa kommentar.", "couldnt_create_comment": "Kunde inte skapa kommentar.",
"couldnt_like_comment": "Kunde inte gilla kommentar.", "couldnt_like_comment": "Kunde inte gilla kommentar.",
"couldnt_update_comment": "Kunde inte uppdatera kommentar.", "couldnt_update_comment": "Kunde inte uppdatera kommentar.",
"couldnt_save_comment": "Kunde inte spara kommentar.", "couldnt_save_comment": "Kunde inte spara kommentar.",
"no_comment_edit_allowed": "Har inte behörighet att redigera komentar.", "no_comment_edit_allowed": "Har inte behörighet att redigera kommentar.",
"no_post_edit_allowed": "Har inte behörighet att redigera inlägg.", "no_post_edit_allowed": "Har inte behörighet att redigera inlägg.",
"no_community_edit_allowed": "Har inte behörighet att redigera gemenskap.", "no_community_edit_allowed": "Har inte behörighet att redigera gemenskap.",
"couldnt_find_community": "Kunde inte hitta gemenskap.", "couldnt_find_community": "Kunde inte hitta gemenskap.",
@ -175,19 +177,84 @@
"couldnt_create_post": "Kunde inte skapa inlägg.", "couldnt_create_post": "Kunde inte skapa inlägg.",
"couldnt_like_post": "Kunde inte gilla inlägg.", "couldnt_like_post": "Kunde inte gilla inlägg.",
"couldnt_find_post": "Kunde inte hitta inlägg.", "couldnt_find_post": "Kunde inte hitta inlägg.",
"couldnt_get_posts": "Kunde inte hämta inlägg.", "couldnt_get_posts": "Kunde inte hämta inlägg",
"couldnt_update_post": "Kunde inte uppdatera inlägg.", "couldnt_update_post": "Kunde inte uppdatera inlägg",
"couldnt_save_post": "Kunde inte spara inlägg.", "couldnt_save_post": "Kunde inte spara inlägg.",
"no_slurs": "Inga förolämpningar.", "no_slurs": "Inga förolämpningar.",
"not_an_admin": "Inte en administratör.", "not_an_admin": "Inte en administratör.",
"site_already_exists": "Webbplatsen finns redan.", "site_already_exists": "Webbplatsen finns redan.",
"couldnt_update_site": "Kunde inte uppdatera webbplats.", "couldnt_update_site": "Kunde inte uppdatera webbplats.",
"couldnt_find_that_username_or_email": "couldnt_find_that_username_or_email": "Kunde inte hitta det användarnamnet eller e-postadressen.",
"Kunde inte hitta det användarnamnet eller e-postadressen.",
"password_incorrect": "Ogiltigt lösenord.", "password_incorrect": "Ogiltigt lösenord.",
"passwords_dont_match": "Lösenorden stämmer inte överens.", "passwords_dont_match": "Lösenorden stämmer inte överens.",
"admin_already_created": "Beklagar, men det finns redan en administratör.", "admin_already_created": "Beklagar, men det finns redan en administratör.",
"user_already_exists": "Användaren finns redan.", "user_already_exists": "Användaren finns redan.",
"couldnt_update_user": "Kunde inte uppdatera användare.", "couldnt_update_user": "Kunde inte uppdatera användare.",
"system_err_login": "Systemfel. Försök att logga ut och sedan in igen." "system_err_login": "Systemfel. Försök att logga ut och sedan in igen.",
"invalid_community_name": "Ogiltigt namn.",
"click_to_delete_picture": "Klicka för att ta bort bild.",
"picture_deleted": "Bild borttagen.",
"upload_avatar": "Ladda upp avatar",
"enable_nsfw": "Aktivera NSFW",
"sorting_help": "sorteringshjälp",
"more": "mer",
"avatar": "Avatar",
"cross_posted_to": "Tvärpostat till: ",
"send_secure_message": "Skicka säkert meddelande",
"send_message": "Skicka meddelande",
"message": "Meddelande",
"create_private_message": "Skapa Privatmeddelande",
"show_avatars": "Visa avatarer",
"archive_link": "Arkivera länk",
"admin_settings": "Administratörsinställningar",
"site_config": "Webbplats konfiguration",
"old": "Gammal",
"banned_users": "Blockerade användare",
"docs": "Dokumentation",
"post_title_too_long": "Inläggstitel är för lång.",
"replies": "Svar",
"mentions": "Nämner",
"message_sent": "Meddelande skickat",
"messages": "Meddelanden",
"old_password": "Gammalt lösenord",
"reset_password_mail_sent": "Skicka e-post för att återställa ditt lösenord.",
"forgot_password": "Glömt lösenord",
"password_change": "Lösenordsbyte",
"new_password": "Nytt lösenord",
"no_email_setup": "Denna server har inte satt upp e-post korrekt.",
"matrix_user_id": "Matrix-användare",
"show_context": "Visa innehåll",
"private_message_disclaimer": "Varning: Privata meddelanden på Lemmy är inte säkra. Vänligen skapa ett konto på <1>Riot.im</1> för att skicka säkra meddelanden.",
"send_notifications_to_email": "Skicka aviseringar till E-post",
"language": "Språk",
"browser_default": "Webbläsarestandard",
"downvotes_disabled": "Nedröstningar inaktiverat",
"enable_downvotes": "Aktivera nedröstningar",
"upvote": "Upprösta",
"number_of_upvotes": "{{count}} Uppröst",
"number_of_upvotes_plural": "{{count}} Uppröstningar",
"downvote": "Nedrösta",
"number_of_downvotes": "{{count}} Nedröst",
"number_of_downvotes_plural": "{{count}} Nedröstningar",
"open_registration": "Öppen registrering",
"registration_closed": "Registrering stängd",
"support_on_liberapay": "Stöd på Liberapay",
"support_on_open_collective": "Stöd på OpenCollective",
"donate_to_lemmy": "Donera till Lemmy",
"donate": "Donera",
"silver_sponsors": "Silversponsor är de som donerat 40 dollar till Lemmy.",
"logged_in": "Inloggad.",
"site_saved": "Webbplats sparad.",
"couldnt_get_comments": "Kunde inte hämta kommentarer.",
"action": "Åtgärd",
"email_already_exists": "E-post finns redan.",
"couldnt_create_private_message": "Kunde inte skapa privat meddelande.",
"no_private_message_edit_allowed": "Inte tillåtet att redigera privata meddelanden.",
"couldnt_update_private_message": "Kunde inte uppdatera privat meddelande.",
"time": "Tid",
"emoji_picker": "Emoji-väljare",
"block_leaving": "Är du säker på att du vill lämna?",
"select_a_community": "Välj en gemenskap",
"from": "från",
"invalid_username": "Ogiltigt användarnamn."
} }

View file

@ -14,7 +14,7 @@
"create_a_community": "创建新社群", "create_a_community": "创建新社群",
"create_community": "创建社群", "create_community": "创建社群",
"remove_community": "移除社群", "remove_community": "移除社群",
"subscribed_to_communities": "订阅新 <1>社群</1>", "subscribed_to_communities": "订阅新<1>社群</1>",
"trending_communities": "热门<1>社群</1>", "trending_communities": "热门<1>社群</1>",
"list_of_communities": "社群列表", "list_of_communities": "社群列表",
"community_reqs": "小写字母、下划线_且不含空格。", "community_reqs": "小写字母、下划线_且不含空格。",
@ -27,9 +27,9 @@
"mod": "社群管理", "mod": "社群管理",
"mods": "社群管理", "mods": "社群管理",
"moderates": "监管", "moderates": "监管",
"remove_as_mod": "删除社群管理", "remove_as_mod": "删除社群管理权限",
"appoint_as_mod": "任命为社群管理", "appoint_as_mod": "任命为社群管理",
"modlog": "审核记录", "modlog": "管理记录",
"admin": "总管理员", "admin": "总管理员",
"admins": "总管理员", "admins": "总管理员",
"remove_as_admin": "移除管理员权限", "remove_as_admin": "移除管理员权限",
@ -55,8 +55,8 @@
"number_of_users": "{{count}} 名用户", "number_of_users": "{{count}} 名用户",
"number_of_subscribers": "{{count}} 名订阅者", "number_of_subscribers": "{{count}} 名订阅者",
"number_of_points": "{{count}} 积分", "number_of_points": "{{count}} 积分",
"name": "名", "name": "名",
"title": "标", "title": "标",
"category": "分类", "category": "分类",
"subscribers": "订阅", "subscribers": "订阅",
"both": "全部", "both": "全部",
@ -66,11 +66,11 @@
"subscribed": "已订阅", "subscribed": "已订阅",
"prev": "上一页", "prev": "上一页",
"next": "下一页", "next": "下一页",
"sidebar": "侧边栏", "sidebar": "介绍",
"sort_type": "排序方式", "sort_type": "排序方式",
"hot": "最热", "hot": "最热",
"new": "最新", "new": "最新",
"top_day": "推荐", "top_day": "日",
"week": "周", "week": "周",
"month": "月", "month": "月",
"year": "年", "year": "年",
@ -82,7 +82,7 @@
"mark_all_as_read": "标记所有已读", "mark_all_as_read": "标记所有已读",
"type": "类型", "type": "类型",
"unread": "未读", "unread": "未读",
"reply_sent": "回复发送", "reply_sent": "回复发送",
"search": "搜索", "search": "搜索",
"overview": "个人中心", "overview": "个人中心",
"view": "查看", "view": "查看",
@ -168,10 +168,10 @@
"yes": "是", "yes": "是",
"no": "否", "no": "否",
"logged_in": "已登录。", "logged_in": "已登录。",
"message": "息", "message": "息",
"create_private_message": "创建私信", "create_private_message": "创建私信",
"send_secure_message": "发送安全息", "send_secure_message": "发送安全息",
"send_message": "发送息", "send_message": "发送息",
"more": "更多", "more": "更多",
"preview": "预览", "preview": "预览",
"upload_image": "上传图片", "upload_image": "上传图片",
@ -184,7 +184,7 @@
"sticky": "固定", "sticky": "固定",
"unsticky": "取消固定", "unsticky": "取消固定",
"archive_link": "链接归档", "archive_link": "链接归档",
"settings": "设", "settings": "设",
"stickied": "已置顶", "stickied": "已置顶",
"delete_account": "删除账号", "delete_account": "删除账号",
"delete_account_confirm": "警告!此操作将永久删除你的数据,请输入密码进行确认。", "delete_account_confirm": "警告!此操作将永久删除你的数据,请输入密码进行确认。",
@ -201,7 +201,7 @@
"replies": "回复", "replies": "回复",
"number_online": "{{count}} 名在线用户", "number_online": "{{count}} 名在线用户",
"mentions": "提到", "mentions": "提到",
"message_sent": "已发送信息", "message_sent": "消息已发送",
"old_password": "当前密码", "old_password": "当前密码",
"forgot_password": "忘记密码", "forgot_password": "忘记密码",
"reset_password_mail_sent": "发送邮件重置密码。", "reset_password_mail_sent": "发送邮件重置密码。",
@ -223,7 +223,7 @@
"open_registration": "开放注册", "open_registration": "开放注册",
"registration_closed": "注册功能已关闭", "registration_closed": "注册功能已关闭",
"recent_comments": "最新评论", "recent_comments": "最新评论",
"by": "", "by": " ",
"transfer_community": "转让社群", "transfer_community": "转让社群",
"transfer_site": "站点转让", "transfer_site": "站点转让",
"post_title_too_long": "帖子标题过长。", "post_title_too_long": "帖子标题过长。",
@ -233,7 +233,7 @@
"no_private_message_edit_allowed": "没有编辑私信的权限。", "no_private_message_edit_allowed": "没有编辑私信的权限。",
"couldnt_update_private_message": "无法更新私信。", "couldnt_update_private_message": "无法更新私信。",
"time": "时间", "time": "时间",
"action": "动", "action": "",
"block_leaving": "确定要离开吗?", "block_leaving": "确定要离开吗?",
"show_context": "显示上下文", "show_context": "显示上下文",
"admin_settings": "管理员设置", "admin_settings": "管理员设置",