mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-25 22:01:13 +00:00
Actually sending ws requests, some other fixes.
This commit is contained in:
parent
7ae444d209
commit
368d4199a5
32 changed files with 362 additions and 250 deletions
|
@ -1,5 +1,5 @@
|
||||||
FROM node:14-alpine as builder
|
FROM node:14-alpine as builder
|
||||||
RUN apk update && apk add yarn curl bash && rm -rf /var/cache/apk/*
|
RUN apk add yarn curl bash --no-cache
|
||||||
|
|
||||||
RUN curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | bash -s -- -b /usr/local/bin
|
RUN curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | bash -s -- -b /usr/local/bin
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ RUN yarn build:prod
|
||||||
|
|
||||||
# Pruning
|
# Pruning
|
||||||
# RUN npm prune --production
|
# RUN npm prune --production
|
||||||
RUN /usr/local/bin/node-prune
|
RUN node-prune
|
||||||
|
|
||||||
FROM node:14-alpine as runner
|
FROM node:14-alpine as runner
|
||||||
COPY --from=builder /usr/src/app/dist /app/dist
|
COPY --from=builder /usr/src/app/dist /app/dist
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { Helmet } from 'inferno-helmet';
|
||||||
import { initializeSite } from '../shared/initialize';
|
import { initializeSite } from '../shared/initialize';
|
||||||
import { httpUri } from '../shared/env';
|
import { httpUri } from '../shared/env';
|
||||||
import { IncomingHttpHeaders } from 'http';
|
import { IncomingHttpHeaders } from 'http';
|
||||||
|
import { setOptionalAuth } from '../shared/utils';
|
||||||
|
|
||||||
const server = express();
|
const server = express();
|
||||||
const port = 1234;
|
const port = 1234;
|
||||||
|
@ -29,7 +30,8 @@ server.get('/*', async (req, res) => {
|
||||||
const context = {} as any;
|
const context = {} as any;
|
||||||
let auth: string = IsomorphicCookie.load('jwt', req);
|
let auth: string = IsomorphicCookie.load('jwt', req);
|
||||||
|
|
||||||
let getSiteForm: GetSite = { auth };
|
let getSiteForm: GetSite = {};
|
||||||
|
setOptionalAuth(getSiteForm, auth);
|
||||||
|
|
||||||
let promises: Promise<any>[] = [];
|
let promises: Promise<any>[] = [];
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
GetSiteConfigResponse,
|
GetSiteConfigResponse,
|
||||||
GetSiteConfig,
|
GetSiteConfig,
|
||||||
} from 'lemmy-js-client';
|
} from 'lemmy-js-client';
|
||||||
import { UserService, WebSocketService } from '../services';
|
import { WebSocketService } from '../services';
|
||||||
import {
|
import {
|
||||||
wsJsonToRes,
|
wsJsonToRes,
|
||||||
capitalizeFirstLetter,
|
capitalizeFirstLetter,
|
||||||
|
@ -18,6 +18,8 @@ import {
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
isBrowser,
|
isBrowser,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import autosize from 'autosize';
|
import autosize from 'autosize';
|
||||||
import { SiteForm } from './site-form';
|
import { SiteForm } from './site-form';
|
||||||
|
@ -42,7 +44,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
|
||||||
siteRes: this.isoData.site_res,
|
siteRes: this.isoData.site_res,
|
||||||
siteConfigForm: {
|
siteConfigForm: {
|
||||||
config_hjson: null,
|
config_hjson: null,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
},
|
},
|
||||||
siteConfigRes: {
|
siteConfigRes: {
|
||||||
config_hjson: null,
|
config_hjson: null,
|
||||||
|
@ -66,9 +68,11 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
|
||||||
this.state.siteConfigLoading = false;
|
this.state.siteConfigLoading = false;
|
||||||
this.state.loading = false;
|
this.state.loading = false;
|
||||||
} else {
|
} else {
|
||||||
WebSocketService.Instance.client.getSiteConfig({
|
WebSocketService.Instance.send(
|
||||||
auth: UserService.Instance.authField(),
|
wsClient.getSiteConfig({
|
||||||
});
|
auth: authField(),
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +202,9 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
|
||||||
handleSiteConfigSubmit(i: AdminSettings, event: any) {
|
handleSiteConfigSubmit(i: AdminSettings, event: any) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
i.state.siteConfigLoading = true;
|
i.state.siteConfigLoading = true;
|
||||||
WebSocketService.Instance.client.saveSiteConfig(i.state.siteConfigForm);
|
WebSocketService.Instance.send(
|
||||||
|
wsClient.saveSiteConfig(i.state.siteConfigForm)
|
||||||
|
);
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ export class App extends Component<AppProps, any> {
|
||||||
<div>
|
<div>
|
||||||
<Theme user={siteRes.my_user} />
|
<Theme user={siteRes.my_user} />
|
||||||
{siteRes &&
|
{siteRes &&
|
||||||
siteRes.site_view.site &&
|
siteRes.site_view &&
|
||||||
this.props.siteRes.site_view.site.icon && (
|
this.props.siteRes.site_view.site.icon && (
|
||||||
<Helmet>
|
<Helmet>
|
||||||
<link
|
<link
|
||||||
|
|
|
@ -9,7 +9,9 @@ import {
|
||||||
} from 'lemmy-js-client';
|
} from 'lemmy-js-client';
|
||||||
import { CommentNode as CommentNodeI } from '../interfaces';
|
import { CommentNode as CommentNodeI } from '../interfaces';
|
||||||
import {
|
import {
|
||||||
|
authField,
|
||||||
capitalizeFirstLetter,
|
capitalizeFirstLetter,
|
||||||
|
wsClient,
|
||||||
wsJsonToRes,
|
wsJsonToRes,
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
@ -21,11 +23,11 @@ import { MarkdownTextArea } from './markdown-textarea';
|
||||||
|
|
||||||
interface CommentFormProps {
|
interface CommentFormProps {
|
||||||
postId?: number;
|
postId?: number;
|
||||||
node?: CommentNodeI;
|
node?: CommentNodeI; // Can either be the parent, or the editable comment
|
||||||
onReplyCancel?(): any;
|
|
||||||
edit?: boolean;
|
edit?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
focus?: boolean;
|
focus?: boolean;
|
||||||
|
onReplyCancel?(): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CommentFormState {
|
interface CommentFormState {
|
||||||
|
@ -68,7 +70,7 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
|
||||||
{UserService.Instance.user ? (
|
{UserService.Instance.user ? (
|
||||||
<MarkdownTextArea
|
<MarkdownTextArea
|
||||||
initialContent={
|
initialContent={
|
||||||
this.props.node
|
this.props.edit
|
||||||
? this.props.node.comment_view.comment.content
|
? this.props.node.comment_view.comment.content
|
||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
|
@ -108,18 +110,18 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
|
||||||
content,
|
content,
|
||||||
form_id: this.state.formId,
|
form_id: this.state.formId,
|
||||||
edit_id: node.comment_view.comment.id,
|
edit_id: node.comment_view.comment.id,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.editComment(form);
|
WebSocketService.Instance.send(wsClient.editComment(form));
|
||||||
} else {
|
} else {
|
||||||
let form: CreateComment = {
|
let form: CreateComment = {
|
||||||
content,
|
content,
|
||||||
form_id: this.state.formId,
|
form_id: this.state.formId,
|
||||||
post_id: node ? node.comment_view.post.id : this.props.postId,
|
post_id: node ? node.comment_view.post.id : this.props.postId,
|
||||||
parent_id: node ? node.comment_view.comment.parent_id : null,
|
parent_id: node ? node.comment_view.comment.id : null,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.createComment(form);
|
WebSocketService.Instance.send(wsClient.createComment(form));
|
||||||
}
|
}
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@ import {
|
||||||
isMod,
|
isMod,
|
||||||
setupTippy,
|
setupTippy,
|
||||||
colorList,
|
colorList,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { MomentTime } from './moment-time';
|
import { MomentTime } from './moment-time';
|
||||||
|
@ -849,9 +851,9 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
let deleteForm: DeleteComment = {
|
let deleteForm: DeleteComment = {
|
||||||
edit_id: comment.id,
|
edit_id: comment.id,
|
||||||
deleted: !comment.deleted,
|
deleted: !comment.deleted,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.deleteComment(deleteForm);
|
WebSocketService.Instance.send(wsClient.deleteComment(deleteForm));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSaveCommentClick(i: CommentNode) {
|
handleSaveCommentClick(i: CommentNode) {
|
||||||
|
@ -860,10 +862,10 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
let form: SaveComment = {
|
let form: SaveComment = {
|
||||||
comment_id: cv.comment.id,
|
comment_id: cv.comment.id,
|
||||||
save,
|
save,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
|
|
||||||
WebSocketService.Instance.client.saveComment(form);
|
WebSocketService.Instance.send(wsClient.saveComment(form));
|
||||||
|
|
||||||
i.state.saveLoading = true;
|
i.state.saveLoading = true;
|
||||||
i.setState(this.state);
|
i.setState(this.state);
|
||||||
|
@ -895,10 +897,10 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
let form: CreateCommentLike = {
|
let form: CreateCommentLike = {
|
||||||
comment_id: i.comment_view.comment.id,
|
comment_id: i.comment_view.comment.id,
|
||||||
score: this.state.my_vote,
|
score: this.state.my_vote,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
|
|
||||||
WebSocketService.Instance.client.likeComment(form);
|
WebSocketService.Instance.send(wsClient.likeComment(form));
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
setupTippy();
|
setupTippy();
|
||||||
}
|
}
|
||||||
|
@ -923,10 +925,10 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
let form: CreateCommentLike = {
|
let form: CreateCommentLike = {
|
||||||
comment_id: i.comment_view.comment.id,
|
comment_id: i.comment_view.comment.id,
|
||||||
score: this.state.my_vote,
|
score: this.state.my_vote,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
|
|
||||||
WebSocketService.Instance.client.likeComment(form);
|
WebSocketService.Instance.send(wsClient.likeComment(form));
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
setupTippy();
|
setupTippy();
|
||||||
}
|
}
|
||||||
|
@ -952,9 +954,9 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
edit_id: comment.id,
|
edit_id: comment.id,
|
||||||
removed: !comment.removed,
|
removed: !comment.removed,
|
||||||
reason: i.state.removeReason,
|
reason: i.state.removeReason,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.removeComment(form);
|
WebSocketService.Instance.send(wsClient.removeComment(form));
|
||||||
|
|
||||||
i.state.showRemoveDialog = false;
|
i.state.showRemoveDialog = false;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
|
@ -971,16 +973,16 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
let form: MarkUserMentionAsRead = {
|
let form: MarkUserMentionAsRead = {
|
||||||
user_mention_id: i.props.node.comment_view.user_mention.id,
|
user_mention_id: i.props.node.comment_view.user_mention.id,
|
||||||
read: !i.props.node.comment_view.user_mention.read,
|
read: !i.props.node.comment_view.user_mention.read,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.markUserMentionAsRead(form);
|
WebSocketService.Instance.send(wsClient.markUserMentionAsRead(form));
|
||||||
} else {
|
} else {
|
||||||
let form: MarkCommentAsRead = {
|
let form: MarkCommentAsRead = {
|
||||||
comment_id: i.props.node.comment_view.comment.id,
|
comment_id: i.props.node.comment_view.comment.id,
|
||||||
read: !i.props.node.comment_view.comment.read,
|
read: !i.props.node.comment_view.comment.read,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.markCommentAsRead(form);
|
WebSocketService.Instance.send(wsClient.markCommentAsRead(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
i.state.readLoading = true;
|
i.state.readLoading = true;
|
||||||
|
@ -1037,9 +1039,9 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
remove_data: i.state.removeData,
|
remove_data: i.state.removeData,
|
||||||
reason: i.state.banReason,
|
reason: i.state.banReason,
|
||||||
expires: getUnixTime(i.state.banExpires),
|
expires: getUnixTime(i.state.banExpires),
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.banFromCommunity(form);
|
WebSocketService.Instance.send(wsClient.banFromCommunity(form));
|
||||||
} else {
|
} else {
|
||||||
// If its an unban, restore all their data
|
// If its an unban, restore all their data
|
||||||
let ban = !cv.creator.banned;
|
let ban = !cv.creator.banned;
|
||||||
|
@ -1052,9 +1054,9 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
remove_data: i.state.removeData,
|
remove_data: i.state.removeData,
|
||||||
reason: i.state.banReason,
|
reason: i.state.banReason,
|
||||||
expires: getUnixTime(i.state.banExpires),
|
expires: getUnixTime(i.state.banExpires),
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.banUser(form);
|
WebSocketService.Instance.send(wsClient.banUser(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
i.state.showBanDialog = false;
|
i.state.showBanDialog = false;
|
||||||
|
@ -1077,9 +1079,9 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
user_id: cv.creator.id,
|
user_id: cv.creator.id,
|
||||||
community_id: cv.community.id,
|
community_id: cv.community.id,
|
||||||
added: !i.isMod,
|
added: !i.isMod,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.addModToCommunity(form);
|
WebSocketService.Instance.send(wsClient.addModToCommunity(form));
|
||||||
i.state.showConfirmAppointAsMod = false;
|
i.state.showConfirmAppointAsMod = false;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
@ -1098,9 +1100,9 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
let form: AddAdmin = {
|
let form: AddAdmin = {
|
||||||
user_id: i.props.node.comment_view.creator.id,
|
user_id: i.props.node.comment_view.creator.id,
|
||||||
added: !i.isAdmin,
|
added: !i.isAdmin,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.addAdmin(form);
|
WebSocketService.Instance.send(wsClient.addAdmin(form));
|
||||||
i.state.showConfirmAppointAsAdmin = false;
|
i.state.showConfirmAppointAsAdmin = false;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
@ -1120,9 +1122,9 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
let form: TransferCommunity = {
|
let form: TransferCommunity = {
|
||||||
community_id: cv.community.id,
|
community_id: cv.community.id,
|
||||||
user_id: cv.creator.id,
|
user_id: cv.creator.id,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.transferCommunity(form);
|
WebSocketService.Instance.send(wsClient.transferCommunity(form));
|
||||||
i.state.showConfirmTransferCommunity = false;
|
i.state.showConfirmTransferCommunity = false;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
@ -1140,9 +1142,9 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
handleTransferSite(i: CommentNode) {
|
handleTransferSite(i: CommentNode) {
|
||||||
let form: TransferSite = {
|
let form: TransferSite = {
|
||||||
user_id: i.props.node.comment_view.creator.id,
|
user_id: i.props.node.comment_view.creator.id,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.transferSite(form);
|
WebSocketService.Instance.send(wsClient.transferSite(form));
|
||||||
i.state.showConfirmTransferSite = false;
|
i.state.showConfirmTransferSite = false;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
SortType,
|
SortType,
|
||||||
SiteView,
|
SiteView,
|
||||||
} from 'lemmy-js-client';
|
} from 'lemmy-js-client';
|
||||||
import { UserService, WebSocketService } from '../services';
|
import { WebSocketService } from '../services';
|
||||||
import {
|
import {
|
||||||
wsJsonToRes,
|
wsJsonToRes,
|
||||||
toast,
|
toast,
|
||||||
|
@ -20,6 +20,9 @@ import {
|
||||||
setIsoData,
|
setIsoData,
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
|
setOptionalAuth,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { CommunityLink } from './community-link';
|
import { CommunityLink } from './community-link';
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
|
@ -212,18 +215,18 @@ export class Communities extends Component<any, CommunitiesState> {
|
||||||
let form: FollowCommunity = {
|
let form: FollowCommunity = {
|
||||||
community_id: communityId,
|
community_id: communityId,
|
||||||
follow: false,
|
follow: false,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.followCommunity(form);
|
WebSocketService.Instance.send(wsClient.followCommunity(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubscribe(communityId: number) {
|
handleSubscribe(communityId: number) {
|
||||||
let form: FollowCommunity = {
|
let form: FollowCommunity = {
|
||||||
community_id: communityId,
|
community_id: communityId,
|
||||||
follow: true,
|
follow: true,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.followCommunity(form);
|
WebSocketService.Instance.send(wsClient.followCommunity(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
refetch() {
|
refetch() {
|
||||||
|
@ -231,10 +234,12 @@ export class Communities extends Component<any, CommunitiesState> {
|
||||||
sort: SortType.TopAll,
|
sort: SortType.TopAll,
|
||||||
limit: communityLimit,
|
limit: communityLimit,
|
||||||
page: this.state.page,
|
page: this.state.page,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
WebSocketService.Instance.client.listCommunities(listCommunitiesForm);
|
WebSocketService.Instance.send(
|
||||||
|
wsClient.listCommunities(listCommunitiesForm)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
||||||
|
@ -244,8 +249,8 @@ export class Communities extends Component<any, CommunitiesState> {
|
||||||
sort: SortType.TopAll,
|
sort: SortType.TopAll,
|
||||||
limit: communityLimit,
|
limit: communityLimit,
|
||||||
page,
|
page,
|
||||||
auth: req.auth,
|
|
||||||
};
|
};
|
||||||
|
setOptionalAuth(listCommunitiesForm, req.auth);
|
||||||
|
|
||||||
return [req.client.listCommunities(listCommunitiesForm)];
|
return [req.client.listCommunities(listCommunitiesForm)];
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
CommunityResponse,
|
CommunityResponse,
|
||||||
CommunityView,
|
CommunityView,
|
||||||
} from 'lemmy-js-client';
|
} from 'lemmy-js-client';
|
||||||
import { UserService, WebSocketService } from '../services';
|
import { WebSocketService } from '../services';
|
||||||
import {
|
import {
|
||||||
wsJsonToRes,
|
wsJsonToRes,
|
||||||
capitalizeFirstLetter,
|
capitalizeFirstLetter,
|
||||||
|
@ -17,6 +17,8 @@ import {
|
||||||
randomStr,
|
randomStr,
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
|
|
||||||
|
@ -52,7 +54,7 @@ export class CommunityForm extends Component<
|
||||||
nsfw: false,
|
nsfw: false,
|
||||||
icon: null,
|
icon: null,
|
||||||
banner: null,
|
banner: null,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
},
|
},
|
||||||
loading: false,
|
loading: false,
|
||||||
};
|
};
|
||||||
|
@ -82,7 +84,7 @@ export class CommunityForm extends Component<
|
||||||
nsfw: cv.community.nsfw,
|
nsfw: cv.community.nsfw,
|
||||||
icon: cv.community.icon,
|
icon: cv.community.icon,
|
||||||
banner: cv.community.banner,
|
banner: cv.community.banner,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,9 +285,11 @@ export class CommunityForm extends Component<
|
||||||
...i.state.communityForm,
|
...i.state.communityForm,
|
||||||
edit_id: i.props.community_view.community.id,
|
edit_id: i.props.community_view.community.id,
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.editCommunity(form);
|
WebSocketService.Instance.send(wsClient.editCommunity(form));
|
||||||
} else {
|
} else {
|
||||||
WebSocketService.Instance.client.createCommunity(i.state.communityForm);
|
WebSocketService.Instance.send(
|
||||||
|
wsClient.createCommunity(i.state.communityForm)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,9 @@ import {
|
||||||
isBrowser,
|
isBrowser,
|
||||||
communityRSSUrl,
|
communityRSSUrl,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
|
setOptionalAuth,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
|
|
||||||
|
@ -126,7 +129,7 @@ export class Community extends Component<any, State> {
|
||||||
} else {
|
} else {
|
||||||
this.fetchCommunity();
|
this.fetchCommunity();
|
||||||
this.fetchData();
|
this.fetchData();
|
||||||
WebSocketService.Instance.client.listCategories();
|
WebSocketService.Instance.send(wsClient.listCategories());
|
||||||
}
|
}
|
||||||
setupTippy();
|
setupTippy();
|
||||||
}
|
}
|
||||||
|
@ -135,9 +138,9 @@ export class Community extends Component<any, State> {
|
||||||
let form: GetCommunity = {
|
let form: GetCommunity = {
|
||||||
id: this.state.communityId ? this.state.communityId : null,
|
id: this.state.communityId ? this.state.communityId : null,
|
||||||
name: this.state.communityName ? this.state.communityName : null,
|
name: this.state.communityName ? this.state.communityName : null,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.getCommunity(form);
|
WebSocketService.Instance.send(wsClient.getCommunity(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
@ -170,7 +173,7 @@ export class Community extends Component<any, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let communityForm: GetCommunity = id ? { id } : { name: name_ };
|
let communityForm: GetCommunity = id ? { id } : { name: name_ };
|
||||||
communityForm.auth = req.auth;
|
setOptionalAuth(communityForm, req.auth);
|
||||||
promises.push(req.client.getCommunity(communityForm));
|
promises.push(req.client.getCommunity(communityForm));
|
||||||
|
|
||||||
let dataType: DataType = pathSplit[4]
|
let dataType: DataType = pathSplit[4]
|
||||||
|
@ -191,8 +194,8 @@ export class Community extends Component<any, State> {
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
sort,
|
sort,
|
||||||
type_: ListingType.Community,
|
type_: ListingType.Community,
|
||||||
auth: req.auth,
|
|
||||||
};
|
};
|
||||||
|
setOptionalAuth(getPostsForm, req.auth);
|
||||||
this.setIdOrName(getPostsForm, id, name_);
|
this.setIdOrName(getPostsForm, id, name_);
|
||||||
promises.push(req.client.getPosts(getPostsForm));
|
promises.push(req.client.getPosts(getPostsForm));
|
||||||
} else {
|
} else {
|
||||||
|
@ -201,8 +204,8 @@ export class Community extends Component<any, State> {
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
sort,
|
sort,
|
||||||
type_: ListingType.Community,
|
type_: ListingType.Community,
|
||||||
auth: req.auth,
|
|
||||||
};
|
};
|
||||||
|
setOptionalAuth(getCommentsForm, req.auth);
|
||||||
this.setIdOrName(getCommentsForm, id, name_);
|
this.setIdOrName(getCommentsForm, id, name_);
|
||||||
promises.push(req.client.getComments(getCommentsForm));
|
promises.push(req.client.getComments(getCommentsForm));
|
||||||
}
|
}
|
||||||
|
@ -236,7 +239,7 @@ export class Community extends Component<any, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let cv = this.state.communityRes.community_view;
|
let cv = this.state.communityRes?.community_view;
|
||||||
return (
|
return (
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{this.state.communityLoading ? (
|
{this.state.communityLoading ? (
|
||||||
|
@ -418,9 +421,9 @@ export class Community extends Component<any, State> {
|
||||||
type_: ListingType.Community,
|
type_: ListingType.Community,
|
||||||
community_id: this.state.communityId,
|
community_id: this.state.communityId,
|
||||||
community_name: this.state.communityName,
|
community_name: this.state.communityName,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.getPosts(form);
|
WebSocketService.Instance.send(wsClient.getPosts(form));
|
||||||
} else {
|
} else {
|
||||||
let form: GetComments = {
|
let form: GetComments = {
|
||||||
page: this.state.page,
|
page: this.state.page,
|
||||||
|
@ -429,9 +432,9 @@ export class Community extends Component<any, State> {
|
||||||
type_: ListingType.Community,
|
type_: ListingType.Community,
|
||||||
community_id: this.state.communityId,
|
community_id: this.state.communityId,
|
||||||
community_name: this.state.communityName,
|
community_name: this.state.communityName,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.getComments(form);
|
WebSocketService.Instance.send(wsClient.getComments(form));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,9 +445,11 @@ export class Community extends Component<any, State> {
|
||||||
this.context.router.history.push('/');
|
this.context.router.history.push('/');
|
||||||
return;
|
return;
|
||||||
} else if (msg.reconnect) {
|
} else if (msg.reconnect) {
|
||||||
WebSocketService.Instance.client.communityJoin({
|
WebSocketService.Instance.send(
|
||||||
community_id: this.state.communityRes.community_view.community.id,
|
wsClient.communityJoin({
|
||||||
});
|
community_id: this.state.communityRes.community_view.community.id,
|
||||||
|
})
|
||||||
|
);
|
||||||
this.fetchData();
|
this.fetchData();
|
||||||
} else if (op == UserOperation.GetCommunity) {
|
} else if (op == UserOperation.GetCommunity) {
|
||||||
let data = wsJsonToRes<GetCommunityResponse>(msg).data;
|
let data = wsJsonToRes<GetCommunityResponse>(msg).data;
|
||||||
|
@ -452,9 +457,11 @@ export class Community extends Component<any, State> {
|
||||||
this.state.communityLoading = false;
|
this.state.communityLoading = false;
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
// TODO why is there no auth in this form?
|
// TODO why is there no auth in this form?
|
||||||
WebSocketService.Instance.client.communityJoin({
|
WebSocketService.Instance.send(
|
||||||
community_id: data.community_view.community.id,
|
wsClient.communityJoin({
|
||||||
});
|
community_id: data.community_view.community.id,
|
||||||
|
})
|
||||||
|
);
|
||||||
} else if (
|
} else if (
|
||||||
op == UserOperation.EditCommunity ||
|
op == UserOperation.EditCommunity ||
|
||||||
op == UserOperation.DeleteCommunity ||
|
op == UserOperation.DeleteCommunity ||
|
||||||
|
|
|
@ -16,6 +16,7 @@ import {
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
isBrowser,
|
isBrowser,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { WebSocketService, UserService } from '../services';
|
import { WebSocketService, UserService } from '../services';
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
|
@ -53,7 +54,7 @@ export class CreateCommunity extends Component<any, CreateCommunityState> {
|
||||||
this.state.categories = this.isoData.routeData[0].categories;
|
this.state.categories = this.isoData.routeData[0].categories;
|
||||||
this.state.loading = false;
|
this.state.loading = false;
|
||||||
} else {
|
} else {
|
||||||
WebSocketService.Instance.client.listCategories();
|
WebSocketService.Instance.send(wsClient.listCategories());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,12 @@ import { Subscription } from 'rxjs';
|
||||||
import { PostForm } from './post-form';
|
import { PostForm } from './post-form';
|
||||||
import { HtmlTags } from './html-tags';
|
import { HtmlTags } from './html-tags';
|
||||||
import {
|
import {
|
||||||
|
authField,
|
||||||
isBrowser,
|
isBrowser,
|
||||||
setIsoData,
|
setIsoData,
|
||||||
|
setOptionalAuth,
|
||||||
toast,
|
toast,
|
||||||
|
wsClient,
|
||||||
wsJsonToRes,
|
wsJsonToRes,
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
@ -64,9 +67,11 @@ export class CreatePost extends Component<any, CreatePostState> {
|
||||||
let listCommunitiesForm: ListCommunities = {
|
let listCommunitiesForm: ListCommunities = {
|
||||||
sort: SortType.TopAll,
|
sort: SortType.TopAll,
|
||||||
limit: 9999,
|
limit: 9999,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.listCommunities(listCommunitiesForm);
|
WebSocketService.Instance.send(
|
||||||
|
wsClient.listCommunities(listCommunitiesForm)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
@ -157,8 +162,8 @@ export class CreatePost extends Component<any, CreatePostState> {
|
||||||
let listCommunitiesForm: ListCommunities = {
|
let listCommunitiesForm: ListCommunities = {
|
||||||
sort: SortType.TopAll,
|
sort: SortType.TopAll,
|
||||||
limit: 9999,
|
limit: 9999,
|
||||||
auth: req.auth,
|
|
||||||
};
|
};
|
||||||
|
setOptionalAuth(listCommunitiesForm, req.auth);
|
||||||
return [req.client.listCommunities(listCommunitiesForm)];
|
return [req.client.listCommunities(listCommunitiesForm)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,12 @@ import {
|
||||||
GetUserDetails,
|
GetUserDetails,
|
||||||
} from 'lemmy-js-client';
|
} from 'lemmy-js-client';
|
||||||
import {
|
import {
|
||||||
|
authField,
|
||||||
getRecipientIdFromProps,
|
getRecipientIdFromProps,
|
||||||
isBrowser,
|
isBrowser,
|
||||||
setIsoData,
|
setIsoData,
|
||||||
toast,
|
toast,
|
||||||
|
wsClient,
|
||||||
wsJsonToRes,
|
wsJsonToRes,
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
@ -73,9 +75,9 @@ export class CreatePrivateMessage extends Component<
|
||||||
user_id: this.state.recipient_id,
|
user_id: this.state.recipient_id,
|
||||||
sort: SortType.New,
|
sort: SortType.New,
|
||||||
saved_only: false,
|
saved_only: false,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.getUserDetails(form);
|
WebSocketService.Instance.send(wsClient.getUserDetails(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
||||||
|
|
|
@ -31,6 +31,8 @@ import {
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
isBrowser,
|
isBrowser,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { CommentNodes } from './comment-nodes';
|
import { CommentNodes } from './comment-nodes';
|
||||||
import { PrivateMessage } from './private-message';
|
import { PrivateMessage } from './private-message';
|
||||||
|
@ -498,26 +500,28 @@ export class Inbox extends Component<any, InboxState> {
|
||||||
unread_only: this.state.unreadOrAll == UnreadOrAll.Unread,
|
unread_only: this.state.unreadOrAll == UnreadOrAll.Unread,
|
||||||
page: this.state.page,
|
page: this.state.page,
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.getReplies(repliesForm);
|
WebSocketService.Instance.send(wsClient.getReplies(repliesForm));
|
||||||
|
|
||||||
let userMentionsForm: GetUserMentions = {
|
let userMentionsForm: GetUserMentions = {
|
||||||
sort: this.state.sort,
|
sort: this.state.sort,
|
||||||
unread_only: this.state.unreadOrAll == UnreadOrAll.Unread,
|
unread_only: this.state.unreadOrAll == UnreadOrAll.Unread,
|
||||||
page: this.state.page,
|
page: this.state.page,
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.getUserMentions(userMentionsForm);
|
WebSocketService.Instance.send(wsClient.getUserMentions(userMentionsForm));
|
||||||
|
|
||||||
let privateMessagesForm: GetPrivateMessages = {
|
let privateMessagesForm: GetPrivateMessages = {
|
||||||
unread_only: this.state.unreadOrAll == UnreadOrAll.Unread,
|
unread_only: this.state.unreadOrAll == UnreadOrAll.Unread,
|
||||||
page: this.state.page,
|
page: this.state.page,
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.getPrivateMessages(privateMessagesForm);
|
WebSocketService.Instance.send(
|
||||||
|
wsClient.getPrivateMessages(privateMessagesForm)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSortChange(val: SortType) {
|
handleSortChange(val: SortType) {
|
||||||
|
@ -528,9 +532,11 @@ export class Inbox extends Component<any, InboxState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
markAllAsRead(i: Inbox) {
|
markAllAsRead(i: Inbox) {
|
||||||
WebSocketService.Instance.client.markAllAsRead({
|
WebSocketService.Instance.send(
|
||||||
auth: UserService.Instance.authField(),
|
wsClient.markAllAsRead({
|
||||||
});
|
auth: authField(),
|
||||||
|
})
|
||||||
|
);
|
||||||
i.state.replies = [];
|
i.state.replies = [];
|
||||||
i.state.mentions = [];
|
i.state.mentions = [];
|
||||||
i.state.messages = [];
|
i.state.messages = [];
|
||||||
|
|
|
@ -19,6 +19,8 @@ import {
|
||||||
isBrowser,
|
isBrowser,
|
||||||
setIsoData,
|
setIsoData,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
import { HtmlTags } from './html-tags';
|
import { HtmlTags } from './html-tags';
|
||||||
|
@ -67,7 +69,7 @@ export class Login extends Component<any, State> {
|
||||||
this.subscription = wsSubscribe(this.parseMessage);
|
this.subscription = wsSubscribe(this.parseMessage);
|
||||||
|
|
||||||
if (isBrowser()) {
|
if (isBrowser()) {
|
||||||
WebSocketService.Instance.client.getCaptcha();
|
WebSocketService.Instance.send(wsClient.getCaptcha());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,7 +351,7 @@ export class Login extends Component<any, State> {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
i.state.loginLoading = true;
|
i.state.loginLoading = true;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
WebSocketService.Instance.client.login(i.state.loginForm);
|
WebSocketService.Instance.send(wsClient.login(i.state.loginForm));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleLoginUsernameChange(i: Login, event: any) {
|
handleLoginUsernameChange(i: Login, event: any) {
|
||||||
|
@ -366,7 +368,7 @@ export class Login extends Component<any, State> {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
i.state.registerLoading = true;
|
i.state.registerLoading = true;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
WebSocketService.Instance.client.register(i.state.registerForm);
|
WebSocketService.Instance.send(wsClient.register(i.state.registerForm));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRegisterUsernameChange(i: Login, event: any) {
|
handleRegisterUsernameChange(i: Login, event: any) {
|
||||||
|
@ -404,7 +406,7 @@ export class Login extends Component<any, State> {
|
||||||
|
|
||||||
handleRegenCaptcha(_i: Login, event: any) {
|
handleRegenCaptcha(_i: Login, event: any) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
WebSocketService.Instance.client.getCaptcha();
|
WebSocketService.Instance.send(wsClient.getCaptcha());
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePasswordReset(i: Login, event: any) {
|
handlePasswordReset(i: Login, event: any) {
|
||||||
|
@ -412,7 +414,7 @@ export class Login extends Component<any, State> {
|
||||||
let resetForm: PasswordReset = {
|
let resetForm: PasswordReset = {
|
||||||
email: i.state.loginForm.username_or_email,
|
email: i.state.loginForm.username_or_email,
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.passwordReset(resetForm);
|
WebSocketService.Instance.send(wsClient.passwordReset(resetForm));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCaptchaPlay(i: Login, event: any) {
|
handleCaptchaPlay(i: Login, event: any) {
|
||||||
|
@ -439,7 +441,7 @@ export class Login extends Component<any, State> {
|
||||||
this.state = this.emptyState;
|
this.state = this.emptyState;
|
||||||
this.state.registerForm.captcha_answer = undefined;
|
this.state.registerForm.captcha_answer = undefined;
|
||||||
// Refetch another captcha
|
// Refetch another captcha
|
||||||
WebSocketService.Instance.client.getCaptcha();
|
WebSocketService.Instance.send(wsClient.getCaptcha());
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
@ -448,9 +450,11 @@ export class Login extends Component<any, State> {
|
||||||
this.state = this.emptyState;
|
this.state = this.emptyState;
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
UserService.Instance.login(data);
|
UserService.Instance.login(data);
|
||||||
WebSocketService.Instance.client.userJoin({
|
WebSocketService.Instance.send(
|
||||||
auth: UserService.Instance.authField(),
|
wsClient.userJoin({
|
||||||
});
|
auth: authField(),
|
||||||
|
})
|
||||||
|
);
|
||||||
toast(i18n.t('logged_in'));
|
toast(i18n.t('logged_in'));
|
||||||
this.props.history.push('/');
|
this.props.history.push('/');
|
||||||
} else if (op == UserOperation.Register) {
|
} else if (op == UserOperation.Register) {
|
||||||
|
@ -458,9 +462,11 @@ export class Login extends Component<any, State> {
|
||||||
this.state = this.emptyState;
|
this.state = this.emptyState;
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
UserService.Instance.login(data);
|
UserService.Instance.login(data);
|
||||||
WebSocketService.Instance.client.userJoin({
|
WebSocketService.Instance.send(
|
||||||
auth: UserService.Instance.authField(),
|
wsClient.userJoin({
|
||||||
});
|
auth: authField(),
|
||||||
|
})
|
||||||
|
);
|
||||||
this.props.history.push('/communities');
|
this.props.history.push('/communities');
|
||||||
} else if (op == UserOperation.GetCaptcha) {
|
} else if (op == UserOperation.GetCaptcha) {
|
||||||
let data = wsJsonToRes<GetCaptchaResponse>(msg).data;
|
let data = wsJsonToRes<GetCaptchaResponse>(msg).data;
|
||||||
|
|
|
@ -55,6 +55,9 @@ import {
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
isBrowser,
|
isBrowser,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
setOptionalAuth,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
import { T } from 'inferno-i18next';
|
import { T } from 'inferno-i18next';
|
||||||
|
@ -133,9 +136,11 @@ export class Main extends Component<any, MainState> {
|
||||||
this.fetchTrendingCommunities();
|
this.fetchTrendingCommunities();
|
||||||
this.fetchData();
|
this.fetchData();
|
||||||
if (UserService.Instance.user) {
|
if (UserService.Instance.user) {
|
||||||
WebSocketService.Instance.client.getFollowedCommunities({
|
WebSocketService.Instance.send(
|
||||||
auth: UserService.Instance.authField(),
|
wsClient.getFollowedCommunities({
|
||||||
});
|
auth: authField(),
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,9 +151,11 @@ export class Main extends Component<any, MainState> {
|
||||||
let listCommunitiesForm: ListCommunities = {
|
let listCommunitiesForm: ListCommunities = {
|
||||||
sort: SortType.Hot,
|
sort: SortType.Hot,
|
||||||
limit: 6,
|
limit: 6,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.listCommunities(listCommunitiesForm);
|
WebSocketService.Instance.send(
|
||||||
|
wsClient.listCommunities(listCommunitiesForm)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
@ -157,7 +164,7 @@ export class Main extends Component<any, MainState> {
|
||||||
this.context.router.history.push('/setup');
|
this.context.router.history.push('/setup');
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocketService.Instance.client.communityJoin({ community_id: 0 });
|
WebSocketService.Instance.send(wsClient.communityJoin({ community_id: 0 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
@ -206,8 +213,8 @@ export class Main extends Component<any, MainState> {
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
sort,
|
sort,
|
||||||
type_,
|
type_,
|
||||||
auth: req.auth,
|
|
||||||
};
|
};
|
||||||
|
setOptionalAuth(getPostsForm, req.auth);
|
||||||
promises.push(req.client.getPosts(getPostsForm));
|
promises.push(req.client.getPosts(getPostsForm));
|
||||||
} else {
|
} else {
|
||||||
let getCommentsForm: GetComments = {
|
let getCommentsForm: GetComments = {
|
||||||
|
@ -215,8 +222,8 @@ export class Main extends Component<any, MainState> {
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
sort,
|
sort,
|
||||||
type_,
|
type_,
|
||||||
auth: req.auth,
|
|
||||||
};
|
};
|
||||||
|
setOptionalAuth(getCommentsForm, req.auth);
|
||||||
promises.push(req.client.getComments(getCommentsForm));
|
promises.push(req.client.getComments(getCommentsForm));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -661,18 +668,18 @@ export class Main extends Component<any, MainState> {
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
sort: this.state.sort,
|
sort: this.state.sort,
|
||||||
type_: this.state.listingType,
|
type_: this.state.listingType,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.getPosts(getPostsForm);
|
WebSocketService.Instance.send(wsClient.getPosts(getPostsForm));
|
||||||
} else {
|
} else {
|
||||||
let getCommentsForm: GetComments = {
|
let getCommentsForm: GetComments = {
|
||||||
page: this.state.page,
|
page: this.state.page,
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
sort: this.state.sort,
|
sort: this.state.sort,
|
||||||
type_: this.state.listingType,
|
type_: this.state.listingType,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.getComments(getCommentsForm);
|
WebSocketService.Instance.send(wsClient.getComments(getCommentsForm));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -682,7 +689,9 @@ export class Main extends Component<any, MainState> {
|
||||||
toast(i18n.t(msg.error), 'danger');
|
toast(i18n.t(msg.error), 'danger');
|
||||||
return;
|
return;
|
||||||
} else if (msg.reconnect) {
|
} else if (msg.reconnect) {
|
||||||
WebSocketService.Instance.client.communityJoin({ community_id: 0 });
|
WebSocketService.Instance.send(
|
||||||
|
wsClient.communityJoin({ community_id: 0 })
|
||||||
|
);
|
||||||
this.fetchData();
|
this.fetchData();
|
||||||
} else if (op == UserOperation.GetFollowedCommunities) {
|
} else if (op == UserOperation.GetFollowedCommunities) {
|
||||||
let data = wsJsonToRes<GetFollowedCommunitiesResponse>(msg).data;
|
let data = wsJsonToRes<GetFollowedCommunitiesResponse>(msg).data;
|
||||||
|
|
|
@ -25,6 +25,7 @@ import {
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
isBrowser,
|
isBrowser,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { MomentTime } from './moment-time';
|
import { MomentTime } from './moment-time';
|
||||||
import { HtmlTags } from './html-tags';
|
import { HtmlTags } from './html-tags';
|
||||||
|
@ -439,7 +440,7 @@ export class Modlog extends Component<any, ModlogState> {
|
||||||
page: this.state.page,
|
page: this.state.page,
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.getModlog(modlogForm);
|
WebSocketService.Instance.send(wsClient.getModlog(modlogForm));
|
||||||
}
|
}
|
||||||
|
|
||||||
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
||||||
|
|
|
@ -30,6 +30,8 @@ import {
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
supportLemmyUrl,
|
supportLemmyUrl,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
import { PictrsImage } from './pictrs-image';
|
import { PictrsImage } from './pictrs-image';
|
||||||
|
@ -88,9 +90,11 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
||||||
// i18n.changeLanguage('de');
|
// i18n.changeLanguage('de');
|
||||||
} else {
|
} else {
|
||||||
this.requestNotificationPermission();
|
this.requestNotificationPermission();
|
||||||
WebSocketService.Instance.client.userJoin({
|
WebSocketService.Instance.send(
|
||||||
auth: UserService.Instance.authField(),
|
wsClient.userJoin({
|
||||||
});
|
auth: authField(),
|
||||||
|
})
|
||||||
|
);
|
||||||
this.fetchUnreads();
|
this.fetchUnreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +102,9 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
||||||
// A login
|
// A login
|
||||||
if (res !== undefined) {
|
if (res !== undefined) {
|
||||||
this.requestNotificationPermission();
|
this.requestNotificationPermission();
|
||||||
WebSocketService.Instance.client.getSite();
|
WebSocketService.Instance.send(
|
||||||
|
wsClient.getSite({ auth: authField() })
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
this.setState({ isLoggedIn: false });
|
this.setState({ isLoggedIn: false });
|
||||||
}
|
}
|
||||||
|
@ -167,7 +173,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
||||||
|
|
||||||
// TODO class active corresponding to current page
|
// TODO class active corresponding to current page
|
||||||
navbar() {
|
navbar() {
|
||||||
let user = this.props.site_res.my_user;
|
let user = this.props.site_res.my_user || UserService.Instance.user;
|
||||||
return (
|
return (
|
||||||
<nav class="navbar navbar-expand-lg navbar-light shadow-sm p-0 px-3">
|
<nav class="navbar navbar-expand-lg navbar-light shadow-sm p-0 px-3">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -376,9 +382,11 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (msg.reconnect) {
|
} else if (msg.reconnect) {
|
||||||
WebSocketService.Instance.client.userJoin({
|
WebSocketService.Instance.send(
|
||||||
auth: UserService.Instance.authField(),
|
wsClient.userJoin({
|
||||||
});
|
auth: authField(),
|
||||||
|
})
|
||||||
|
);
|
||||||
this.fetchUnreads();
|
this.fetchUnreads();
|
||||||
} else if (op == UserOperation.GetReplies) {
|
} else if (op == UserOperation.GetReplies) {
|
||||||
let data = wsJsonToRes<GetRepliesResponse>(msg).data;
|
let data = wsJsonToRes<GetRepliesResponse>(msg).data;
|
||||||
|
@ -409,6 +417,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
||||||
} else if (op == UserOperation.GetSite) {
|
} else if (op == UserOperation.GetSite) {
|
||||||
// This is only called on a successful login
|
// This is only called on a successful login
|
||||||
let data = wsJsonToRes<GetSiteResponse>(msg).data;
|
let data = wsJsonToRes<GetSiteResponse>(msg).data;
|
||||||
|
console.log(data.my_user);
|
||||||
UserService.Instance.user = data.my_user;
|
UserService.Instance.user = data.my_user;
|
||||||
setTheme(UserService.Instance.user.theme);
|
setTheme(UserService.Instance.user.theme);
|
||||||
i18n.changeLanguage(getLanguage());
|
i18n.changeLanguage(getLanguage());
|
||||||
|
@ -450,7 +459,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
||||||
unread_only: true,
|
unread_only: true,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let userMentionsForm: GetUserMentions = {
|
let userMentionsForm: GetUserMentions = {
|
||||||
|
@ -458,20 +467,24 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
||||||
unread_only: true,
|
unread_only: true,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let privateMessagesForm: GetPrivateMessages = {
|
let privateMessagesForm: GetPrivateMessages = {
|
||||||
unread_only: true,
|
unread_only: true,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.currentLocation !== '/inbox') {
|
if (this.currentLocation !== '/inbox') {
|
||||||
WebSocketService.Instance.client.getReplies(repliesForm);
|
WebSocketService.Instance.send(wsClient.getReplies(repliesForm));
|
||||||
WebSocketService.Instance.client.getUserMentions(userMentionsForm);
|
WebSocketService.Instance.send(
|
||||||
WebSocketService.Instance.client.getPrivateMessages(privateMessagesForm);
|
wsClient.getUserMentions(userMentionsForm)
|
||||||
|
);
|
||||||
|
WebSocketService.Instance.send(
|
||||||
|
wsClient.getPrivateMessages(privateMessagesForm)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import {
|
||||||
isBrowser,
|
isBrowser,
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
import { HtmlTags } from './html-tags';
|
import { HtmlTags } from './html-tags';
|
||||||
|
@ -138,7 +139,9 @@ export class PasswordChange extends Component<any, State> {
|
||||||
i.state.loading = true;
|
i.state.loading = true;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
|
|
||||||
WebSocketService.Instance.client.passwordChange(i.state.passwordChangeForm);
|
WebSocketService.Instance.send(
|
||||||
|
wsClient.passwordChange(i.state.passwordChangeForm)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
parseMessage(msg: any) {
|
parseMessage(msg: any) {
|
||||||
|
|
|
@ -34,6 +34,8 @@ import {
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
isBrowser,
|
isBrowser,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
|
|
||||||
var Choices;
|
var Choices;
|
||||||
|
@ -76,7 +78,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
community_id: null,
|
community_id: null,
|
||||||
name: null,
|
name: null,
|
||||||
nsfw: false,
|
nsfw: false,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
},
|
},
|
||||||
loading: false,
|
loading: false,
|
||||||
imageLoading: false,
|
imageLoading: false,
|
||||||
|
@ -102,7 +104,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
community_id: this.props.post_view.community.id,
|
community_id: this.props.post_view.community.id,
|
||||||
url: this.props.post_view.post.url,
|
url: this.props.post_view.post.url,
|
||||||
nsfw: this.props.post_view.post.nsfw,
|
nsfw: this.props.post_view.post.nsfw,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,9 +379,9 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
...i.state.postForm,
|
...i.state.postForm,
|
||||||
edit_id: i.props.post_view.post.id,
|
edit_id: i.props.post_view.post.id,
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.editPost(form);
|
WebSocketService.Instance.send(wsClient.editPost(form));
|
||||||
} else {
|
} else {
|
||||||
WebSocketService.Instance.client.createPost(i.state.postForm);
|
WebSocketService.Instance.send(wsClient.createPost(i.state.postForm));
|
||||||
}
|
}
|
||||||
i.state.loading = true;
|
i.state.loading = true;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
|
@ -408,10 +410,10 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
sort: SortType.TopAll,
|
sort: SortType.TopAll,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: 6,
|
limit: 6,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
WebSocketService.Instance.client.search(form);
|
WebSocketService.Instance.send(wsClient.search(form));
|
||||||
|
|
||||||
// Fetch the page title
|
// Fetch the page title
|
||||||
getPageTitle(this.state.postForm.url).then(d => {
|
getPageTitle(this.state.postForm.url).then(d => {
|
||||||
|
@ -438,11 +440,11 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
community_id: this.state.postForm.community_id,
|
community_id: this.state.postForm.community_id,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: 6,
|
limit: 6,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.state.postForm.name !== '') {
|
if (this.state.postForm.name !== '') {
|
||||||
WebSocketService.Instance.client.search(form);
|
WebSocketService.Instance.send(wsClient.search(form));
|
||||||
} else {
|
} else {
|
||||||
this.state.suggestedPosts = [];
|
this.state.suggestedPosts = [];
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ import {
|
||||||
setupTippy,
|
setupTippy,
|
||||||
hostname,
|
hostname,
|
||||||
previewLines,
|
previewLines,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
import { externalHost } from '../env';
|
import { externalHost } from '../env';
|
||||||
|
@ -1175,10 +1177,10 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
let form: CreatePostLike = {
|
let form: CreatePostLike = {
|
||||||
post_id: i.props.post_view.post.id,
|
post_id: i.props.post_view.post.id,
|
||||||
score: i.state.my_vote,
|
score: i.state.my_vote,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
|
|
||||||
WebSocketService.Instance.client.likePost(form);
|
WebSocketService.Instance.send(wsClient.likePost(form));
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
setupTippy();
|
setupTippy();
|
||||||
}
|
}
|
||||||
|
@ -1207,10 +1209,10 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
let form: CreatePostLike = {
|
let form: CreatePostLike = {
|
||||||
post_id: i.props.post_view.post.id,
|
post_id: i.props.post_view.post.id,
|
||||||
score: i.state.my_vote,
|
score: i.state.my_vote,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
|
|
||||||
WebSocketService.Instance.client.likePost(form);
|
WebSocketService.Instance.send(wsClient.likePost(form));
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
setupTippy();
|
setupTippy();
|
||||||
}
|
}
|
||||||
|
@ -1235,9 +1237,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
let deleteForm: DeletePost = {
|
let deleteForm: DeletePost = {
|
||||||
edit_id: i.props.post_view.post.id,
|
edit_id: i.props.post_view.post.id,
|
||||||
deleted: !i.props.post_view.post.deleted,
|
deleted: !i.props.post_view.post.deleted,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.deletePost(deleteForm);
|
WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSavePostClick(i: PostListing) {
|
handleSavePostClick(i: PostListing) {
|
||||||
|
@ -1246,10 +1248,10 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
let form: SavePost = {
|
let form: SavePost = {
|
||||||
post_id: i.props.post_view.post.id,
|
post_id: i.props.post_view.post.id,
|
||||||
save: saved,
|
save: saved,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
|
|
||||||
WebSocketService.Instance.client.savePost(form);
|
WebSocketService.Instance.send(wsClient.savePost(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
get crossPostParams(): string {
|
get crossPostParams(): string {
|
||||||
|
@ -1286,9 +1288,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
edit_id: i.props.post_view.post.id,
|
edit_id: i.props.post_view.post.id,
|
||||||
removed: !i.props.post_view.post.removed,
|
removed: !i.props.post_view.post.removed,
|
||||||
reason: i.state.removeReason,
|
reason: i.state.removeReason,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.removePost(form);
|
WebSocketService.Instance.send(wsClient.removePost(form));
|
||||||
|
|
||||||
i.state.showRemoveDialog = false;
|
i.state.showRemoveDialog = false;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
|
@ -1298,18 +1300,18 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
let form: LockPost = {
|
let form: LockPost = {
|
||||||
edit_id: i.props.post_view.post.id,
|
edit_id: i.props.post_view.post.id,
|
||||||
locked: !i.props.post_view.post.locked,
|
locked: !i.props.post_view.post.locked,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.lockPost(form);
|
WebSocketService.Instance.send(wsClient.lockPost(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleModSticky(i: PostListing) {
|
handleModSticky(i: PostListing) {
|
||||||
let form: StickyPost = {
|
let form: StickyPost = {
|
||||||
edit_id: i.props.post_view.post.id,
|
edit_id: i.props.post_view.post.id,
|
||||||
stickied: !i.props.post_view.post.stickied,
|
stickied: !i.props.post_view.post.stickied,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.stickyPost(form);
|
WebSocketService.Instance.send(wsClient.stickyPost(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleModBanFromCommunityShow(i: PostListing) {
|
handleModBanFromCommunityShow(i: PostListing) {
|
||||||
|
@ -1362,9 +1364,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
remove_data: i.state.removeData,
|
remove_data: i.state.removeData,
|
||||||
reason: i.state.banReason,
|
reason: i.state.banReason,
|
||||||
expires: getUnixTime(i.state.banExpires),
|
expires: getUnixTime(i.state.banExpires),
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.banFromCommunity(form);
|
WebSocketService.Instance.send(wsClient.banFromCommunity(form));
|
||||||
} else {
|
} else {
|
||||||
// If its an unban, restore all their data
|
// If its an unban, restore all their data
|
||||||
let ban = !i.props.post_view.creator.banned;
|
let ban = !i.props.post_view.creator.banned;
|
||||||
|
@ -1377,9 +1379,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
remove_data: i.state.removeData,
|
remove_data: i.state.removeData,
|
||||||
reason: i.state.banReason,
|
reason: i.state.banReason,
|
||||||
expires: getUnixTime(i.state.banExpires),
|
expires: getUnixTime(i.state.banExpires),
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.banUser(form);
|
WebSocketService.Instance.send(wsClient.banUser(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
i.state.showBanDialog = false;
|
i.state.showBanDialog = false;
|
||||||
|
@ -1391,9 +1393,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
user_id: i.props.post_view.creator.id,
|
user_id: i.props.post_view.creator.id,
|
||||||
community_id: i.props.post_view.community.id,
|
community_id: i.props.post_view.community.id,
|
||||||
added: !i.isMod,
|
added: !i.isMod,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.addModToCommunity(form);
|
WebSocketService.Instance.send(wsClient.addModToCommunity(form));
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1401,9 +1403,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
let form: AddAdmin = {
|
let form: AddAdmin = {
|
||||||
user_id: i.props.post_view.creator.id,
|
user_id: i.props.post_view.creator.id,
|
||||||
added: !i.isAdmin,
|
added: !i.isAdmin,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.addAdmin(form);
|
WebSocketService.Instance.send(wsClient.addAdmin(form));
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1421,9 +1423,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
let form: TransferCommunity = {
|
let form: TransferCommunity = {
|
||||||
community_id: i.props.post_view.community.id,
|
community_id: i.props.post_view.community.id,
|
||||||
user_id: i.props.post_view.creator.id,
|
user_id: i.props.post_view.creator.id,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.transferCommunity(form);
|
WebSocketService.Instance.send(wsClient.transferCommunity(form));
|
||||||
i.state.showConfirmTransferCommunity = false;
|
i.state.showConfirmTransferCommunity = false;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
@ -1441,9 +1443,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
handleTransferSite(i: PostListing) {
|
handleTransferSite(i: PostListing) {
|
||||||
let form: TransferSite = {
|
let form: TransferSite = {
|
||||||
user_id: i.props.post_view.creator.id,
|
user_id: i.props.post_view.creator.id,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.transferSite(form);
|
WebSocketService.Instance.send(wsClient.transferSite(form));
|
||||||
i.state.showConfirmTransferSite = false;
|
i.state.showConfirmTransferSite = false;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,9 @@ import {
|
||||||
previewLines,
|
previewLines,
|
||||||
isImage,
|
isImage,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
|
setOptionalAuth,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { PostListing } from './post-listing';
|
import { PostListing } from './post-listing';
|
||||||
import { Sidebar } from './sidebar';
|
import { Sidebar } from './sidebar';
|
||||||
|
@ -103,16 +106,16 @@ export class Post extends Component<any, PostState> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.fetchPost();
|
this.fetchPost();
|
||||||
WebSocketService.Instance.client.listCategories();
|
WebSocketService.Instance.send(wsClient.listCategories());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchPost() {
|
fetchPost() {
|
||||||
let form: GetPost = {
|
let form: GetPost = {
|
||||||
id: this.state.postId,
|
id: this.state.postId,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.getPost(form);
|
WebSocketService.Instance.send(wsClient.getPost(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
||||||
|
@ -123,8 +126,8 @@ export class Post extends Component<any, PostState> {
|
||||||
|
|
||||||
let postForm: GetPost = {
|
let postForm: GetPost = {
|
||||||
id,
|
id,
|
||||||
auth: req.auth,
|
|
||||||
};
|
};
|
||||||
|
setOptionalAuth(postForm, req.auth);
|
||||||
|
|
||||||
promises.push(req.client.getPost(postForm));
|
promises.push(req.client.getPost(postForm));
|
||||||
promises.push(req.client.listCategories());
|
promises.push(req.client.listCategories());
|
||||||
|
@ -138,7 +141,9 @@ export class Post extends Component<any, PostState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
WebSocketService.Instance.client.postJoin({ post_id: this.state.postId });
|
WebSocketService.Instance.send(
|
||||||
|
wsClient.postJoin({ post_id: this.state.postId })
|
||||||
|
);
|
||||||
autosize(document.querySelectorAll('textarea'));
|
autosize(document.querySelectorAll('textarea'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,9 +196,9 @@ export class Post extends Component<any, PostState> {
|
||||||
let form: MarkCommentAsRead = {
|
let form: MarkCommentAsRead = {
|
||||||
comment_id: found.creator.id,
|
comment_id: found.creator.id,
|
||||||
read: true,
|
read: true,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.markCommentAsRead(form);
|
WebSocketService.Instance.send(wsClient.markCommentAsRead(form));
|
||||||
UserService.Instance.unreadCountSub.next(
|
UserService.Instance.unreadCountSub.next(
|
||||||
UserService.Instance.unreadCountSub.value - 1
|
UserService.Instance.unreadCountSub.value - 1
|
||||||
);
|
);
|
||||||
|
@ -218,7 +223,7 @@ export class Post extends Component<any, PostState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let pv = this.state.postRes.post_view;
|
let pv = this.state.postRes?.post_view;
|
||||||
return (
|
return (
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{this.state.loading ? (
|
{this.state.loading ? (
|
||||||
|
@ -444,11 +449,13 @@ export class Post extends Component<any, PostState> {
|
||||||
return;
|
return;
|
||||||
} else if (msg.reconnect) {
|
} else if (msg.reconnect) {
|
||||||
let postId = Number(this.props.match.params.id);
|
let postId = Number(this.props.match.params.id);
|
||||||
WebSocketService.Instance.client.postJoin({ post_id: postId });
|
WebSocketService.Instance.send(wsClient.postJoin({ post_id: postId }));
|
||||||
WebSocketService.Instance.client.getPost({
|
WebSocketService.Instance.send(
|
||||||
id: postId,
|
wsClient.getPost({
|
||||||
auth: UserService.Instance.authField(false),
|
id: postId,
|
||||||
});
|
auth: authField(false),
|
||||||
|
})
|
||||||
|
);
|
||||||
} else if (op == UserOperation.GetPost) {
|
} else if (op == UserOperation.GetPost) {
|
||||||
let data = wsJsonToRes<GetPostResponse>(msg).data;
|
let data = wsJsonToRes<GetPostResponse>(msg).data;
|
||||||
this.state.postRes = data;
|
this.state.postRes = data;
|
||||||
|
@ -462,9 +469,9 @@ export class Post extends Component<any, PostState> {
|
||||||
sort: SortType.TopAll,
|
sort: SortType.TopAll,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: 6,
|
limit: 6,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.search(form);
|
WebSocketService.Instance.send(wsClient.search(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
UserSafe,
|
UserSafe,
|
||||||
UserOperation,
|
UserOperation,
|
||||||
} from 'lemmy-js-client';
|
} from 'lemmy-js-client';
|
||||||
import { UserService, WebSocketService } from '../services';
|
import { WebSocketService } from '../services';
|
||||||
import {
|
import {
|
||||||
capitalizeFirstLetter,
|
capitalizeFirstLetter,
|
||||||
wsJsonToRes,
|
wsJsonToRes,
|
||||||
|
@ -18,6 +18,8 @@ import {
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
isBrowser,
|
isBrowser,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { UserListing } from './user-listing';
|
import { UserListing } from './user-listing';
|
||||||
import { MarkdownTextArea } from './markdown-textarea';
|
import { MarkdownTextArea } from './markdown-textarea';
|
||||||
|
@ -48,7 +50,7 @@ export class PrivateMessageForm extends Component<
|
||||||
privateMessageForm: {
|
privateMessageForm: {
|
||||||
content: null,
|
content: null,
|
||||||
recipient_id: this.props.recipient.id,
|
recipient_id: this.props.recipient.id,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
},
|
},
|
||||||
loading: false,
|
loading: false,
|
||||||
previewMode: false,
|
previewMode: false,
|
||||||
|
@ -191,12 +193,12 @@ export class PrivateMessageForm extends Component<
|
||||||
let form: EditPrivateMessage = {
|
let form: EditPrivateMessage = {
|
||||||
edit_id: i.props.privateMessage.private_message.id,
|
edit_id: i.props.privateMessage.private_message.id,
|
||||||
content: i.state.privateMessageForm.content,
|
content: i.state.privateMessageForm.content,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.editPrivateMessage(form);
|
WebSocketService.Instance.send(wsClient.editPrivateMessage(form));
|
||||||
} else {
|
} else {
|
||||||
WebSocketService.Instance.client.createPrivateMessage(
|
WebSocketService.Instance.send(
|
||||||
i.state.privateMessageForm
|
wsClient.createPrivateMessage(i.state.privateMessageForm)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
i.state.loading = true;
|
i.state.loading = true;
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
UserSafe,
|
UserSafe,
|
||||||
} from 'lemmy-js-client';
|
} from 'lemmy-js-client';
|
||||||
import { WebSocketService, UserService } from '../services';
|
import { WebSocketService, UserService } from '../services';
|
||||||
import { mdToHtml, toast } from '../utils';
|
import { authField, mdToHtml, toast, wsClient } from '../utils';
|
||||||
import { MomentTime } from './moment-time';
|
import { MomentTime } from './moment-time';
|
||||||
import { PrivateMessageForm } from './private-message-form';
|
import { PrivateMessageForm } from './private-message-form';
|
||||||
import { UserListing } from './user-listing';
|
import { UserListing } from './user-listing';
|
||||||
|
@ -231,9 +231,9 @@ export class PrivateMessage extends Component<
|
||||||
let form: DeletePrivateMessage = {
|
let form: DeletePrivateMessage = {
|
||||||
edit_id: i.props.private_message_view.private_message.id,
|
edit_id: i.props.private_message_view.private_message.id,
|
||||||
deleted: !i.props.private_message_view.private_message.deleted,
|
deleted: !i.props.private_message_view.private_message.deleted,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.deletePrivateMessage(form);
|
WebSocketService.Instance.send(wsClient.deletePrivateMessage(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleReplyCancel() {
|
handleReplyCancel() {
|
||||||
|
@ -246,9 +246,9 @@ export class PrivateMessage extends Component<
|
||||||
let form: MarkPrivateMessageAsRead = {
|
let form: MarkPrivateMessageAsRead = {
|
||||||
edit_id: i.props.private_message_view.private_message.id,
|
edit_id: i.props.private_message_view.private_message.id,
|
||||||
read: !i.props.private_message_view.private_message.read,
|
read: !i.props.private_message_view.private_message.read,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.markPrivateMessageAsRead(form);
|
WebSocketService.Instance.send(wsClient.markPrivateMessageAsRead(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMessageCollapse(i: PrivateMessage) {
|
handleMessageCollapse(i: PrivateMessage) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {
|
||||||
CommentResponse,
|
CommentResponse,
|
||||||
Site,
|
Site,
|
||||||
} from 'lemmy-js-client';
|
} from 'lemmy-js-client';
|
||||||
import { UserService, WebSocketService } from '../services';
|
import { WebSocketService } from '../services';
|
||||||
import {
|
import {
|
||||||
wsJsonToRes,
|
wsJsonToRes,
|
||||||
fetchLimit,
|
fetchLimit,
|
||||||
|
@ -27,6 +27,9 @@ import {
|
||||||
setIsoData,
|
setIsoData,
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
|
setOptionalAuth,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { PostListing } from './post-listing';
|
import { PostListing } from './post-listing';
|
||||||
import { HtmlTags } from './html-tags';
|
import { HtmlTags } from './html-tags';
|
||||||
|
@ -141,8 +144,8 @@ export class Search extends Component<any, SearchState> {
|
||||||
sort: this.getSortTypeFromProps(pathSplit[7]),
|
sort: this.getSortTypeFromProps(pathSplit[7]),
|
||||||
page: this.getPageFromProps(pathSplit[9]),
|
page: this.getPageFromProps(pathSplit[9]),
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
auth: req.auth,
|
|
||||||
};
|
};
|
||||||
|
setOptionalAuth(form, req.auth);
|
||||||
|
|
||||||
if (form.q != '') {
|
if (form.q != '') {
|
||||||
promises.push(req.client.search(form));
|
promises.push(req.client.search(form));
|
||||||
|
@ -456,11 +459,11 @@ export class Search extends Component<any, SearchState> {
|
||||||
sort: this.state.sort,
|
sort: this.state.sort,
|
||||||
page: this.state.page,
|
page: this.state.page,
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.state.q != '') {
|
if (this.state.q != '') {
|
||||||
WebSocketService.Instance.client.search(form);
|
WebSocketService.Instance.send(wsClient.search(form));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { Subscription } from 'rxjs';
|
||||||
import { retryWhen, delay, take } from 'rxjs/operators';
|
import { retryWhen, delay, take } from 'rxjs/operators';
|
||||||
import { Register, LoginResponse, UserOperation } from 'lemmy-js-client';
|
import { Register, LoginResponse, UserOperation } from 'lemmy-js-client';
|
||||||
import { WebSocketService, UserService } from '../services';
|
import { WebSocketService, UserService } from '../services';
|
||||||
import { wsUserOp, wsJsonToRes, toast } from '../utils';
|
import { wsUserOp, wsJsonToRes, toast, wsClient } from '../utils';
|
||||||
import { SiteForm } from './site-form';
|
import { SiteForm } from './site-form';
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ export class Setup extends Component<any, State> {
|
||||||
i.state.userLoading = true;
|
i.state.userLoading = true;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
WebSocketService.Instance.client.register(i.state.userForm);
|
WebSocketService.Instance.send(wsClient.register(i.state.userForm));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRegisterUsernameChange(i: Setup, event: any) {
|
handleRegisterUsernameChange(i: Setup, event: any) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
Category,
|
Category,
|
||||||
} from 'lemmy-js-client';
|
} from 'lemmy-js-client';
|
||||||
import { WebSocketService, UserService } from '../services';
|
import { WebSocketService, UserService } from '../services';
|
||||||
import { mdToHtml, getUnixTime } from '../utils';
|
import { mdToHtml, getUnixTime, wsClient, authField } from '../utils';
|
||||||
import { CommunityForm } from './community-form';
|
import { CommunityForm } from './community-form';
|
||||||
import { UserListing } from './user-listing';
|
import { UserListing } from './user-listing';
|
||||||
import { CommunityLink } from './community-link';
|
import { CommunityLink } from './community-link';
|
||||||
|
@ -394,9 +394,9 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
|
||||||
let deleteForm: DeleteCommunity = {
|
let deleteForm: DeleteCommunity = {
|
||||||
edit_id: i.props.community_view.community.id,
|
edit_id: i.props.community_view.community.id,
|
||||||
deleted: !i.props.community_view.community.deleted,
|
deleted: !i.props.community_view.community.deleted,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.deleteCommunity(deleteForm);
|
WebSocketService.Instance.send(wsClient.deleteCommunity(deleteForm));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleShowConfirmLeaveModTeamClick(i: Sidebar) {
|
handleShowConfirmLeaveModTeamClick(i: Sidebar) {
|
||||||
|
@ -409,9 +409,9 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
|
||||||
user_id: UserService.Instance.user.id,
|
user_id: UserService.Instance.user.id,
|
||||||
community_id: i.props.community_view.community.id,
|
community_id: i.props.community_view.community.id,
|
||||||
added: false,
|
added: false,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.addModToCommunity(form);
|
WebSocketService.Instance.send(wsClient.addModToCommunity(form));
|
||||||
i.state.showConfirmLeaveModTeam = false;
|
i.state.showConfirmLeaveModTeam = false;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
@ -426,9 +426,9 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
|
||||||
let form: FollowCommunity = {
|
let form: FollowCommunity = {
|
||||||
community_id: communityId,
|
community_id: communityId,
|
||||||
follow: false,
|
follow: false,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.followCommunity(form);
|
WebSocketService.Instance.send(wsClient.followCommunity(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubscribe(communityId: number, event: any) {
|
handleSubscribe(communityId: number, event: any) {
|
||||||
|
@ -436,9 +436,9 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
|
||||||
let form: FollowCommunity = {
|
let form: FollowCommunity = {
|
||||||
community_id: communityId,
|
community_id: communityId,
|
||||||
follow: true,
|
follow: true,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.followCommunity(form);
|
WebSocketService.Instance.send(wsClient.followCommunity(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
private get amCreator(): boolean {
|
private get amCreator(): boolean {
|
||||||
|
@ -486,9 +486,9 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
|
||||||
removed: !i.props.community_view.community.removed,
|
removed: !i.props.community_view.community.removed,
|
||||||
reason: i.state.removeReason,
|
reason: i.state.removeReason,
|
||||||
expires: getUnixTime(i.state.removeExpires),
|
expires: getUnixTime(i.state.removeExpires),
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.removeCommunity(removeForm);
|
WebSocketService.Instance.send(wsClient.removeCommunity(removeForm));
|
||||||
|
|
||||||
i.state.showRemoveDialog = false;
|
i.state.showRemoveDialog = false;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
|
|
|
@ -3,8 +3,13 @@ import { Prompt } from 'inferno-router';
|
||||||
import { MarkdownTextArea } from './markdown-textarea';
|
import { MarkdownTextArea } from './markdown-textarea';
|
||||||
import { ImageUploadForm } from './image-upload-form';
|
import { ImageUploadForm } from './image-upload-form';
|
||||||
import { Site, EditSite } from 'lemmy-js-client';
|
import { Site, EditSite } from 'lemmy-js-client';
|
||||||
import { UserService, WebSocketService } from '../services';
|
import { WebSocketService } from '../services';
|
||||||
import { capitalizeFirstLetter, randomStr } from '../utils';
|
import {
|
||||||
|
authField,
|
||||||
|
capitalizeFirstLetter,
|
||||||
|
randomStr,
|
||||||
|
wsClient,
|
||||||
|
} from '../utils';
|
||||||
import { i18n } from '../i18next';
|
import { i18n } from '../i18next';
|
||||||
|
|
||||||
interface SiteFormProps {
|
interface SiteFormProps {
|
||||||
|
@ -27,7 +32,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
|
||||||
name: null,
|
name: null,
|
||||||
icon: null,
|
icon: null,
|
||||||
banner: null,
|
banner: null,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
},
|
},
|
||||||
loading: false,
|
loading: false,
|
||||||
};
|
};
|
||||||
|
@ -55,7 +60,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
|
||||||
enable_nsfw: this.props.site.enable_nsfw,
|
enable_nsfw: this.props.site.enable_nsfw,
|
||||||
icon: this.props.site.icon,
|
icon: this.props.site.icon,
|
||||||
banner: this.props.site.banner,
|
banner: this.props.site.banner,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,9 +249,9 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
i.state.loading = true;
|
i.state.loading = true;
|
||||||
if (i.props.site) {
|
if (i.props.site) {
|
||||||
WebSocketService.Instance.client.editSite(i.state.siteForm);
|
WebSocketService.Instance.send(wsClient.editSite(i.state.siteForm));
|
||||||
} else {
|
} else {
|
||||||
WebSocketService.Instance.client.createSite(i.state.siteForm);
|
WebSocketService.Instance.send(wsClient.createSite(i.state.siteForm));
|
||||||
}
|
}
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,9 @@ import {
|
||||||
previewLines,
|
previewLines,
|
||||||
editPostFindRes,
|
editPostFindRes,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
wsClient,
|
||||||
|
authField,
|
||||||
|
setOptionalAuth,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { UserListing } from './user-listing';
|
import { UserListing } from './user-listing';
|
||||||
import { HtmlTags } from './html-tags';
|
import { HtmlTags } from './html-tags';
|
||||||
|
@ -107,14 +110,14 @@ export class User extends Component<any, UserState> {
|
||||||
send_notifications_to_email: null,
|
send_notifications_to_email: null,
|
||||||
bio: null,
|
bio: null,
|
||||||
preferred_username: null,
|
preferred_username: null,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
},
|
},
|
||||||
userSettingsLoading: null,
|
userSettingsLoading: null,
|
||||||
deleteAccountLoading: null,
|
deleteAccountLoading: null,
|
||||||
deleteAccountShowConfirm: false,
|
deleteAccountShowConfirm: false,
|
||||||
deleteAccountForm: {
|
deleteAccountForm: {
|
||||||
password: null,
|
password: null,
|
||||||
auth: UserService.Instance.authField(),
|
auth: authField(),
|
||||||
},
|
},
|
||||||
siteRes: this.isoData.site_res,
|
siteRes: this.isoData.site_res,
|
||||||
};
|
};
|
||||||
|
@ -164,9 +167,9 @@ export class User extends Component<any, UserState> {
|
||||||
saved_only: this.state.view === UserDetailsView.Saved,
|
saved_only: this.state.view === UserDetailsView.Saved,
|
||||||
page: this.state.page,
|
page: this.state.page,
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.client.getUserDetails(form);
|
WebSocketService.Instance.send(wsClient.getUserDetails(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
get isCurrentUser() {
|
get isCurrentUser() {
|
||||||
|
@ -211,8 +214,8 @@ export class User extends Component<any, UserState> {
|
||||||
saved_only: view === UserDetailsView.Saved,
|
saved_only: view === UserDetailsView.Saved,
|
||||||
page,
|
page,
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
auth: req.auth,
|
|
||||||
};
|
};
|
||||||
|
setOptionalAuth(form, req.auth);
|
||||||
this.setIdOrName(form, user_id, username);
|
this.setIdOrName(form, user_id, username);
|
||||||
promises.push(req.client.getUserDetails(form));
|
promises.push(req.client.getUserDetails(form));
|
||||||
return promises;
|
return promises;
|
||||||
|
@ -1018,7 +1021,9 @@ export class User extends Component<any, UserState> {
|
||||||
i.state.userSettingsLoading = true;
|
i.state.userSettingsLoading = true;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
|
|
||||||
WebSocketService.Instance.client.saveUserSettings(i.state.userSettingsForm);
|
WebSocketService.Instance.send(
|
||||||
|
wsClient.saveUserSettings(i.state.userSettingsForm)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDeleteAccountShowConfirmToggle(i: User, event: any) {
|
handleDeleteAccountShowConfirmToggle(i: User, event: any) {
|
||||||
|
@ -1042,7 +1047,9 @@ export class User extends Component<any, UserState> {
|
||||||
i.state.deleteAccountLoading = true;
|
i.state.deleteAccountLoading = true;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
|
|
||||||
WebSocketService.Instance.client.deleteAccount(i.state.deleteAccountForm);
|
WebSocketService.Instance.send(
|
||||||
|
wsClient.deleteAccount(i.state.deleteAccountForm)
|
||||||
|
);
|
||||||
i.handleLogoutClick(i);
|
i.handleLogoutClick(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ const secure = isBrowser()
|
||||||
const host = isBrowser() ? externalHost : internalHost;
|
const host = isBrowser() ? externalHost : internalHost;
|
||||||
|
|
||||||
const httpBase = `http://${host}`; // Don't use secure here
|
const httpBase = `http://${host}`; // Don't use secure here
|
||||||
export const wsUri = `ws${secure}://${host}/api/v1/ws`;
|
export const wsUri = `ws${secure}://${host}/api/v2/ws`;
|
||||||
export const httpUri = `${httpBase}/api/v1`;
|
export const httpUri = `${httpBase}/api/v2`;
|
||||||
export const pictrsUri = `http${secure}://${host}/pictrs/image`;
|
export const pictrsUri = `http${secure}://${host}/pictrs/image`;
|
||||||
|
|
||||||
console.log(`httpbase: ${httpBase}`);
|
console.log(`httpbase: ${httpBase}`);
|
||||||
|
|
|
@ -3,8 +3,6 @@ import IsomorphicCookie from 'isomorphic-cookie';
|
||||||
import { User_, LoginResponse } from 'lemmy-js-client';
|
import { User_, LoginResponse } from 'lemmy-js-client';
|
||||||
import jwt_decode from 'jwt-decode';
|
import jwt_decode from 'jwt-decode';
|
||||||
import { Subject, BehaviorSubject } from 'rxjs';
|
import { Subject, BehaviorSubject } from 'rxjs';
|
||||||
import { i18n } from '../i18next';
|
|
||||||
import { toast } from '../utils';
|
|
||||||
|
|
||||||
interface Claims {
|
interface Claims {
|
||||||
id: number;
|
id: number;
|
||||||
|
@ -50,15 +48,6 @@ export class UserService {
|
||||||
return IsomorphicCookie.load('jwt');
|
return IsomorphicCookie.load('jwt');
|
||||||
}
|
}
|
||||||
|
|
||||||
public authField(throwErr: boolean = true): string {
|
|
||||||
if (this.auth == null && throwErr) {
|
|
||||||
toast(i18n.t('not_logged_in'), 'danger');
|
|
||||||
throw 'Not logged in';
|
|
||||||
} else {
|
|
||||||
return this.auth;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private setClaims(jwt: string) {
|
private setClaims(jwt: string) {
|
||||||
this.claims = jwt_decode(jwt);
|
this.claims = jwt_decode(jwt);
|
||||||
this.jwtSub.next(jwt);
|
this.jwtSub.next(jwt);
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
import { wsUri } from '../env';
|
import { wsUri } from '../env';
|
||||||
import {
|
import { UserViewSafe, WebSocketJsonResponse } from 'lemmy-js-client';
|
||||||
LemmyWebsocket,
|
|
||||||
UserViewSafe,
|
|
||||||
WebSocketJsonResponse,
|
|
||||||
} from 'lemmy-js-client';
|
|
||||||
import { isBrowser } from '../utils';
|
import { isBrowser } from '../utils';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { share } from 'rxjs/operators';
|
import { share } from 'rxjs/operators';
|
||||||
|
@ -14,7 +10,7 @@ import {
|
||||||
|
|
||||||
export class WebSocketService {
|
export class WebSocketService {
|
||||||
private static _instance: WebSocketService;
|
private static _instance: WebSocketService;
|
||||||
public ws: ReconnectingWebSocket;
|
private ws: ReconnectingWebSocket;
|
||||||
public wsOptions: WSOptions = {
|
public wsOptions: WSOptions = {
|
||||||
connectionTimeout: 5000,
|
connectionTimeout: 5000,
|
||||||
maxRetries: 10,
|
maxRetries: 10,
|
||||||
|
@ -23,7 +19,6 @@ export class WebSocketService {
|
||||||
|
|
||||||
public admins: UserViewSafe[];
|
public admins: UserViewSafe[];
|
||||||
public banned: UserViewSafe[];
|
public banned: UserViewSafe[];
|
||||||
public client = new LemmyWebsocket();
|
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
this.ws = new ReconnectingWebSocket(wsUri, [], this.wsOptions);
|
this.ws = new ReconnectingWebSocket(wsUri, [], this.wsOptions);
|
||||||
|
@ -46,15 +41,19 @@ export class WebSocketService {
|
||||||
firstConnect = false;
|
firstConnect = false;
|
||||||
};
|
};
|
||||||
}).pipe(share());
|
}).pipe(share());
|
||||||
|
|
||||||
|
if (isBrowser()) {
|
||||||
|
window.onbeforeunload = () => {
|
||||||
|
this.ws.close();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public send(data: string) {
|
||||||
|
this.ws.send(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static get Instance() {
|
public static get Instance() {
|
||||||
return this._instance || (this._instance = new this());
|
return this._instance || (this._instance = new this());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isBrowser()) {
|
|
||||||
window.onbeforeunload = () => {
|
|
||||||
WebSocketService.Instance.ws.close();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ import {
|
||||||
SearchResponse,
|
SearchResponse,
|
||||||
PostView,
|
PostView,
|
||||||
PrivateMessageView,
|
PrivateMessageView,
|
||||||
|
LemmyWebsocket,
|
||||||
} from 'lemmy-js-client';
|
} from 'lemmy-js-client';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -66,6 +67,9 @@ import tippy from 'tippy.js';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
import { retryWhen, delay, take } from 'rxjs/operators';
|
import { retryWhen, delay, take } from 'rxjs/operators';
|
||||||
|
import { i18n } from './i18next';
|
||||||
|
|
||||||
|
export const wsClient = new LemmyWebsocket();
|
||||||
|
|
||||||
export const favIconUrl = '/static/assets/favicon.svg';
|
export const favIconUrl = '/static/assets/favicon.svg';
|
||||||
export const favIconPngUrl = '/static/assets/apple-touch-icon.png';
|
export const favIconPngUrl = '/static/assets/apple-touch-icon.png';
|
||||||
|
@ -719,10 +723,10 @@ function userSearch(text: string, cb: any) {
|
||||||
sort: SortType.TopAll,
|
sort: SortType.TopAll,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: mentionDropdownFetchLimit,
|
limit: mentionDropdownFetchLimit,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
WebSocketService.Instance.client.search(form);
|
WebSocketService.Instance.send(wsClient.search(form));
|
||||||
|
|
||||||
let userSub = WebSocketService.Instance.subject.subscribe(
|
let userSub = WebSocketService.Instance.subject.subscribe(
|
||||||
msg => {
|
msg => {
|
||||||
|
@ -757,10 +761,10 @@ function communitySearch(text: string, cb: any) {
|
||||||
sort: SortType.TopAll,
|
sort: SortType.TopAll,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: mentionDropdownFetchLimit,
|
limit: mentionDropdownFetchLimit,
|
||||||
auth: UserService.Instance.authField(false),
|
auth: authField(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
WebSocketService.Instance.client.search(form);
|
WebSocketService.Instance.send(wsClient.search(form));
|
||||||
|
|
||||||
let communitySub = WebSocketService.Instance.subject.subscribe(
|
let communitySub = WebSocketService.Instance.subject.subscribe(
|
||||||
msg => {
|
msg => {
|
||||||
|
@ -1111,6 +1115,24 @@ export function wsSubscribe(parseMessage: any): Subscription {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setOptionalAuth(obj: any, auth = UserService.Instance.auth) {
|
||||||
|
if (auth) {
|
||||||
|
obj.auth = auth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function authField(
|
||||||
|
throwErr: boolean = true,
|
||||||
|
auth = UserService.Instance.auth
|
||||||
|
): string {
|
||||||
|
if (auth == null && throwErr) {
|
||||||
|
toast(i18n.t('not_logged_in'), 'danger');
|
||||||
|
throw 'Not logged in';
|
||||||
|
} else {
|
||||||
|
return auth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
moment.updateLocale('en', {
|
moment.updateLocale('en', {
|
||||||
relativeTime: {
|
relativeTime: {
|
||||||
future: 'in %s',
|
future: 'in %s',
|
||||||
|
|
Loading…
Reference in a new issue