Skip to content

Commit

Permalink
Merge pull request #230 from boostcamp-2020/develop
Browse files Browse the repository at this point in the history
Release Reply Reaction
  • Loading branch information
Do-ho authored Dec 18, 2020
2 parents 9b88753 + 3d63698 commit c468196
Show file tree
Hide file tree
Showing 23 changed files with 285 additions and 63 deletions.
5 changes: 3 additions & 2 deletions client/src/common/constants/chat-type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const ChatType = {
DM: 'DM',
Channel: 'Channel'
Message: 'Message',
ReplyTitle: 'ReplyTitle',
Reply: 'Reply'
};

export { ChatType };
6 changes: 6 additions & 0 deletions client/src/common/constants/chatroom-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const ChatroomType = {
DM: 'DM',
Channel: 'Channel'
};

export { ChatroomType };
3 changes: 2 additions & 1 deletion client/src/common/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { DefaultSectionName } from './default-section-name';
import { KeyCode } from './key-code';
import { ScrollEventType } from './scroll-event-type';
import { ChatroomType } from './chatroom-type';
import { ChatType } from './chat-type';
import { HttpStatusCode } from './http-status-code';

export { DefaultSectionName, KeyCode, ScrollEventType, ChatType, HttpStatusCode };
export { DefaultSectionName, KeyCode, ScrollEventType, ChatroomType, ChatType, HttpStatusCode };
14 changes: 13 additions & 1 deletion client/src/common/socket/emits/reaction.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import {
CREATE_MESSAGE_REACTION,
DELETE_MESSAGE_REACTION,
CREATE_REPLY_REACTION,
DELETE_REPLY_REACTION,
createMessageReactionState,
deleteMessageReactionState
deleteMessageReactionState,
createReplyReactionState,
deleteReplyReactionState
} from '@socket/types/reaction-types';
import socket from '../socketIO';

