actionAboutMe.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { actionPromise } from "./actionsPromise";
  2. import { gql } from "../helpers/gql";
  3. import { actionAddChats } from "./actionsForChats";
  4. export const actionFindUser = (_id) => (
  5. actionPromise('aboutMe', gql(`query findUserOne($q: String) {
  6. UserFindOne (query: $q){
  7. _id
  8. createdAt
  9. login
  10. nick
  11. avatar {
  12. _id
  13. url
  14. }
  15. chats {
  16. _id
  17. title
  18. createdAt
  19. lastModified
  20. owner{
  21. _id
  22. }
  23. lastMessage {
  24. media{
  25. _id
  26. url
  27. }
  28. text
  29. createdAt
  30. owner{
  31. _id
  32. nick
  33. }
  34. }
  35. avatar{
  36. _id
  37. url
  38. }
  39. members{
  40. _id
  41. nick
  42. avatar{
  43. url
  44. }
  45. }
  46. }
  47. }
  48. }`, {
  49. q: JSON.stringify([ {_id: _id} ])
  50. }
  51. ))
  52. )
  53. export const actionAboutMe = () =>
  54. async (dispatch, getState) => {
  55. const{auth} = getState();
  56. const id = auth?.payload?.sub?.id
  57. if(id){
  58. let user = await dispatch(actionFindUser(id))
  59. console.log(user)
  60. if (user){
  61. dispatch(actionAddChats([...user.chats]));
  62. }
  63. }
  64. }