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