Skip to content

Commit

Permalink
completed async-labs#23
Browse files Browse the repository at this point in the history
  • Loading branch information
tima101 committed May 1, 2019
1 parent 017822c commit 96deabf
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 26 deletions.
2 changes: 0 additions & 2 deletions api/server/api/team-member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ router.post('/posts/edit', async (req, res, next) => {

postEdited({ socketId, post: updatedPost });

// console.log(socketId);

res.json({ done: 1 });
} catch (err) {
next(err);
Expand Down
1 change: 0 additions & 1 deletion app/components/posts/PostForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class PostForm extends React.Component<MyProps, MyState> {

if (discussion.notificationType === 'email') {
const userIdsForLambda = discussion.memberIds.filter(m => m !== discussion.createdUserId);
console.log(discussion.notificationType, userIdsForLambda);
await discussion.sendDataToLambdaApiMethod({
discussionName: discussion.name,
discussionLink: `${URL_APP}/team/${discussion.team.slug}/discussions/${discussion.slug}`,
Expand Down
38 changes: 19 additions & 19 deletions app/lib/store/discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ class Discussion {

const postObj = new Post({ discussion: this, store: this.store, ...data });

if (postObj.createdUserId !== this.store.currentUser._id) {
return;
}

this.posts.push(postObj);

return postObj;
Expand Down Expand Up @@ -210,6 +206,19 @@ class Discussion {
this.team.discussions.remove(discussion);
}

public handleDiscussionRealtimeEvent = data => {
console.log('discussion realtime event', data);
const { action: actionName } = data;

if (actionName === 'added') {
this.addDiscussionToLocalCache(data.discussion);
} else if (actionName === 'edited') {
this.editDiscussionFromLocalCache(data.discussion);
} else if (actionName === 'deleted') {
this.removeDiscussionFromLocalCache(data.id);
}
};

public handlePostRealtimeEvent(data) {
const { action: actionName } = data;

Expand All @@ -224,13 +233,17 @@ class Discussion {

public leaveSocketRoom() {
if (this.store.socket) {
this.store.socket.off('discussionEvent', this.handleDiscussionRealtimeEvent);
console.log('leaving socket discussion room', this.name);
this.store.socket.emit('leaveDiscussion', this._id);
this.store.socket.emit('leaveTeam', this.team._id);
}
}

public joinSocketRoom() {
if (this.store.socket) {
this.store.socket.on('discussionEvent', this.handleDiscussionRealtimeEvent);
console.log('joining socket discussion room', this.name);
this.store.socket.emit('joinDiscussion', this._id);
this.store.socket.emit('joinTeam', this.team._id);
}
}

Expand All @@ -243,19 +256,6 @@ class Discussion {
discussionObjs.filter(d => !d.isDraft || d.createdUserId === this.store.currentUser._id),
);
}

private handleDiscussionRealtimeEvent = data => {
console.log('discussion realtime event', data);
const { action: actionName } = data;

if (actionName === 'added') {
this.addDiscussionToLocalCache(data.discussion);
} else if (actionName === 'edited') {
this.editDiscussionFromLocalCache(data.discussion);
} else if (actionName === 'deleted') {
this.removeDiscussionFromLocalCache(data.id);
}
};
}

decorate(Discussion, {
Expand Down
11 changes: 11 additions & 0 deletions app/pages/discussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DiscussionComp extends React.Component<Props> {
store.currentTeam.loadDiscussions().catch(err => notify(err));
}

this.props.store.socket.on('discussionEvent', this.handleDiscussionEvent);
this.props.store.socket.on('postEvent', this.handlePostEvent);
this.props.store.socket.on('reconnect', this.handleSocketReconnect);

Expand Down Expand Up @@ -73,6 +74,7 @@ class DiscussionComp extends React.Component<Props> {
discussion.leaveSocketRoom();
}

this.props.store.socket.off('discussionEvent', this.handleDiscussionEvent);
this.props.store.socket.off('postEvent', this.handlePostEvent);
this.props.store.socket.off('reconnect', this.handleSocketReconnect);
}
Expand Down Expand Up @@ -293,6 +295,15 @@ class DiscussionComp extends React.Component<Props> {
this.setState({ selectedPost: post, showMarkdownClicked: true });
};

private handleDiscussionEvent = data => {
console.log('discussion realtime event', data);

const discussion = this.getDiscussion(this.props.discussionSlug);
if (discussion) {
discussion.handleDiscussionRealtimeEvent(data);
}
};

private handlePostEvent = data => {
console.log('post realtime event', data);

Expand Down
3 changes: 1 addition & 2 deletions app/pages/team-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import Avatar from '@material-ui/core/Avatar';
import Button from '@material-ui/core/Button';
import Grid from '@material-ui/core/Grid';
import Hidden from '@material-ui/core/Hidden';
import Paper from '@material-ui/core/Paper';
import TextField from '@material-ui/core/TextField';
import NProgress from 'nprogress';
import { observer } from 'mobx-react';
import Head from 'next/head';
import NProgress from 'nprogress';
import * as React from 'react';

import Table from '@material-ui/core/Table';
Expand Down
2 changes: 0 additions & 2 deletions lambda/src/sendEmailForNewPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ async function sendEmailNotification({
.select('email')
.setOptions({ lean: true });

console.log('users', users);

const usersToNotify = users.filter(user => userIds.includes(user._id.toString()));

console.log('usersToNotify', usersToNotify);
Expand Down

0 comments on commit 96deabf

Please sign in to comment.