Skip to content

Commit

Permalink
Merge pull request #1085 from kimbu-chat/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
remotenode authored Mar 30, 2022
2 parents b378067 + 24b2194 commit 25cb457
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 55 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"eslint-plugin-react-hooks": "4.2.0",
"file-loader": "6.2.0",
"husky": "7.0.1",
"kimbu-models": "git://github.com/kimbu-chat/frontend-types.git#fd7cc7c",
"kimbu-models": "https://github.com/kimbu-chat/frontend-types.git#fd7cc7c",
"lint-staged": "11.1.2",
"prettier": "2.3.2",
"run-script-os": "1.1.6",
Expand Down
4 changes: 2 additions & 2 deletions src/components/message-input/message-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ const CreateMessageInput = () => {
currentUserId
) {
if (chatId) {
const message: ICreateMessageActionPayload = {};
const message: ICreateMessageActionPayload = { text: messageText };
if (refferedReplyingMessage.current) {
const {
current: referMessage,
Expand Down Expand Up @@ -269,7 +269,7 @@ const CreateMessageInput = () => {
});
},
1000,
{ leading: true, trailing: false },
{ leading: true, trailing: true },
),
).current;

Expand Down
4 changes: 2 additions & 2 deletions src/components/message-list/message-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { MessageItem } from '@components/message-item';
import { SelectedMessagesData } from '@components/selected-messages-data';
import { useActionWithDispatch } from '@hooks/use-action-with-dispatch';
import { useIntersectionObserver } from '@hooks/use-intersection-observer';
import { getMessagesAction, markMessagesAsReadAction } from '@store/chats/actions';
import { getMessagesAction, markChatAsReadAction } from '@store/chats/actions';
import {
getMessagesIdsByChatIdSelector,
getSelectedMessageIds,
Expand All @@ -42,7 +42,7 @@ type ISeparatedMessagesPack = {

const MessageList = () => {
const getMessages = useActionWithDispatch(getMessagesAction);
const markMessagesAsRead = useActionWithDispatch(markMessagesAsReadAction);
const markMessagesAsRead = useActionWithDispatch(markChatAsReadAction);

const { t } = useTranslation();

Expand Down
12 changes: 6 additions & 6 deletions src/store/chats/actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CreateDraftMessage } from '@store/chats/features/create-draft-message/create-draft-message';
import { DiscardDraftMessage } from '@store/chats/features/create-draft-message/discard-draft-message';
import { GetPossibleMembers } from '@store/chats/features/get-possible-members/get-possible-members';
import {MessageAttachmentsUploaded} from '@store/chats/features/upload-attachment/message-attachments-uploaded';
import { MessageAttachmentsUploaded } from '@store/chats/features/upload-attachment/message-attachments-uploaded';

import { AddUsersToGroupChatSuccess } from './features/add-users-to-group-chat/add-users-to-group-chat-success';
import { AddUsersToGroupChat } from './features/add-users-to-group-chat/add-users-to-group-chat';
Expand Down Expand Up @@ -48,8 +48,8 @@ import { GetVoiceAttachments } from './features/get-voice-attachments/get-voice-
import { InterlocutorStoppedTyping } from './features/interlocutor-message-typing/interlocutor-stopped-typing';
import { LeaveGroupChatSuccess } from './features/leave-group-chat/leave-group-chat-success';
import { LeaveGroupChat } from './features/leave-group-chat/leave-group-chat';
import { MarkMessagesAsReadSuccess } from './features/mark-messages-as-read/mark-messages-as-read-success';
import { MarkMessagesAsRead } from './features/mark-messages-as-read/mark-messages-as-read';
import { MarkChatAsReadSuccess } from './features/mark-chat-as-read/mark-chat-as-read-success';
import { MarkChatAsRead } from './features/mark-chat-as-read/mark-chat-as-read';
import { MessageTyping } from './features/message-typing/message-typing';
import { RemoveAllAttachments } from './features/remove-attachment/remove-all-attachments';
import { RemoveAttachment } from './features/remove-attachment/remove-attachment';
Expand Down Expand Up @@ -121,8 +121,8 @@ export const uploadAttachmentSuccessAction = UploadAttachmentSuccess.action;
export const uploadAttachmentFailureAction = UploadAttachmentFailure.action;
export const removeAttachmentAction = RemoveAttachment.action;
export const uploadMessageAttachmentsSuccess = MessageAttachmentsUploaded.action;
export const markMessagesAsReadAction = MarkMessagesAsRead.action;
export const markMessagesAsReadSuccessAction = MarkMessagesAsReadSuccess.action;
export const markChatAsReadAction = MarkChatAsRead.action;
export const markMessagesAsReadSuccessAction = MarkChatAsReadSuccess.action;
export const getMessagesAction = GetMessages.action;
export const getMessagesSuccessAction = GetMessagesSuccess.action;
export const getMessagesFailureAction = GetMessagesFailure.action;
Expand Down Expand Up @@ -211,7 +211,7 @@ export const ChatActions = {
uploadAttachmentSuccessAction,
uploadAttachmentFailureAction,
removeAttachmentAction,
markMessagesAsReadAction,
markMessagesAsReadAction: markChatAsReadAction,
markMessagesAsReadSuccessAction,
getMessagesAction,
getMessagesSuccessAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import { INormalizedMessage } from '@store/chats/models';
export interface ICreateMessageActionPayload {
linkedMessage?: INormalizedMessage;
linkedMessageType?: MessageLinkType;
text: string;
}
12 changes: 8 additions & 4 deletions src/store/chats/features/create-message/create-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class CreateMessage {
static get reducer() {
return produce((draft: IChatsState, { payload }: ReturnType<typeof CreateMessage.action>) => {
const chat = draft.chats[draft.selectedChatId as number];
const { text, linkedMessage, linkedMessageType } = payload;

if (chat) {
chat.lastMessageId = chat.draftMessageId as number;
Expand All @@ -45,17 +46,20 @@ export class CreateMessage {

if (chat.messages && chat.draftMessageId) {
const draftMessage = chat.messages.messages[chat.draftMessageId];
draftMessage.text = text;
draftMessage.state = MessageState.QUEUED;
draftMessage.linkedMessage = payload.linkedMessage;
draftMessage.linkedMessageType = payload.linkedMessageType;
draftMessage.linkedMessage = linkedMessage;
draftMessage.linkedMessageType = linkedMessageType;
chat.messages.messageIds.unshift(chat.draftMessageId);
}
return draft;
});
}

static get saga() {
return function* createMessage(): SagaIterator {
return function* createMessage(action: ReturnType<typeof CreateMessage.action>): SagaIterator {
const { text } = action.payload;

const selectedChatId: number = yield select(getSelectedChatIdSelector);
const { draftMessageId }: INormalizedChat = yield select(getChatByIdSelector(selectedChatId));
const chat = yield select(getChatByIdSelector(selectedChatId));
Expand All @@ -64,7 +68,7 @@ export class CreateMessage {
let uploadedAttachments = [];

const messageCreationReq: ICreateMessageRequest = {
text: message.text,
text,
chatId: selectedChatId,
attachmentIds: [],
clientId: message.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import { createAction } from 'typesafe-actions';
import { IChatsState } from '../../chats-state';
import { getChatByIdDraftSelector } from '../../selectors';

import { IMarkMessagesAsReadSuccessActionPayload } from './action-payloads/mark-messages-as-read-success-action-payload';
export interface IMarkChatAsReadSuccessActionPayload {
chatId: number;
lastReadMessageId: number;
}

export class MarkMessagesAsReadSuccess {
export class MarkChatAsReadSuccess {
static get action() {
return createAction(
'RESET_UNREAD_MESSAGES_COUNT_SUCCESS',
)<IMarkMessagesAsReadSuccessActionPayload>();
return createAction('MARK_CHAT_AS_READ_SUCCESS')<IMarkChatAsReadSuccessActionPayload>();
}

static get reducer() {
return produce(
(draft: IChatsState, { payload }: ReturnType<typeof MarkMessagesAsReadSuccess.action>) => {
(draft: IChatsState, { payload }: ReturnType<typeof MarkChatAsReadSuccess.action>) => {
const { chatId } = payload;

const chat = getChatByIdDraftSelector(chatId, draft);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { SagaIterator } from 'redux-saga';
import { call, put, select } from 'redux-saga/effects';

import { MAIN_API } from '@common/paths';
import {INormalizedChat} from "@store/chats/models";
import { INormalizedChat } from '@store/chats/models';
import { createEmptyAction } from '@store/common/actions';
import { httpRequestFactory, HttpRequestMethod } from '@store/common/http';

import { getSelectedChatSelector } from '../../selectors';

import { MarkMessagesAsReadSuccess } from './mark-messages-as-read-success';
import { MarkChatAsReadSuccess } from './mark-chat-as-read-success';

export class MarkMessagesAsRead {
export class MarkChatAsRead {
static get action() {
return createEmptyAction('RESET_UNREAD_MESSAGES_COUNT_FOR_SELECTED_CHAT');
return createEmptyAction('MARK_CHAT_AS_READ');
}

static get saga() {
Expand All @@ -24,9 +24,9 @@ export class MarkMessagesAsRead {
const lastReadMessageId = chat?.lastMessageId;

if (lastReadMessageId && chatId) {
yield call(() => MarkMessagesAsRead.httpRequest.generator({ chatId, lastReadMessageId }));
yield call(() => MarkChatAsRead.httpRequest.generator({ chatId, lastReadMessageId }));

yield put(MarkMessagesAsReadSuccess.action({ chatId, lastReadMessageId }));
yield put(MarkChatAsReadSuccess.action({ chatId, lastReadMessageId }));
}
};
}
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions src/store/chats/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { GetVoiceAttachmentsSuccess } from './features/get-voice-attachments/get
import { GetVoiceAttachments } from './features/get-voice-attachments/get-voice-attachments';
import { InterlocutorStoppedTyping } from './features/interlocutor-message-typing/interlocutor-stopped-typing';
import { LeaveGroupChatSuccess } from './features/leave-group-chat/leave-group-chat-success';
import { MarkMessagesAsReadSuccess } from './features/mark-messages-as-read/mark-messages-as-read-success';
import { MarkChatAsReadSuccess } from './features/mark-chat-as-read/mark-chat-as-read-success';
import { MessageTyping } from './features/message-typing/message-typing';
import { RemoveAllAttachments } from './features/remove-attachment/remove-all-attachments';
import { RemoveAttachment } from './features/remove-attachment/remove-attachment';
Expand Down Expand Up @@ -117,7 +117,7 @@ const reducer = createReducer<IChatsState>(initialState)
.handleAction(GetChatsSuccess.action, GetChatsSuccess.reducer)
.handleAction(GetChatsFailure.action, GetChatsFailure.reducer)
.handleAction(LeaveGroupChatSuccess.action, LeaveGroupChatSuccess.reducer)
.handleAction(MarkMessagesAsReadSuccess.action, MarkMessagesAsReadSuccess.reducer)
.handleAction(MarkChatAsReadSuccess.action, MarkChatAsReadSuccess.reducer)
.handleAction(GetPhotoAttachmentsSuccess.action, GetPhotoAttachmentsSuccess.reducer)
.handleAction(GetVoiceAttachmentsSuccess.action, GetVoiceAttachmentsSuccess.reducer)
.handleAction(GetRawAttachmentsSuccess.action, GetRawAttachmentsSuccess.reducer)
Expand Down
4 changes: 2 additions & 2 deletions src/store/chats/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { GetRawAttachments } from './features/get-raw-attachments/get-raw-attach
import { GetVideoAttachments } from './features/get-video-attachments/get-video-attachments';
import { GetVoiceAttachments } from './features/get-voice-attachments/get-voice-attachments';
import { LeaveGroupChat } from './features/leave-group-chat/leave-group-chat';
import { MarkMessagesAsRead } from './features/mark-messages-as-read/mark-messages-as-read';
import { MarkChatAsRead } from './features/mark-chat-as-read/mark-chat-as-read';
import { MessageTyping } from './features/message-typing/message-typing';
import { RemoveAllAttachments } from './features/remove-attachment/remove-all-attachments';
import { RemoveAttachment } from './features/remove-attachment/remove-attachment';
Expand All @@ -51,7 +51,7 @@ export function* chatSaga() {
takeLatest(GetRawAttachments.action, GetRawAttachments.saga),
takeLatest(GetVoiceAttachments.action, GetVoiceAttachments.saga),
takeLatest(GetAudioAttachments.action, GetAudioAttachments.saga),
takeLatest(MarkMessagesAsRead.action, MarkMessagesAsRead.saga),
takeLatest(MarkChatAsRead.action, MarkChatAsRead.saga),
takeLatest(GetChatInfo.action, GetChatInfo.saga),
takeLatest(ChangeSelectedChat.action, ChangeSelectedChat.saga),
takeLatest(EditGroupChat.action, EditGroupChat.saga),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { select, put, call } from 'redux-saga/effects';
import { createAction } from 'typesafe-actions';

import { MAIN_API } from '@common/paths';
import { MarkMessagesAsRead } from '@store/chats/features/mark-messages-as-read/mark-messages-as-read';
import { MarkChatAsRead } from '@store/chats/features/mark-chat-as-read/mark-chat-as-read';
import { INormalizedChat, INormalizedMessage } from '@store/chats/models';
import {
chatNormalizationSchema,
Expand Down Expand Up @@ -189,7 +189,7 @@ export class MessageCreatedEventHandler {
lastReadMessageId: id,
};

yield call(() => MarkMessagesAsRead.httpRequest.generator(httpRequestPayload));
yield call(() => MarkChatAsRead.httpRequest.generator(httpRequestPayload));
} else {
setUnreadMessageId(id);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function* watcher(): SagaIterator {
const visibilityChannel = createVisibilityChannel();
const visibilityTask = yield takeEvery(
visibilityChannel,
function* changeOnlineStatus(action: boolean): SagaIterator {
yield put(ChangeUserOnlineStatus.action(action));
function* changeOnlineStatus(online: boolean): SagaIterator {
yield put(ChangeUserOnlineStatus.action(online));
},
);

Expand Down
6 changes: 1 addition & 5 deletions src/store/middlewares/websockets/centrifuge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ async function openConnection(store: MiddlewareAPI<Dispatch, RootState>) {
CentrifugeModule = (await import('centrifuge')).default;
}

connection = new CentrifugeModule(REACT_APP_WEBSOCKET_API, {
debug: true,
timeout,
});

const onRefresh = (_: any, cb: (response: Centrifuge.RefreshResponse) => void) => {
store.dispatch(refreshTokenAction());
refreshResponseCallback = cb;
Expand All @@ -34,6 +29,7 @@ async function openConnection(store: MiddlewareAPI<Dispatch, RootState>) {
connection = new CentrifugeModule(REACT_APP_WEBSOCKET_API, {
debug: true,
onRefresh,
timeout,
});

connection.setToken(store.getState().auth?.securityTokens?.accessToken || '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createAction } from 'typesafe-actions';

import { MAIN_API } from '@common/paths';
import { authenticatedSelector } from '@store/auth/selectors';
import { MarkMessagesAsRead } from '@store/chats/features/mark-messages-as-read/mark-messages-as-read';
import { MarkChatAsRead } from '@store/chats/features/mark-chat-as-read/mark-chat-as-read';
import { getSelectedChatIdSelector } from '@store/chats/selectors';
import { getUnreadMessageId, setUnreadMessageId } from '@store/chats/utils/unread-message';
import { httpRequestFactory, HttpRequestMethod } from '@store/common/http';
Expand Down Expand Up @@ -53,7 +53,7 @@ export class ChangeUserOnlineStatus {
lastReadMessageId: unreadMessageId,
};

yield call(() => MarkMessagesAsRead.httpRequest.generator(httpRequestPayload));
yield call(() => MarkChatAsRead.httpRequest.generator(httpRequestPayload));

setUnreadMessageId(null);
}
Expand Down

0 comments on commit 25cb457

Please sign in to comment.