|
@@ -74,7 +74,9 @@ let userChats = async (id) => {
|
|
|
let chatMSG = async (id) => {
|
|
|
let query = `query getMSG($chatID: String){
|
|
|
MessageFind(query: $chatID){
|
|
|
- _id text createdAt owner{
|
|
|
+ _id text createdAt media{
|
|
|
+ url _id type
|
|
|
+ } owner{
|
|
|
login _id nick
|
|
|
} replies {
|
|
|
_id text createdAt owner{
|
|
@@ -177,6 +179,8 @@ let editChat = async (chat_id, title, members) => {
|
|
|
ChatUpsert(chat: $chat){
|
|
|
_id title members{
|
|
|
_id login nick
|
|
|
+ } avatar {
|
|
|
+ _id url
|
|
|
}
|
|
|
}
|
|
|
}`
|
|
@@ -223,7 +227,7 @@ let newMSG = async (chat_id, text, media) => {
|
|
|
_id text createdAt owner{
|
|
|
_id nick login
|
|
|
} media{
|
|
|
- _id url
|
|
|
+ _id url type
|
|
|
}
|
|
|
}
|
|
|
}`
|
|
@@ -242,17 +246,11 @@ let newMSG = async (chat_id, text, media) => {
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
-let editMSG = async (id, text, media) => {
|
|
|
+let editMSG = async (id, text) => {
|
|
|
let input = {}
|
|
|
input._id = id
|
|
|
input.text = text
|
|
|
|
|
|
- if (media && Array.isArray(media)) {
|
|
|
- let mediaQuery = []
|
|
|
- media.map(item => mediaQuery.push({ "_id": item }))
|
|
|
- input.media = mediaQuery
|
|
|
- }
|
|
|
-
|
|
|
let query = `mutation editMSG($msg: MessageInput){
|
|
|
MessageUpsert(message: $msg){
|
|
|
_id text media{
|
|
@@ -379,38 +377,26 @@ const actionGetChats = (id) => actionPromise("chats", userChats(id))
|
|
|
|
|
|
const actionGetMessages = (chatID) => actionPromise("messages", chatMSG(chatID))
|
|
|
|
|
|
-const actionChats = (chat_id, title, createdAt, lastModified, avatar, messages, members) => ({ type: "ADD_CHAT", chat_id, title, createdAt, lastModified, avatar, messages, members })
|
|
|
+const actionChats = (chat_id, title, createdAt, lastModified, avatar, messages, members) => ({ type: "CHAT", chat_id, title, createdAt, lastModified, avatar, messages, members })
|
|
|
|
|
|
-export const actionEditChat = (chat_id, title, avatar, members) => ({ type: "EDIT_CHAT", chat_id, title, avatar, members })
|
|
|
+export const actionEditChat = (chat_id, title, avatar, members) => ({ type: "CHAT", chat_id, title, avatar, members })
|
|
|
|
|
|
const actionEditChatBack = (title, avatar, members) => actionPromise("edit_chat", editChat(title, avatar, members))
|
|
|
|
|
|
-export const actionEditMSG = (chat_id, message_id, text, media) => ({ type: "EDIT_MESSAGE", chat_id, messages: [{ _id: message_id, text, media }] })
|
|
|
+export const actionEditMSG = (chat_id, msg_id, msg_text) => ({ type: "MESSAGE", chat_id, msg_id, msg_text })
|
|
|
|
|
|
-const actionEditMSGback = (message_id, text, media) => actionPromise("edit_message", editMSG(message_id, text, media))
|
|
|
+export const actionEditMSGback = (message_id, text, media) => actionPromise("edit_message", editMSG(message_id, text, media))
|
|
|
|
|
|
export const actionAddChatBack = (title, members) => actionPromise("chat", newChat(title, members))
|
|
|
|
|
|
-export const actionAddChat = (chat_id, title, createdAt, lastModified, owner, avatar, messages, members) => ({ type: "ADD_CHAT", chat_id, title, createdAt, lastModified, owner, avatar, messages, members })
|
|
|
+export const actionAddChat = (chat_id, title, createdAt, lastModified, owner, avatar, messages, members) => ({ type: "CHAT", chat_id, title, createdAt, lastModified, owner, avatar, messages, members })
|
|
|
|
|
|
-export const actionAddMSG = (chat_id, msg_id, msg_text, msg_createdAt, msg_owner, msg_media) => ({ type: "ADD_MESSAGE", chat_id, msg_id, msg_text, msg_createdAt, msg_owner, msg_media })
|
|
|
+export const actionAddMSG = (chat_id, msg_id, msg_text, msg_createdAt, msg_owner, msg_media) => ({ type: "MESSAGE", chat_id, msg_id, msg_text, msg_createdAt, msg_owner, msg_media })
|
|
|
|
|
|
export const actionAddMSGBack = (chat_id, text, media) => actionPromise("new_message", newMSG(chat_id, text, media))
|
|
|
|
|
|
export const actionSetAvatar = (avatar_id, chat_id) => actionPromise("set_avatar", avatarSet(avatar_id, chat_id))
|
|
|
|
|
|
-// export const actionFullGetChats = (id) => {
|
|
|
-// return async (dispatch) => {
|
|
|
-// let chats = await dispatch(actionGetChats(id))
|
|
|
-
|
|
|
-// chats.data.UserFindOne.chats.map(async (chat) => {
|
|
|
-// let result = await dispatch(actionGetMessages(chat._id))
|
|
|
-// let messages = result.data.MessageFind
|
|
|
-// dispatch(actionChats(chat._id, chat.title, chat.createdAt, chat.lastModified, chat.avatar, messages, chat.members))
|
|
|
-// })
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
export const actionUserSearch = (searchInput) => actionPromise("userSearch", userSearch(searchInput))
|
|
|
|
|
|
export const actionFullGetChats = (id) => {
|
|
@@ -418,8 +404,6 @@ export const actionFullGetChats = (id) => {
|
|
|
let chats = await dispatch(actionGetChats(id))
|
|
|
|
|
|
chats.data.UserFindOne.chats.map(async (chat) => {
|
|
|
- // let result = await dispatch(actionGetMessages(chat._id))
|
|
|
- // let messages = result.data.MessageFind
|
|
|
dispatch(actionChats(chat._id, chat.title, chat.createdAt, chat.lastModified, chat.avatar, [], chat.members))
|
|
|
})
|
|
|
}
|
|
@@ -452,9 +436,10 @@ export const actionFullEditChat = (chat_id, title, avatar, members) => {
|
|
|
return async (dispatch) => {
|
|
|
let result = await dispatch(actionEditChatBack(chat_id, title, members))
|
|
|
let avatarResult = await dispatch(actionSetAvatar(avatar, chat_id))
|
|
|
+ console.log(avatarResult)
|
|
|
|
|
|
- if (result.data?.ChatUpsert && avatarResult) {
|
|
|
- dispatch(actionEditChat(chat_id, title, avatar, members))
|
|
|
+ if (result.data.ChatUpsert && avatarResult.data.MediaUpsert) {
|
|
|
+ dispatch(actionEditChat(chat_id, title, avatarResult.data.MediaUpsert, members))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -463,7 +448,6 @@ export const actionFullAddMessage = (chat_id, text, media) => {
|
|
|
return async (dispatch) => {
|
|
|
let result = await dispatch(actionAddMSGBack(chat_id, text, media))
|
|
|
|
|
|
- // dispatch(actionAddMSG(result.))
|
|
|
}
|
|
|
}
|
|
|
|