action-create-msg.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import actionPromise from "./action-promise"
  2. import { gql } from '../../graphQl/getGQL'
  3. import { useParams } from "react-router-dom"
  4. export const actionCreateMessage = (text, _id, chats) => {
  5. const windowId = window.location.pathname
  6. const windowSplit = windowId.split('/')
  7. const chatId = windowSplit[2]
  8. return (
  9. actionPromise(
  10. 'updateMsg',
  11. gql(
  12. `mutation newMsg($text: String, $id: ID) {
  13. MessageUpsert(message: {chat: {_id: $id} text: $text}){
  14. _id owner {
  15. _id
  16. createdAt
  17. login
  18. nick
  19. } chat {
  20. _id
  21. createdAt
  22. lastModified
  23. title
  24. } text media {
  25. _id
  26. createdAt
  27. text
  28. url
  29. originalFileName
  30. type
  31. } createdAt
  32. }
  33. }`, { id: chatId, text: text }))
  34. )
  35. }