Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fns_front_2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenqikuai
fns_front_2
Commits
135bc242
Commit
135bc242
authored
Oct 29, 2021
by
chenqikuai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
如果由于网络问题消息没有发送出去,就再下一次连接成功时,再次发送
parent
1f87fb1e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
4 deletions
+49
-4
App.vue
src/App.vue
+2
-1
ChatMessageDB.ts
src/db/ChatMessageDB.ts
+22
-2
messagesStore.ts
src/store/messagesStore.ts
+2
-0
chatutils.ts
src/utils/chatutils.ts
+23
-1
No files found.
src/App.vue
View file @
135bc242
...
...
@@ -27,7 +27,7 @@ import { generateToken } from "./utils/generateToken/generate-token";
import
{
defineComponent
,
nextTick
,
onBeforeMount
,
onBeforeUnmount
,
onMounted
,
onUnmounted
,
watch
}
from
"vue"
;
import
decodeChatMessage
from
"./utils/fzm-message-protocol-chat/decodeChatMessage"
;
import
ChatDBService
from
"@/db/ChatDBService"
import
{
getMasterIdFromDisplayMsg
,
getTargetIdFromDisplayMsg
}
from
"./utils/chatutils"
;
import
{
checkPendingMsgAndSendIt
,
getMasterIdFromDisplayMsg
,
getTargetIdFromDisplayMsg
}
from
"./utils/chatutils"
;
import
isChattingWith
from
"./utils/isChattingWith"
;
import
{
ChatMessageTypes
}
from
"@/types/chatMessageTypes"
import
{
chatCardTimeStamp
}
from
"./store/chatCardStore"
;
...
...
@@ -126,6 +126,7 @@ export default defineComponent({
})
.
then
((
conn
)
=>
{
connectionState
.
connection
=
conn
;
checkPendingMsgAndSendIt
();
})
.
catch
((
reason
)
=>
{
initError
.
value
=
true
;
...
...
src/db/ChatMessageDB.ts
View file @
135bc242
...
...
@@ -19,6 +19,18 @@ export default class ChatMessageDB extends MyAppDatabase {
.
reverse
()
.
first
()
/* 若消息已存在,则更新状态,否则,添加 */
const
msgExist
=
(
await
this
.
chatMessage
.
filter
((
i
)
=>
i
.
uuid
===
message
.
uuid
)
.
count
())
===
1
console
.
log
(
msgExist
,
'msgExist'
)
if
(
msgExist
)
{
return
this
.
chatMessage
.
filter
((
i
)
=>
i
.
uuid
===
message
.
uuid
)
.
modify
((
i
)
=>
(
i
.
state
=
message
.
state
))
}
else
{
return
this
.
chatMessage
.
add
({
...
message
,
masterId
,
...
...
@@ -28,6 +40,7 @@ export default class ChatMessageDB extends MyAppDatabase {
),
})
}
}
async
deleteMsg
({
uuid
,
logid
}:
{
uuid
?:
string
;
logid
?:
string
})
{
const
updateChatList
=
async
(
...
...
@@ -97,8 +110,9 @@ export default class ChatMessageDB extends MyAppDatabase {
(
await
this
.
chatMessage
.
filter
(
(
i
)
=>
(
i
.
masterId
===
masterId
&&
((
i
.
state
===
null
&&
i
.
from
===
personId
)
||
(
i
.
state
!==
null
&&
i
.
target
===
personId
)))
i
.
masterId
===
masterId
&&
((
i
.
state
===
null
&&
i
.
from
===
personId
)
||
(
i
.
state
!==
null
&&
i
.
target
===
personId
)),
)
.
count
())
!==
0
)
...
...
@@ -117,6 +131,12 @@ export default class ChatMessageDB extends MyAppDatabase {
.
toArray
()
}
getPendingMessage
(
masterId
:
string
)
{
return
this
.
chatMessage
.
filter
((
i
)
=>
i
.
masterId
===
masterId
&&
i
.
state
===
'pending'
)
.
toArray
()
}
/* wo获取和ta之间最新的消息 */
async
getLatestedMessage
(
from
:
string
,
target
:
string
)
{
const
ret
=
await
this
.
chatMessage
...
...
src/store/messagesStore.ts
View file @
135bc242
...
...
@@ -325,6 +325,8 @@ class MessageStore {
})
.
catch
(()
=>
{
message
.
state
=
'failure'
console
.
log
(
'failure!!!'
);
ChatMessageDB
.
getInstance
().
updateMsg
(
{
logid
:
message
.
logid
,
...
...
src/utils/chatutils.ts
View file @
135bc242
import
{
DisplayMessage
}
from
'@/store/messagesStore'
import
ChatMessageDB
from
'@/db/ChatMessageDB'
import
{
DisplayMessage
,
messageStore
}
from
'@/store/messagesStore'
import
{
getUserMsg
}
from
'./userMsg'
export
function
getMasterIdFromDisplayMsg
(
msg
:
DisplayMessage
)
{
if
(
!
msg
.
state
)
{
...
...
@@ -15,3 +17,23 @@ export function getTargetIdFromDisplayMsg(msg: DisplayMessage) {
return
msg
.
target
as
string
}
}
export
async
function
checkPendingMsgAndSendIt
()
{
console
.
log
(
'检查pending的消息,然后发送'
)
const
addr
=
getUserMsg
()?.
userInfo
.
addr
if
(
addr
)
{
const
pendingMessageList
=
await
ChatMessageDB
.
getInstance
().
getPendingMessage
(
addr
,
)
pendingMessageList
.
forEach
((
i
)
=>
{
messageStore
.
sendMessage
({
// ...i,
type
:
i
.
type
,
content
:
i
.
content
,
target
:
i
.
target
as
string
,
uuid
:
i
.
uuid
,
})
})
}
}
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