Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
foreign
/
customer-service
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
87ad0f2f
authored
Nov 26, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update
parent
d30772c1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
29 deletions
store/index.ts
xim/xim.ts
store/index.ts
View file @
87ad0f2f
...
...
@@ -349,9 +349,10 @@ export default {
}
else
{
arr
.
push
(
eid
);
}
setTimeoutId
[
eid
]
=
setTimeout
(()
=>
{
arr
.
splice
(
arr
.
indexOf
(
eid
),
1
);
},
4000
);
setTimeoutId
[
eid
]
=
setTimeout
(
()
=>
arr
.
splice
(
arr
.
indexOf
(
eid
),
1
),
4000
);
};
})(),
[
ChatStore
.
MUTATION_CLEAR_CURRENT_CHAT_INPUTING
]:
(
state
)
=>
{
...
...
@@ -477,21 +478,31 @@ export default {
items
.
forEach
((
i
)
=>
(
sum
+=
i
.
unread_msg_count
));
state
[
ChatStore
.
STATE_CURRENT_UNREAD_MESSAGE_COUNT
]
=
sum
;
},
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES
]({
state
,
commit
})
{
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES
]({
state
,
commit
,
getters
})
{
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
const
chat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
isMember
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
];
if
(
chatId
==
null
)
return
;
let
data
:
Message
[]
=
[];
const
cache
=
await
dbController
.
getChatMessages
(
chatId
);
if
(
cache
&&
cache
.
length
)
{
data
=
cache
;
const
getMessages
=
async
()
=>
{
const
o
=
{
model
:
chat
.
model_name
,
obj
:
chat
.
obj_id
,
isMember
,
};
data
=
await
xim
.
queryLastPageMsg
(
chatType
,
chatId
,
20
,
o
);
};
if
(
isMember
)
{
const
cache
=
await
dbController
.
getChatMessages
(
chatId
);
if
(
cache
&&
cache
.
length
)
{
data
=
cache
;
}
else
{
await
getMessages
();
}
}
else
{
data
=
await
xim
.
queryLastPageMsg
(
chatType
,
chatId
,
20
,
!
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
]
);
await
getMessages
();
}
try
{
commit
(
ChatStore
.
MUTATION_PUSH_CHAT_MSG_HISTORY
,
data
);
dbController
.
saveChatMessages
(
chatId
,
data
);
...
...
@@ -504,34 +515,46 @@ export default {
}
},
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES_BEFORE_SPECIFIC_ID
](
{
state
,
commit
},
{
state
,
commit
,
getters
},
msgId
:
Parameters
<
ChatStore
.
ACTION_GET_CHAT_MESSAGES_BEFORE_SPECIFIC_ID
>
[
0
]
)
{
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
if
(
chatId
==
null
)
return
;
const
chat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
o
=
{
model
:
chat
.
model_name
,
obj
:
chat
.
obj_id
,
isMember
:
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
],
};
const
data
=
await
xim
.
queryPrevPageMsg
(
chatType
,
chatId
,
msgId
,
10
,
!
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
]
o
);
commit
(
ChatStore
.
MUTATION_UNSHIFT_CHAT_MSG_HISTORY
,
data
);
dbController
.
appendMessages
(
chatId
,
data
);
return
data
;
},
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID
](
{
state
,
commit
},
{
state
,
commit
,
getters
},
msgId
:
Parameters
<
ChatStore
.
ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID
>
[
0
]
)
{
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
if
(
chatId
==
null
)
return
;
const
chat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
o
=
{
model
:
chat
.
model_name
,
obj
:
chat
.
obj_id
,
isMember
:
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
],
};
const
data
=
await
xim
.
queryNextPageMsg
(
chatType
,
chatId
,
msgId
,
10
,
!
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
]
o
);
commit
(
ChatStore
.
MUTATION_PUSH_CHAT_MSG_HISTORY
,
data
);
dbController
.
appendMessages
(
chatId
,
data
);
...
...
@@ -618,7 +641,12 @@ export default {
dispatch
(
ChatStore
.
ACTION_GET_MY_CHAT_LIST
);
return
chatId
;
},
async
[
ChatStore
.
ACTION_REGISTER_EVENT
]({
dispatch
,
commit
,
state
})
{
async
[
ChatStore
.
ACTION_REGISTER_EVENT
]({
dispatch
,
commit
,
state
,
getters
,
})
{
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
const
onNewMsg
=
(
e
:
Message
)
=>
{
if
(
e
.
chat_id
===
chatId
)
{
...
...
@@ -637,11 +665,21 @@ export default {
if
(
msgs
==
null
)
return
;
const
oldestMsgId
=
msgs
[
0
].
id
-
1
;
const
lastMsgId
=
msgs
[
msgs
.
length
-
1
].
id
+
1
;
const
chat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
o
=
{
model
:
chat
.
model_name
,
obj
:
chat
.
obj_id
,
isMember
:
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
],
};
const
freshMsgs
=
await
xim
.
queryMsgs
(
chatType
,
chatId
,
oldestMsgId
<
1
?
1
:
oldestMsgId
,
lastMsgId
lastMsgId
,
20
,
true
,
o
);
commit
(
ChatStore
.
MUTATION_CLEAR_CHAT_MSG_HISTORY
);
commit
(
...
...
xim/xim.ts
View file @
87ad0f2f
...
...
@@ -165,12 +165,16 @@ export class Xim {
lid
=
0
,
rid
=
0
,
limit
=
DefaultMsgPageSize
,
desc
=
true
desc
:
boolean
,
p
:
{
isMember
:
boolean
;
model
:
string
;
obj
:
string
}
):
Promise
<
Message
[]
>
{
this
.
checkConnected
();
if
(
this
.
client
==
null
)
{
throw
new
Error
(
"client shouldn't undefined"
);
}
if
(
!
p
.
isMember
&&
p
.
model
&&
p
.
obj
)
{
return
this
.
queryMessageWhenIsNotMember
(
p
,
limit
,
lid
,
rid
,
desc
);
}
const
res
=
await
this
.
client
.
fetchChatMsgs
(
chatType
,
chatId
,
{
lid
,
rid
,
...
...
@@ -180,6 +184,25 @@ export class Xim {
return
res
.
args
[
0
];
}
private
queryMessageWhenIsNotMember
(
p
:
{
isMember
:
boolean
;
model
:
string
;
obj
:
string
},
limit
:
number
,
lid
:
number
,
rid
:
number
,
desc
:
boolean
)
{
return
chat
.
getSdk
()
.
getAxios
()
.
get
(
`/general/xim/model/
${
p
.
model
}
/
${
p
.
obj
}
/msgs?lid=
${
lid
}
&rid=
${
rid
}
&limit=
${
limit
}
&desc=
${
desc
?
0
:
1
}
`
);
}
private
setMessagesRead
(
chatId
:
number
,
msg
:
Message
[])
{
if
(
msg
.
length
===
0
)
return
;
return
this
.
setRead
(
chatId
,
msg
[
0
].
id
,
msg
[
msg
.
length
-
1
].
id
);
...
...
@@ -190,10 +213,18 @@ export class Xim {
chatType
:
string
,
chatId
:
number
,
limit
:
number
,
notToRead
?:
boolean
p
:
{
isMember
:
boolean
;
model
:
string
;
obj
:
string
}
)
{
const
data
=
await
this
.
queryMsgs
(
chatType
,
chatId
,
0
,
0
,
limit
,
true
);
if
(
!
notToRead
)
{
const
data
=
await
this
.
queryMsgs
(
chatType
,
chatId
,
0
,
0
,
limit
,
true
,
p
);
if
(
p
&&
p
.
isMember
)
{
this
.
setMessagesRead
(
chatId
,
data
);
}
return
data
;
...
...
@@ -205,7 +236,7 @@ export class Xim {
chatId
:
number
,
msgId
:
number
,
limit
:
number
,
notToRead
?:
boolean
p
:
{
isMember
:
boolean
;
model
:
string
;
obj
:
string
}
)
{
const
data
=
await
this
.
queryMsgs
(
chatType
,
...
...
@@ -213,9 +244,10 @@ export class Xim {
0
,
msgId
,
limit
,
true
true
,
p
);
if
(
!
notToRead
)
{
if
(
p
&&
p
.
isMember
)
{
this
.
setMessagesRead
(
chatId
,
data
);
}
return
data
;
...
...
@@ -227,7 +259,7 @@ export class Xim {
chatId
:
number
,
msgId
:
number
,
limit
:
number
,
notToRead
?:
boolean
p
:
{
isMember
:
boolean
;
model
:
string
;
obj
:
string
}
)
{
const
data
=
await
this
.
queryMsgs
(
chatType
,
...
...
@@ -235,9 +267,10 @@ export class Xim {
msgId
,
0
,
limit
,
false
false
,
p
);
if
(
!
notToRead
)
{
if
(
p
&&
p
.
isMember
)
{
this
.
setMessagesRead
(
chatId
,
data
);
}
return
data
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment