Skip to content

Commit

Permalink
Change from console to chat logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Tainan404 committed Jan 19, 2021
1 parent 09e95be commit 207daa3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ const generateStateWithNewMessage = ({ msg, senderData }, state) => {
const reducer = (state, action) => {
switch (action.type) {
case ACTIONS.TEST: {
ChatLogger.info(ACTIONS.TEST);
ChatLogger.debug(ACTIONS.TEST);
return {
...state,
...action.value,
};
}
case ACTIONS.ADDED: {
ChatLogger.info(ACTIONS.ADDED);
ChatLogger.debug(ACTIONS.ADDED);
const newState = generateStateWithNewMessage(action.value, state);
return {...newState};
}
Expand All @@ -160,14 +160,14 @@ const reducer = (state, action) => {
};
}
case ACTIONS.REMOVED: {
ChatLogger.info(ACTIONS.REMOVED);
ChatLogger.debug(ACTIONS.REMOVED);
if (state[msg.chatId]){
delete state[msg.chatId];
}
return state;
}
case ACTIONS.USER_STATUS_CHANGED: {
ChatLogger.info(ACTIONS.USER_STATUS_CHANGED);
ChatLogger.debug(ACTIONS.USER_STATUS_CHANGED);
const newState = {
...state,
};
Expand Down Expand Up @@ -198,7 +198,7 @@ const reducer = (state, action) => {
return newState
}
case ACTIONS.LAST_READ_MESSAGE_TIMESTAMP_CHANGED: {
ChatLogger.info(ACTIONS.LAST_READ_MESSAGE_TIMESTAMP_CHANGED);
ChatLogger.debug(ACTIONS.LAST_READ_MESSAGE_TIMESTAMP_CHANGED);
const { timestamp, chatId } = action.value;
const newState = {
...state,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useMemo, useContext, useEffect } from 'react';
import { useContext, useEffect } from 'react';
import Users from '/imports/api/users';
import { UsersContext, ACTIONS } from './context';
import ChatLogger from '/imports/ui/components/chat/chat-logger/ChatLogger';

const Adapter = () => {
const usingUsersContext = useContext(UsersContext);
Expand All @@ -9,7 +10,7 @@ const Adapter = () => {
const usersCursor = Users.find({}, { sort: { timestamp: 1 } });
usersCursor.observe({
added: (obj) => {
console.log("usersAdapter::observe::added", obj);
ChatLogger.debug("usersAdapter::observe::added", obj);
dispatch({
type: ACTIONS.ADDED,
value: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, {
useEffect,
useContext,
createContext,
useReducer,
} from 'react';
import ChatLogger from '/imports/ui/components/chat/chat-logger/ChatLogger';

export const ACTIONS = {
TEST: 'test',
Expand All @@ -25,7 +24,7 @@ const reducer = (state, action) => {

case ACTIONS.ADDED:
case ACTIONS.CHANGED: {
console.log('UsersContextProvider::reducer::added', { ...action });
ChatLogger.debug('UsersContextProvider::reducer::added', { ...action });
const { user } = action.value;

const newState = {
Expand All @@ -37,7 +36,7 @@ const reducer = (state, action) => {
return newState;
}
case ACTIONS.REMOVED: {
console.log('UsersContextProvider::reducer::removed', { ...action });
ChatLogger.debug('UsersContextProvider::reducer::removed', { ...action });

const { user } = action.value;
if (state[user.userId]) {
Expand All @@ -56,7 +55,7 @@ const reducer = (state, action) => {

export const UsersContextProvider = (props) => {
const [usersContextState, usersContextDispatch] = useReducer(reducer, {});
console.log('UsersContextProvider::usersContextState',usersContextState);
ChatLogger.debug('UsersContextProvider::usersContextState', usersContextState);
return (
<UsersContext.Provider value={
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ export default withTracker(() => {
const ready = subscriptionsHandlers.every(handler => handler.ready());
let groupChatMessageHandler = {};

console.log('not Ready');
if (CHAT_ENABLED && ready) {
console.log('Ready');
const chats = GroupChat.find({
$or: [
{
Expand All @@ -106,8 +104,6 @@ export default withTracker(() => {

const chatIds = chats.map(chat => chat.chatId);
groupChatMessageHandler = Meteor.subscribe('group-chat-msg', chatIds, subscriptionErrorHandler);
console.log('groupChatMessageHandler', groupChatMessageHandler);
// subscriptionsHandlers.push(groupChatMessageHandler);
}

return {
Expand Down

0 comments on commit 207daa3

Please sign in to comment.