Expand All @@ -13,3 +17,11 @@ export const createMessageReaction = (reaction: createMessageReactionState) => {
export const deleteMessageReaction = (reaction: deleteMessageReactionState) => {
socket.emit(DELETE_MESSAGE_REACTION, reaction);
};

export const createReplyReaction = (reaction: createReplyReactionState) => {
socket.emit(CREATE_REPLY_REACTION, reaction);
};

export const deleteReplyReaction = (reaction: deleteReplyReactionState) => {
socket.emit(DELETE_REPLY_REACTION, reaction);
};
22 changes: 22 additions & 0 deletions client/src/common/socket/types/reaction-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const CREATE_MESSAGE_REACTION = 'create reaction';
export const DELETE_MESSAGE_REACTION = 'delete reaction';
export const CREATE_REPLY_REACTION = 'create reply reaction';
export const DELETE_REPLY_REACTION = 'delete reply reaction';

interface userInfo {
displayName: string;
Expand All @@ -17,6 +19,17 @@ export interface deleteMessageReactionState {
reactionId: number;
}

export interface createReplyReactionState {
replyId: number;
title: string;
emoji: string;
}

export interface deleteReplyReactionState {
replyId: number;
reactionId: number;
}

export interface socketMessageReactionState {
authors: Array<userInfo>;
chatroomId: number;
Expand All @@ -25,3 +38,12 @@ export interface socketMessageReactionState {
reactionId: number;
title: string;
}

export interface socketReplyReactionState {
reactionId: number;
title: string;
emoji: string;
replyId: number;
authors: Array<userInfo>;
messageId: number;
}
12 changes: 11 additions & 1 deletion client/src/common/store/actions/thread-action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { LOAD_THREAD_ASYNC, INSERT_REPLY, LOAD_NEXT_REPLIES_ASYNC, replyState } from '@store/types/thread-types';
import { socketReplyReactionState } from '@socket/types/reaction-types';
import {
LOAD_THREAD_ASYNC,
INSERT_REPLY,
LOAD_NEXT_REPLIES_ASYNC,
ADD_REPLY_REACTION,
DELETE_REPLY_REACTION,
replyState
} from '@store/types/thread-types';

export const loadThread = (messageId: number) => ({ type: LOAD_THREAD_ASYNC, payload: { messageId } });
export const InsertReply = (payload: replyState) => ({ type: INSERT_REPLY, payload });
export const loadNextReplies = (payload: any) => ({ type: LOAD_NEXT_REPLIES_ASYNC, payload });
export const createReplyReaction = (payload: socketReplyReactionState) => ({ type: ADD_REPLY_REACTION, payload });
export const deleteReplyReaction = (payload: socketReplyReactionState) => ({ type: DELETE_REPLY_REACTION, payload });
6 changes: 3 additions & 3 deletions client/src/common/store/reducers/chatroom-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { uriParser } from '@utils/index';
import { joinChatroom, joinDM } from '@socket/emits/chatroom';
import { messageState } from '@store/types/message-types';
import { messageReactionsState } from '@store/types/message-reactions-type';
import { reactionsState } from '@store/types/reactions-type';
import {
chatroomState,
LOAD,
Expand Down Expand Up @@ -155,7 +155,7 @@ const chatroomReducer = (state = initialState, action: ChatroomTypes) => {
addReactionMessages.forEach((message: messageState) => {
if (message.messageId === action.payload.messageId) {
let isExistReaction = false;
message.messageReactions.forEach((reaction: messageReactionsState) => {
message.messageReactions.forEach((reaction: reactionsState) => {
if (reaction.reactionId === action.payload.reactionId) {
reaction.reactionCount += 1;
reaction.reactionDisplayNames = action.payload.authors.reduce((acc: Array<string>, val: any) => {
Expand Down Expand Up @@ -183,7 +183,7 @@ const chatroomReducer = (state = initialState, action: ChatroomTypes) => {
if (state.selectedChatroomId === action.payload.chatroomId) {
deleteReactionMessages.forEach((message: messageState) => {
if (message.messageId === action.payload.messageId) {
message.messageReactions.forEach((reaction: messageReactionsState) => {
message.messageReactions.forEach((reaction: reactionsState) => {
if (reaction.reactionId === action.payload.reactionId) {
reaction.reactionCount -= 1;
reaction.reactionDisplayNames = action.payload.authors.reduce((acc: Array<string>, val: any) => {
Expand Down
7 changes: 4 additions & 3 deletions client/src/common/store/reducers/modal-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import {
EMOJI_PICKER_CLOSE,
EMOJI_PICKER_OPEN
} from '@store/types/modal-types';
import { ChatType } from '@constants/index';

const initialState: ModalState = {
createModal: { isOpen: false },
channelModal: { isOpen: false, x: 0, y: 0 },
userboxModal: { isOpen: false },
profileModal: { isOpen: false, x: 0, y: 0, userId: 0, profileUri: '', displayName: '' },
emojiPicker: { isOpen: false, x: 0, y: 0, messageId: null }
emojiPicker: { isOpen: false, x: 0, y: 0, chatId: null, type: ChatType.Message }
};

const ModalReducer = (state = initialState, action: ModalTypes) => {
Expand All @@ -41,8 +42,8 @@ const ModalReducer = (state = initialState, action: ModalTypes) => {
case PROFILE_MODAL_CLOSE:
return { ...state, profileModal: { isOpen: false } };
case EMOJI_PICKER_OPEN:
const { x, y, messageId } = action.payload;
return { ...state, emojiPicker: { isOpen: true, x, y, messageId } };
const { x, y, chatId, type } = action.payload;
return { ...state, emojiPicker: { isOpen: true, x, y, chatId, type } };
case EMOJI_PICKER_CLOSE:
return { ...state, emojiPicker: { isOpen: false } };
default:
Expand Down
72 changes: 69 additions & 3 deletions client/src/common/store/reducers/thread-reducer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import { LOAD_THREAD, threadState, INSERT_REPLY, ThreadTypes, LOAD_NEXT_REPLIES } from '@store/types/thread-types';
/* eslint-disable no-param-reassign */
import { reactionsState } from '@store/types/reactions-type';
import {
LOAD_THREAD,
threadState,
INSERT_REPLY,
ThreadTypes,
LOAD_NEXT_REPLIES,
ADD_REPLY_REACTION,
DELETE_REPLY_REACTION,
replyState
} from '@store/types/thread-types';
import { uriParser } from '@utils/index';

const initialState: threadState = {
message: {
Expand All @@ -15,7 +27,8 @@ const initialState: threadState = {
chatroom: {},
messageReactions: []
},
replies: []
replies: [],
selectedThreadId: uriParser.getThreadId()
};

export default function threadReducer(state = initialState, action: ThreadTypes) {
Expand All @@ -24,7 +37,8 @@ export default function threadReducer(state = initialState, action: ThreadTypes)
return {
...state,
message: action.payload.message,
replies: action.payload.replies
replies: action.payload.replies,
selectedThreadId: uriParser.getThreadId()
};
case INSERT_REPLY:
const newReplies = state.replies;
Expand All @@ -42,6 +56,58 @@ export default function threadReducer(state = initialState, action: ThreadTypes)
...state,
replies: nextreplies
};
case ADD_REPLY_REACTION: {
const NewReplies = state.replies;
const { messageId, reactionId, replyId } = action.payload;
if (state.selectedThreadId === messageId) {
NewReplies.forEach((reply: replyState) => {
if (reply.replyId === replyId) {
let bExistReaction = false;
reply.replyReactions.forEach((reaction: any) => {
if (reaction.reactionId === reactionId) {
reaction.reactionCount += 1;
reaction.replyDisplayNames = action.payload.authors.reduce((acc: Array<string>, val: any) => {
acc.push(val.displayName);
return acc;
}, []);
bExistReaction = true;
}
});
if (!bExistReaction) {
reply.replyReactions.push({
reactionCount: 1,
emoji: action.payload.emoji,
replyDisplayNames: [action.payload.authors[0].displayName],
reactionId: action.payload.reactionId,
title: action.payload.title
});
}
}
});
}

return { ...state, replies: NewReplies };
}
case DELETE_REPLY_REACTION: {
const NewReplies = state.replies;
const { messageId, reactionId, replyId } = action.payload;
if (state.selectedThreadId === messageId) {
NewReplies.forEach((reply: replyState) => {
if (reply.replyId === replyId) {
reply.replyReactions.forEach((reaction: any) => {
if (reaction.reactionId === action.payload.reactionId) {
reaction.reactionCount -= 1;
reaction.replyDisplayNames = action.payload.authors.reduce((acc: Array<string>, val: any) => {
acc.push(val.displayName);
return acc;
}, []);
}
});
}
});
}
return { ...state, replies: NewReplies };
}
default:
return state;
}
Expand Down
6 changes: 3 additions & 3 deletions client/src/common/store/sagas/chatroom-saga.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { call, put, takeEvery } from 'redux-saga/effects';
import API from '@utils/api';
import { ChatType } from '@constants/index';
import { ChatroomType } from '@constants/index';
import {
LOAD,
LOAD_ASYNC,
Expand Down Expand Up @@ -59,7 +59,7 @@ function* pickChannelSaga(action: any) {
function* addChannel(action: any) {
try {
const chatroomId = yield call(API.createChannel, action.payload.title, action.payload.description, action.payload.isPrivate);
const payload = { chatroomId, chatType: ChatType.Channel, isPrivate: action.payload.isPrivate, title: action.payload.title };
const payload = { chatroomId, chatType: ChatroomType.Channel, isPrivate: action.payload.isPrivate, title: action.payload.title };
yield put({ type: ADD_CHANNEL, payload });
yield put({ type: PICK_CHANNEL_ASYNC, payload: { selectedChatroomId: chatroomId } });
} catch (e) {
Expand All @@ -72,7 +72,7 @@ function* addDM(action: any) {
const { invitedUserId } = action.payload;
const chatroomId = yield call(API.createDM, invitedUserId);
const { profileUri, displayName } = yield call(API.getUser, invitedUserId);
yield put({ type: ADD_DM, payload: { chatroomId, chatProfileImg: profileUri, chatType: ChatType.DM, title: displayName, invitedUserId } });
yield put({ type: ADD_DM, payload: { chatroomId, chatProfileImg: profileUri, chatType: ChatroomType.DM, title: displayName, invitedUserId } });
yield put({ type: PICK_CHANNEL_ASYNC, payload: { selectedChatroomId: chatroomId } });
} catch (e) {
console.log(e);
Expand Down
4 changes: 2 additions & 2 deletions client/src/common/store/types/message-types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { userState } from './user-types';
import { messageReactionsState } from './message-reactions-type';
import { reactionsState } from './reactions-type';
import { chatroomThreadState } from './chatroom-types';

export interface messageState {
messageId: number;
createdAt: Date;
updatedAt: Date;
user: userState;
messageReactions: Array<messageReactionsState>;
messageReactions: Array<reactionsState>;
thread: chatroomThreadState;
}

Expand Down
3 changes: 2 additions & 1 deletion client/src/common/store/types/modal-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export interface EmojiPickerState {
isOpen: boolean;
x: number;
y: number;
messageId: number | null;
chatId: number | null;
type: string;
}

export interface ModalState {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface messageReactionsState {
export interface reactionsState {
reactionId: number;
title: string;
reactionCount: number;
Expand Down
24 changes: 19 additions & 5 deletions client/src/common/store/types/thread-types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { socketReplyReactionState } from '@socket/types/reaction-types';
import { userState } from '@store/types/user-types';

export const LOAD_THREAD = 'LOAD_THREAD';
export const LOAD_THREAD_ASYNC = 'LOAD_THREAD_ASYNC';
export const INSERT_REPLY = 'INSERT_REPLY';
export const LOAD_NEXT_REPLIES = 'LOAD_NEXT_REPLIES';
export const LOAD_NEXT_REPLIES_ASYNC = 'LOAD_NEXT_REPLIES_ASYNC';
export const ADD_REPLY_REACTION = 'ADD_MESSAGE_REACTION';
export const DELETE_REPLY_REACTION = 'DELETE_MESSAGE_REACTION';

export interface threadMessageState {
messageId: number;
Expand All @@ -18,13 +21,13 @@ export interface threadMessageState {
}

export interface replyState {
messageId?: number;
replyId: number;
messageId: number;
content: string;
createdAt: Date;
updateAt: Date;
updatedAt: Date;
replyId: number;
replyReactions: Array<any>;
user: userState;
replyReactions: Array<object>;
}

export interface repliesState {
Expand All @@ -34,6 +37,7 @@ export interface repliesState {
export interface threadState {
message: threadMessageState;
replies: Array<replyState>;
selectedThreadId: number | null;
}

interface LoadThreadAction {
Expand All @@ -51,4 +55,14 @@ interface LoadNextReplies {
payload: repliesState;
}

export type ThreadTypes = LoadThreadAction | InsertReply | LoadNextReplies;
interface AddReplyReaction {
type: typeof ADD_REPLY_REACTION;
payload: socketReplyReactionState;
}

interface DeleteReplyReaction {
type: typeof DELETE_REPLY_REACTION;
payload: socketReplyReactionState;
}

export type ThreadTypes = LoadThreadAction | InsertReply | LoadNextReplies | AddReplyReaction | DeleteReplyReaction;
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ const Template: Story<ActionbarProps> = (args) => <Actionbar {...args} />;

export const BlackActionbar = Template.bind({});
BlackActionbar.args = {
messageId: 1
chatId: 1
};
Loading

0 comments on commit c468196

Please sign in to comment.