|
@@ -1,5 +1,3 @@
|
|
-//потом почищу лишнее
|
|
|
|
-
|
|
|
|
const getGQL = url => {
|
|
const getGQL = url => {
|
|
return (query, variables) => {
|
|
return (query, variables) => {
|
|
return fetch(url, {
|
|
return fetch(url, {
|
|
@@ -71,42 +69,6 @@ let userChats = async (id) => {
|
|
return result
|
|
return result
|
|
}
|
|
}
|
|
|
|
|
|
-let chatMSG = async (id) => {
|
|
|
|
- let query = `query getMSG($chatID: String){
|
|
|
|
- MessageFind(query: $chatID){
|
|
|
|
- _id text createdAt media{
|
|
|
|
- url _id type
|
|
|
|
- } owner{
|
|
|
|
- login _id nick
|
|
|
|
- } replyTo {
|
|
|
|
- _id text createdAt owner{
|
|
|
|
- login _id nick
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }`
|
|
|
|
-
|
|
|
|
- let qVariables = {
|
|
|
|
- "chatID": JSON.stringify([{ "chat._id": id }])
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- let result = await gql(query, qVariables)
|
|
|
|
- return result
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-let msgCount = async (chat_id) => {
|
|
|
|
- let query = `query msgCount($query: String){
|
|
|
|
- MessageCount(query: $query)
|
|
|
|
- }`
|
|
|
|
-
|
|
|
|
- let qVariables = {
|
|
|
|
- "query": JSON.stringify([{ "chat._id": chat_id }])
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- let result = await gql(query, qVariables)
|
|
|
|
- return result
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
let chatSortMSG = async (id, skipCount) => {
|
|
let chatSortMSG = async (id, skipCount) => {
|
|
let query = `query getMSG($query: String){
|
|
let query = `query getMSG($query: String){
|
|
MessageFind(query: $query){
|
|
MessageFind(query: $query){
|
|
@@ -126,8 +88,6 @@ let chatSortMSG = async (id, skipCount) => {
|
|
"query": JSON.stringify([{ "chat._id": id }, { sort: [{ _id: -1 }], skip: [skipCount], limit: [30] }])
|
|
"query": JSON.stringify([{ "chat._id": id }, { sort: [{ _id: -1 }], skip: [skipCount], limit: [30] }])
|
|
}
|
|
}
|
|
|
|
|
|
- //меняем skip по событию скролла вверх
|
|
|
|
-
|
|
|
|
let result = await gql(query, qVariables)
|
|
let result = await gql(query, qVariables)
|
|
return result
|
|
return result
|
|
}
|
|
}
|
|
@@ -285,15 +245,17 @@ let editMSG = async (id, text) => {
|
|
return result
|
|
return result
|
|
}
|
|
}
|
|
|
|
|
|
-let fileFound = async (id) => {
|
|
|
|
- let query = `query findMedia($id: String){
|
|
|
|
- MediaFind(query: $id){
|
|
|
|
- url type originalFileName
|
|
|
|
- }
|
|
|
|
- }`
|
|
|
|
|
|
+let userInfo = async (id) => {
|
|
|
|
+ let query = `query user($uid: String){
|
|
|
|
+ UserFindOne(query: $uid){
|
|
|
|
+ _id login nick avatar{
|
|
|
|
+ _id url
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }`
|
|
|
|
|
|
let qVariables = {
|
|
let qVariables = {
|
|
- "id": JSON.stringify([{ "_id": id }])
|
|
|
|
|
|
+ "uid": JSON.stringify([{ "_id": id }])
|
|
}
|
|
}
|
|
|
|
|
|
let result = await gql(query, qVariables)
|
|
let result = await gql(query, qVariables)
|
|
@@ -321,7 +283,62 @@ let userSearch = async (searchInput) => {
|
|
}
|
|
}
|
|
|
|
|
|
let result = await gql(query, qVariables)
|
|
let result = await gql(query, qVariables)
|
|
- console.log(result)
|
|
|
|
|
|
+ return result
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+let changeNick = async (userID, nick) => {
|
|
|
|
+ let query = `mutation passwordChange($input: UserInput){
|
|
|
|
+ UserUpsert(user: $input){
|
|
|
|
+ _id
|
|
|
|
+ }
|
|
|
|
+ }`
|
|
|
|
+
|
|
|
|
+ let qVariables = {
|
|
|
|
+ "input": {
|
|
|
|
+ "_id": userID,
|
|
|
|
+ "nick": nick
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let result = await gql(query, qVariables)
|
|
|
|
+ return result
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+let changeUserAvatar = async (userID, imageID) => {
|
|
|
|
+ let query = `mutation setUserAvatar($avatar: MediaInput){
|
|
|
|
+ MediaUpsert(media: $avatar){
|
|
|
|
+ _id text url
|
|
|
|
+ }
|
|
|
|
+ }`
|
|
|
|
+
|
|
|
|
+ let qVariables = {
|
|
|
|
+ "avatar": {
|
|
|
|
+ "_id": imageID,
|
|
|
|
+ "userAvatar": {
|
|
|
|
+ "_id": userID
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let result = await gql(query, qVariables)
|
|
|
|
+ return result
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+let changeUserPassword = async (userID, newPassword) => {
|
|
|
|
+ let query = `mutation passwordChange($input: UserInput){
|
|
|
|
+ UserUpsert(user: $input){
|
|
|
|
+ _id
|
|
|
|
+ }
|
|
|
|
+ }`
|
|
|
|
+
|
|
|
|
+ let qVariables = {
|
|
|
|
+ "input": {
|
|
|
|
+ "_id": userID,
|
|
|
|
+ "password": newPassword
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let result = await gql(query, qVariables)
|
|
return result
|
|
return result
|
|
}
|
|
}
|
|
|
|
|
|
@@ -342,9 +359,9 @@ const actionPromise = (name, promise) =>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-export const actionAuthLogin = token => ({ type: "LOGIN", token })
|
|
|
|
|
|
+const actionAuthLogin = token => ({ type: "LOGIN", token })
|
|
|
|
|
|
-export const actionLogin = (login, password) => actionPromise("login", log(login, password))
|
|
|
|
|
|
+const actionLogin = (login, password) => actionPromise("login", log(login, password))
|
|
|
|
|
|
export const actionFullLogin = (login, password) => {
|
|
export const actionFullLogin = (login, password) => {
|
|
return async (dispatch) => {
|
|
return async (dispatch) => {
|
|
@@ -383,11 +400,47 @@ let upload = async (files) => {
|
|
}).then(res => res.json())
|
|
}).then(res => res.json())
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+export const actionChangeUserAvatar = (userID, imageID) => actionPromise("changeUserAvatar", changeUserAvatar(userID, imageID))
|
|
|
|
+
|
|
|
|
+export const actionChangeUserPassword = (userID, newPassword) => actionPromise("changeUserPassword", changeUserPassword(userID, newPassword))
|
|
|
|
+
|
|
|
|
+export const actionChangeUserNick = (userID, nick) => actionPromise("changeUserNick", changeNick(userID, nick))
|
|
|
|
+
|
|
|
|
+export const actionFullChangeUserNick = (userID, nick) => {
|
|
|
|
+ return async (dispatch) => {
|
|
|
|
+ let result = await dispatch(actionChangeUserNick(userID, nick))
|
|
|
|
+
|
|
|
|
+ if (result.data.UserUpsert !== null) {
|
|
|
|
+ dispatch(actionGetUserInfo(userID))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export const actionFullChangeUserAvatar = (userID, imageID) => {
|
|
|
|
+ return async (dispatch) => {
|
|
|
|
+ let result = await dispatch(actionChangeUserAvatar(userID, imageID))
|
|
|
|
+
|
|
|
|
+ if (result.data.UserUpsert !== null) {
|
|
|
|
+ dispatch(actionGetUserInfo(userID))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export const actionFullChangeUserPassword = (userID, newPassword) => {
|
|
|
|
+ return async (dispatch) => {
|
|
|
|
+ let result = await dispatch(actionChangeUserPassword(userID, newPassword))
|
|
|
|
+
|
|
|
|
+ if (result.data.UserUpsert !== null) {
|
|
|
|
+ dispatch(actionGetUserInfo(userID))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
export const actionUploadFile = (files) => actionPromise("upload", upload(files))
|
|
export const actionUploadFile = (files) => actionPromise("upload", upload(files))
|
|
|
|
|
|
export const actionAuthLogout = () => ({ type: "LOGOUT" })
|
|
export const actionAuthLogout = () => ({ type: "LOGOUT" })
|
|
|
|
|
|
-export const actionGetFile = (id) => actionPromise("fileFound", fileFound(id))
|
|
|
|
|
|
+export const actionGetUserInfo = (id) => actionPromise("userInfo", userInfo(id))
|
|
|
|
|
|
const actionGetChats = (id) => actionPromise("chats", userChats(id))
|
|
const actionGetChats = (id) => actionPromise("chats", userChats(id))
|
|
|
|
|
|
@@ -451,19 +504,17 @@ export const actionFullAddChat = (title, members) => {
|
|
export const actionFullEditChat = (chat_id, title, avatar, members) => {
|
|
export const actionFullEditChat = (chat_id, title, avatar, members) => {
|
|
return async (dispatch) => {
|
|
return async (dispatch) => {
|
|
let result = await dispatch(actionEditChatBack(chat_id, title, members))
|
|
let result = await dispatch(actionEditChatBack(chat_id, title, members))
|
|
- let avatarResult = await dispatch(actionSetAvatar(avatar, chat_id))
|
|
|
|
- console.log(avatarResult)
|
|
|
|
|
|
+ let avatarResult
|
|
|
|
|
|
- if (result.data.ChatUpsert && avatarResult.data.MediaUpsert) {
|
|
|
|
- dispatch(actionEditChat(chat_id, title, avatarResult.data.MediaUpsert, members))
|
|
|
|
|
|
+ if (avatar) {
|
|
|
|
+ avatarResult = await dispatch(actionSetAvatar(avatar, chat_id))
|
|
}
|
|
}
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export const actionFullAddMessage = (chat_id, text, media) => {
|
|
|
|
- return async (dispatch) => {
|
|
|
|
- let result = await dispatch(actionAddMSGBack(chat_id, text, media))
|
|
|
|
|
|
|
|
|
|
+ if (result.data.ChatUpsert && avatarResult?.data.MediaUpsert) {
|
|
|
|
+ dispatch(actionEditChat(chat_id, title, avatarResult.data.MediaUpsert, members))
|
|
|
|
+ } else if (result.data.ChatUpsert) {
|
|
|
|
+ dispatch(actionEditChat(chat_id, title, null, members))
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -476,5 +527,4 @@ export const actionFullEditMSG = (message_id, text, media) => {
|
|
result.data.MessageUpsert.text,
|
|
result.data.MessageUpsert.text,
|
|
result.data.MessageUpsert.media))
|
|
result.data.MessageUpsert.media))
|
|
}
|
|
}
|
|
-}
|
|
|
|
-
|
|
|
|
|
|
+}
|