amAdmin,
auth,
donateLemmyUrl,
- getLanguages,
isBrowser,
notifyComment,
notifyPrivateMessage,
numToSI,
- setTheme,
showAvatars,
toast,
wsClient,
auth: auth().unwrap(),
})
);
- this.fetchUnreads();
- }
- this.userSub = UserService.Instance.jwtSub.subscribe(res => {
- // A login
- if (res.isSome()) {
- this.requestNotificationPermission();
- WebSocketService.Instance.send(
- wsClient.getSite({ auth: res.map(r => r.jwt) })
- );
+ if (this.props.siteRes.site_view.isSome()) {
+ this.fetchUnreads();
}
- });
+ }
+
+ this.requestNotificationPermission();
// Subscribe to unread count changes
this.unreadInboxCountSub =
this.state.unreadApplicationCount = data.registration_applications;
this.setState(this.state);
this.sendApplicationUnread();
- } else if (op == UserOperation.GetSite) {
- // This is only called on a successful login
- let data = wsJsonToRes<GetSiteResponse>(msg, GetSiteResponse);
- UserService.Instance.myUserInfo = data.my_user;
- UserService.Instance.myUserInfo.match({
- some: mui => {
- setTheme(mui.local_user_view.local_user.theme);
- i18n.changeLanguage(getLanguages()[0]);
- this.setState(this.state);
- },
- none: void 0,
- });
} else if (op == UserOperation.CreateComment) {
let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
posting_restricted_to_mods: Some(
cv.community.posting_restricted_to_mods
),
- auth: auth().unwrap(),
+ auth: undefined,
});
},
none: void 0,
event.preventDefault();
i.state.loading = true;
let cForm = i.state.communityForm;
+ cForm.auth = auth().unwrap();
i.props.community_view.match({
some: cv => {
banner: cForm.banner,
nsfw: cForm.nsfw,
posting_restricted_to_mods: cForm.posting_restricted_to_mods,
- auth: auth().unwrap(),
+ auth: cForm.auth,
});
WebSocketService.Instance.send(wsClient.editCommunity(form));
listingType: getListingTypeFromProps(
this.props,
ListingType[
- this.isoData.site_res.site_view.unwrap().site.default_post_listing_type
+ this.isoData.site_res.site_view.match({
+ some: type_ => type_.site.default_post_listing_type,
+ none: ListingType.Local,
+ })
]
),
dataType: getDataTypeFromProps(this.props),
componentDidMount() {
// This means it hasn't been set up yet
- if (!this.state.siteRes.site_view) {
+ if (this.state.siteRes.site_view.isNone()) {
this.context.router.history.push("/setup");
}
setupTippy();
import { i18n } from "../../i18next";
import { UserService, WebSocketService } from "../../services";
import {
- auth,
isBrowser,
setIsoData,
toast,
this.state = this.emptyState;
this.setState(this.state);
UserService.Instance.login(data);
- WebSocketService.Instance.send(
- wsClient.userJoin({
- auth: auth().unwrap(),
- })
- );
- toast(i18n.t("logged_in"));
- this.props.history.push("/");
} else if (op == UserOperation.PasswordReset) {
toast(i18n.t("reset_password_mail_sent"));
} else if (op == UserOperation.GetSite) {
honeypot: None,
answer: None,
}),
- doneRegisteringUser: false,
+ doneRegisteringUser: UserService.Instance.myUserInfo.isSome(),
userLoading: false,
};
} else if (op == UserOperation.Register) {
let data = wsJsonToRes<LoginResponse>(msg, LoginResponse);
this.state.userLoading = false;
- this.state.doneRegisteringUser = true;
UserService.Instance.login(data);
this.setState(this.state);
} else if (op == UserOperation.CreateSite) {
import { i18n } from "../../i18next";
import { UserService, WebSocketService } from "../../services";
import {
- auth,
isBrowser,
joinLemmyUrl,
mdToHtml,
this.state = this.emptyState;
this.setState(this.state);
// Only log them in if a jwt was set
- if (data.jwt) {
+ if (data.jwt.isSome()) {
UserService.Instance.login(data);
- WebSocketService.Instance.send(
- wsClient.userJoin({
- auth: auth().unwrap(),
- })
- );
this.props.history.push("/communities");
} else {
if (data.verify_email_sent) {
import IsomorphicCookie from "isomorphic-cookie";
import jwt_decode from "jwt-decode";
import { LoginResponse, MyUserInfo } from "lemmy-js-client";
-import { BehaviorSubject, Subject } from "rxjs";
+import { BehaviorSubject } from "rxjs";
import { isHttps } from "../env";
import { i18n } from "../i18next";
import { isBrowser, toast } from "../utils";
private static _instance: UserService;
public myUserInfo: Option<MyUserInfo> = None;
public jwtInfo: Option<JwtInfo> = None;
- public jwtSub: Subject<Option<JwtInfo>> = new Subject<Option<JwtInfo>>();
public unreadInboxCountSub: BehaviorSubject<number> =
new BehaviorSubject<number>(0);
public unreadReportCountSub: BehaviorSubject<number> =
public login(res: LoginResponse) {
let expires = new Date();
expires.setDate(expires.getDate() + 365);
- IsomorphicCookie.save("jwt", res.jwt, { expires, secure: isHttps });
- console.log("jwt cookie set");
- this.setJwtInfo();
+ res.jwt.match({
+ some: jwt => {
+ toast(i18n.t("logged_in"));
+ IsomorphicCookie.save("jwt", jwt, { expires, secure: isHttps });
+ this.setJwtInfo();
+ location.reload();
+ },
+ none: void 0,
+ });
}
public logout() {
this.jwtInfo = None;
this.myUserInfo = None;
- this.jwtSub.next(this.jwtInfo);
IsomorphicCookie.remove("jwt"); // TODO is sometimes unreliable for some reason
document.cookie = "jwt=; Max-Age=0; path=/; domain=" + location.host;
- location.reload(); // TODO may not be necessary anymore
- console.log("Logged out.");
+ location.reload();
}
public auth(throwErr = true): Result<string, string> {
if (jwt) {
let jwtInfo: JwtInfo = { jwt, claims: jwt_decode(jwt) };
this.jwtInfo = Some(jwtInfo);
- this.jwtSub.next(this.jwtInfo);
}
}
if (routeData[4]) {
routeDataOut[4] = convertWindowJson(cls5, routeData[4]);
}
+ let site_res = convertWindowJson(GetSiteResponse, json.site_res);
let isoData: IsoData = {
path: json.path,
- site_res: convertWindowJson(GetSiteResponse, json.site_res),
+ site_res,
routeData: routeDataOut,
};
return isoData;