|
@@ -78,7 +78,7 @@ let chatMSG = async (id) => {
|
|
url _id type
|
|
url _id type
|
|
} owner{
|
|
} owner{
|
|
login _id nick
|
|
login _id nick
|
|
- } replies {
|
|
|
|
|
|
+ } replyTo {
|
|
_id text createdAt owner{
|
|
_id text createdAt owner{
|
|
login _id nick
|
|
login _id nick
|
|
}
|
|
}
|
|
@@ -107,19 +107,23 @@ let msgCount = async (chat_id) => {
|
|
return result
|
|
return result
|
|
}
|
|
}
|
|
|
|
|
|
-let chatSortMSG = async (id) => {
|
|
|
|
- let query = `query getMSGWithSort($query: String){
|
|
|
|
- MessageFind(query: $query){
|
|
|
|
- _id text createdAt owner{
|
|
|
|
|
|
+let chatSortMSG = async (id, skipCount) => {
|
|
|
|
+ let query = `query getMSG($query: String){
|
|
|
|
+ MessageFind(query: $query){
|
|
|
|
+ _id text createdAt media{
|
|
|
|
+ url _id type
|
|
|
|
+ } owner{
|
|
|
|
+ login _id nick
|
|
|
|
+ } replyTo {
|
|
|
|
+ _id text createdAt owner{
|
|
login _id nick
|
|
login _id nick
|
|
- } forwarded{
|
|
|
|
- _id text
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }`
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }`
|
|
|
|
|
|
let qVariables = {
|
|
let qVariables = {
|
|
- "query": JSON.stringify([{ "chat._id": id }, { sort: [{ title: -1 }], skip: [100], limit: [100] }])
|
|
|
|
|
|
+ "query": JSON.stringify([{ "chat._id": id }, { sort: [{ _id: -1 }], skip: [skipCount], limit: [30] }])
|
|
}
|
|
}
|
|
|
|
|
|
//меняем skip по событию скролла вверх
|
|
//меняем skip по событию скролла вверх
|
|
@@ -213,13 +217,31 @@ let avatarSet = async (avatar_id, chat_id) => {
|
|
return result
|
|
return result
|
|
}
|
|
}
|
|
|
|
|
|
-let newMSG = async (chat_id, text, media) => {
|
|
|
|
- let mediaQuery = []
|
|
|
|
|
|
+let newMSG = async (chat_id, text, media, replyTo, forwardTo) => {
|
|
|
|
+ let input = {}
|
|
|
|
+
|
|
|
|
+ input.text = text
|
|
|
|
+ input.media = []
|
|
|
|
+ input.chat = {
|
|
|
|
+ "_id": chat_id
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (replyTo) {
|
|
|
|
+ input.replyTo = {
|
|
|
|
+ "_id": replyTo
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (forwardTo) {
|
|
|
|
+ input.forwarded = {
|
|
|
|
+ "_id": forwardTo
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
if (media && Array.isArray(media)) {
|
|
if (media && Array.isArray(media)) {
|
|
- media.map(item => mediaQuery.push({ "_id": item._id }))
|
|
|
|
|
|
+ media.map(item => input.media.push({ "_id": item._id }))
|
|
} else {
|
|
} else {
|
|
- mediaQuery.push({})
|
|
|
|
|
|
+ input.media.push({})
|
|
}
|
|
}
|
|
|
|
|
|
let query = `mutation newMSG($msg: MessageInput){
|
|
let query = `mutation newMSG($msg: MessageInput){
|
|
@@ -233,13 +255,7 @@ let newMSG = async (chat_id, text, media) => {
|
|
}`
|
|
}`
|
|
|
|
|
|
let qVariables = {
|
|
let qVariables = {
|
|
- "msg": {
|
|
|
|
- "text": text,
|
|
|
|
- "media": mediaQuery,
|
|
|
|
- "chat": {
|
|
|
|
- "_id": chat_id
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ "msg": input
|
|
}
|
|
}
|
|
|
|
|
|
let result = await gql(query, qVariables)
|
|
let result = await gql(query, qVariables)
|
|
@@ -375,7 +391,7 @@ export const actionGetFile = (id) => actionPromise("fileFound", fileFound(id))
|
|
|
|
|
|
const actionGetChats = (id) => actionPromise("chats", userChats(id))
|
|
const actionGetChats = (id) => actionPromise("chats", userChats(id))
|
|
|
|
|
|
-const actionGetMessages = (chatID) => actionPromise("messages", chatMSG(chatID))
|
|
|
|
|
|
+const actionGetMessages = (chatID, skipCount) => actionPromise("messages", chatSortMSG(chatID, skipCount))
|
|
|
|
|
|
const actionChats = (chat_id, title, createdAt, lastModified, avatar, messages, members) => ({ type: "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 })
|
|
|
|
|
|
@@ -391,9 +407,9 @@ export const actionAddChatBack = (title, members) => actionPromise("chat", newCh
|
|
|
|
|
|
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 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: "MESSAGE", chat_id, msg_id, msg_text, msg_createdAt, msg_owner, msg_media })
|
|
|
|
|
|
+export const actionAddMSG = (socket, chat_id, msg_id, msg_text, msg_createdAt, msg_owner, msg_media, msg_replyTo) => ({ type: "MESSAGE", socket, chat_id, msg_id, msg_text, msg_createdAt, msg_owner, msg_media, msg_replyTo })
|
|
|
|
|
|
-export const actionAddMSGBack = (chat_id, text, media) => actionPromise("new_message", newMSG(chat_id, text, media))
|
|
|
|
|
|
+export const actionAddMSGBack = (chat_id, text, media, replyTo, forwardTo) => actionPromise("new_message", newMSG(chat_id, text, media, replyTo, forwardTo))
|
|
|
|
|
|
export const actionSetAvatar = (avatar_id, chat_id) => actionPromise("set_avatar", avatarSet(avatar_id, chat_id))
|
|
export const actionSetAvatar = (avatar_id, chat_id) => actionPromise("set_avatar", avatarSet(avatar_id, chat_id))
|
|
|
|
|
|
@@ -409,11 +425,11 @@ export const actionFullGetChats = (id) => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-export const actionFullGetMessages = (id) => {
|
|
|
|
|
|
+export const actionFullGetMessages = (id, skip) => {
|
|
return async (dispatch) => {
|
|
return async (dispatch) => {
|
|
- let result = await dispatch(actionGetMessages(id))
|
|
|
|
|
|
+ let result = await dispatch(actionGetMessages(id, skip))
|
|
let messages = result.data.MessageFind
|
|
let messages = result.data.MessageFind
|
|
- messages.map(message => dispatch(actionAddMSG(id, message._id, message.text, message.createdAt, message.owner, message.media)))
|
|
|
|
|
|
+ messages.map(message => dispatch(actionAddMSG(false, id, message._id, message.text, message.createdAt, message.owner, message.media, message.replyTo)))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|