- parseMessage(msg: any) {
- let op = wsUserOp(msg);
- console.log(msg);
- if (msg.error) {
- // Errors handled by top level pages
- // toast(i18n.t(msg.error), "danger");
- this.state.loading = false;
- this.setState(this.state);
- return;
- } else if (op == UserOperation.CreateCommunity) {
- let data = wsJsonToRes<CommunityResponse>(msg).data;
- this.state.loading = false;
- this.props.onCreate(data.community_view);
-
- // Update myUserInfo
- let community = data.community_view.community;
- let person = UserService.Instance.myUserInfo.local_user_view.person;
- UserService.Instance.myUserInfo.follows.push({
- community,
- follower: person,
- });
- UserService.Instance.myUserInfo.moderates.push({
- community,
- moderator: person,
- });
- } else if (op == UserOperation.EditCommunity) {
- let data = wsJsonToRes<CommunityResponse>(msg).data;
- this.state.loading = false;
- this.props.onEdit(data.community_view);
- let community = data.community_view.community;
-
- let followFound = UserService.Instance.myUserInfo.follows.findIndex(
- f => f.community.id == community.id
- );
- if (followFound) {
- UserService.Instance.myUserInfo.follows[followFound].community =
- community;
- }
-
- let moderatesFound = UserService.Instance.myUserInfo.moderates.findIndex(
- f => f.community.id == community.id
- );
- if (moderatesFound) {
- UserService.Instance.myUserInfo.moderates[moderatesFound].community =
- community;
- }
- }