diff --git a/src/components/message-list-footer/message-list-footer.ts b/src/components/message-list-footer/message-list-footer.ts index 59f11052e..b7d5406cd 100644 --- a/src/components/message-list-footer/message-list-footer.ts +++ b/src/components/message-list-footer/message-list-footer.ts @@ -27,6 +27,7 @@ export class MessageListFooter extends Block { props.onClickSend = () => { const error=validateMessage(this.valueMessage()); if (!error) { + sendMessage( this.valueMessage()); } else showAlert(error); @@ -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(); } } @@ -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}}} `) } diff --git a/src/services/send-message.ts b/src/services/send-message.ts index 38cb54bac..96ff87013 100644 --- a/src/services/send-message.ts +++ b/src/services/send-message.ts @@ -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) { @@ -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) => {