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
24ca3954
authored
Dec 29, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
sync
parent
dfd573d1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
7 deletions
database/index.ts
store/index.ts
store/model.ts
database/index.ts
View file @
24ca3954
...
...
@@ -16,7 +16,7 @@ class ChatCacheDatabaseController {
private
setuping
=
false
;
private
setupError
=
false
;
public
readonly
historyOrderModelName
=
'order_info'
;
public
readonly
historyOrderModelName
=
"order_info"
;
private
waitSetupCompleted
()
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
...
...
@@ -102,17 +102,17 @@ class ChatCacheDatabaseController {
}
setTimeout
(()
=>
resolve
(),
200
);
};
r
.
onsuccess
=
function
(
e
)
{
r
.
onsuccess
=
function
(
e
)
{
const
db
=
(
e
.
target
as
any
).
result
;
that
.
messageDatabases
.
set
(
k
,
db
);
setupDb
();
};
r
.
onupgradeneeded
=
function
(
e
)
{
r
.
onupgradeneeded
=
function
(
e
)
{
const
db
=
(
e
.
target
as
any
).
result
;
that
.
messageDatabases
.
set
(
k
,
db
);
setupDb
();
};
r
.
onerror
=
function
(
e
)
{
r
.
onerror
=
function
(
e
)
{
console
.
log
(
`chat message index database init failed,
${
e
}
`
);
...
...
@@ -459,6 +459,47 @@ class ChatCacheDatabaseController {
});
});
}
public
syncChats
(
chats
:
number
[])
{
return
new
Promise
<
void
>
((
resolve
)
=>
{
if
(
this
.
db
)
{
this
.
getChatList
().
then
((
r
)
=>
{
const
set
=
new
Set
<
number
>
(
chats
);
let
finished
=
0
;
let
removing
=
[];
for
(
const
item
of
r
)
{
if
(
!
set
.
has
(
item
.
id
))
{
removing
.
push
(
item
.
id
);
}
}
for
(
const
item
of
removing
)
{
this
.
removeChatAndMessages
(
item
).
finally
(()
=>
{
finished
++
;
if
(
finished
===
removing
.
length
)
{
resolve
();
}
});
}
!
removing
.
length
&&
resolve
();
});
}
});
}
private
removeChatAndMessages
(
chat
:
number
)
{
this
.
setupChatMessageDatabase
(
chat
).
finally
(()
=>
{
const
store
=
this
.
buildChatMessageStore
(
chat
);
const
r
=
store
.
clear
();
r
.
onsuccess
=
()
=>
{
indexedDB
.
deleteDatabase
(
this
.
buildChatMessageKey
(
chat
));
};
});
return
this
.
removeChatFromList
(
chat
);
}
}
export
const
dbController
=
new
ChatCacheDatabaseController
();
store/index.ts
View file @
24ca3954
...
...
@@ -32,7 +32,7 @@ function uniqueMessages(
messages
:
NonNullable
<
ChatStore
.
STATE_CHAT_MSG_HISTORY
>
)
{
const
arr
=
[...
messages
];
return
unique
(
arr
,
function
(
item
,
all
)
{
return
unique
(
arr
,
function
(
item
,
all
)
{
return
all
.
findIndex
((
k
)
=>
k
.
id
===
item
.
id
);
});
}
...
...
@@ -138,6 +138,8 @@ function clearAction(value: ChatType[]) {
return
value
;
}
let
synced
=
false
;
export
default
{
namespaced
:
true
,
state
:
()
=>
({
...
...
@@ -366,7 +368,7 @@ export default {
state
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
]
=
[...
current
];
}
},
[
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_INPUTING
]:
(
function
()
{
[
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_INPUTING
]:
(
function
()
{
const
setTimeoutId
:
{
[
key
:
string
]:
number
}
=
{};
return
(
state
:
ChatStoreState
,
...
...
@@ -426,6 +428,8 @@ export default {
async
[
ChatStore
.
ACTION_GET_MY_CHAT_LIST
]({
commit
,
dispatch
})
{
commit
(
ChatStore
.
MUTATION_SAVE_MYSELF_ID
);
await
dispatch
(
ChatStore
.
ACTION_SYNC_MY_CHAT_LIST
);
if
(
loadingChatList
)
{
return
new
Promise
<
ChatType
[]
>
((
resolve
)
=>
cachedLoadingChatListAction
.
push
(
resolve
)
...
...
@@ -520,6 +524,27 @@ export default {
return
await
execute
().
then
((
d
)
=>
clearAction
(
d
));
},
async
[
ChatStore
.
ACTION_SYNC_MY_CHAT_LIST
]()
{
if
(
synced
)
{
return
Promise
.
resolve
();
}
return
new
Promise
<
void
>
((
resolve
)
=>
Chat
.
onReady
(()
=>
{
synced
=
true
;
xim
.
fetchChatList
()
.
then
((
data
)
=>
{
dbController
.
syncChats
(
(
data
.
args
[
0
]
as
RawChatItem
[]).
map
(
(
i
)
=>
i
.
id
)
)
.
finally
(
resolve
);
})
.
catch
(
resolve
);
})
);
},
async
[
ChatStore
.
ACTION_FORCE_RELOAD_CHAT_LIST
]({
commit
})
{
return
new
Promise
<
ChatType
[]
>
((
resolve
)
=>
{
Chat
.
onReady
(()
=>
{
...
...
@@ -940,7 +965,7 @@ export default {
}
commit
(
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_MEMBERS
,
unique
(
newChatMembers
,
function
(
item
,
all
)
{
unique
(
newChatMembers
,
function
(
item
,
all
)
{
return
all
.
findIndex
((
k
)
=>
k
.
eid
===
item
.
eid
);
})
);
...
...
store/model.ts
View file @
24ca3954
...
...
@@ -247,6 +247,9 @@ export namespace ChatStore {
keyword
?:
string
)
=>
Promise
<
ChatType
[]
>
;
export
const
ACTION_SYNC_MY_CHAT_LIST
=
"同步我的会话列表"
;
export
type
ACTION_SYNC_MY_CHAT_LIST
=
()
=>
void
;
export
const
ACTION_FORCE_RELOAD_CHAT_LIST
=
"重新获取我的会话列表"
;
export
type
ACTION_FORCE_RELOAD_CHAT_LIST
=
()
=>
Promise
<
ChatType
[]
>
;
...
...
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