Skip to content

Commit

Permalink
fixed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
LevanovaElena committed Oct 15, 2023
1 parent 9848919 commit deb2c3b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/components/message-list-footer/message-list-footer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class MessageListFooter extends Block {
props.onClickSend = () => {
const error=validateMessage(this.valueMessage());
if (!error) {

sendMessage( this.valueMessage());
}
else showAlert(error);
Expand All @@ -39,6 +40,7 @@ export class MessageListFooter extends Block {
submit:(event: Event)=>{
event.stopPropagation();
event.preventDefault();
console.log('submit')
this.props.onClickSend&&this.props.onClickSend();
}
}
Expand Down Expand Up @@ -69,7 +71,7 @@ export class MessageListFooter extends Block {
name="message"
onBlur=onBlurMessage
}}}
{{{ Button type="arrow" onClick=onClickSend isSubmit=true}}}
{{{ Button type="arrow" isSubmit=true}}}
</form>
`)
}
Expand Down
8 changes: 5 additions & 3 deletions src/services/send-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export const openConnectMessages = (chat: IChat, currentUser: IUser) => {
if (!chat.messages) chat.messages = [];
if (Array.isArray(message)) {
message.reverse();
chat.messages = [...chat.messages, ...message];
chat.messages =chat.messages.concat(message);
} else chat.messages.push(message);
if (chat.id === window.store.getState().currentChat?.id) window.store.set({currentChat: {...chat}});
if (chat.id === window.store.getState().currentChat?.id) window.store.set({currentChat:chat});
else {
const foundedChat = window.store.getState().chats?.find(_chat => _chat.id === chat.id);
if (foundedChat) {
Expand All @@ -58,10 +58,12 @@ export const openConnectMessages = (chat: IChat, currentUser: IUser) => {

export const sendMessage = (message: string) => {
const chat = window.store.getState().currentChat;
const user =window.store.getState().user;
if (!chat) throw Error('Select Chat!');
if (chat.connection) {
if (chat.connection&&chat.connection.getState()==='OPEN') {
chat.connection.sendMessage(message);
}
else if(user)openConnectMessages(chat,user)
}

export const getAllNewMessage = (limit: number, chat: IChat | null) => {
Expand Down

0 comments on commit deb2c3b

Please sign in to comment.