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
c7763c7d
authored
Dec 16, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'master' of
http://gitlab.corp.qinqinxiaobao.com:9880/uniplat/customer-service
parents
13f3b8a0
da956e5a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
13 deletions
database/index.ts
database/index.ts
View file @
c7763c7d
...
...
@@ -14,12 +14,13 @@ class ChatCacheDatabaseController {
private
readonly
chatMessageKey
=
"chat-message"
;
private
setuping
=
false
;
private
setupError
=
false
;
private
waitSetupCompleted
()
{
return
new
Promise
<
void
>
((
resolve
)
=>
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
const
checker
=
()
=>
{
if
(
!
this
.
setuping
)
{
resolve
();
this
.
setupError
?
reject
(
new
Error
(
`IM index database setup failed`
))
:
resolve
();
}
else
{
setTimeout
(()
=>
checker
(),
200
);
}
...
...
@@ -32,43 +33,45 @@ class ChatCacheDatabaseController {
if
(
this
.
setuping
)
{
return
this
.
waitSetupCompleted
();
}
return
new
Promise
<
void
>
((
resolve
)
=>
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
if
(
uid
&&
indexedDB
)
{
this
.
setuping
=
true
;
const
r
=
indexedDB
.
open
(
"u-"
+
(
this
.
uid
=
uid
),
this
.
listVersion
);
// eslint-disable-next-line @typescript-eslint/no-this-alias
const
that
=
this
;
const
setupDb
=
()
=>
{
if
(
this
.
setuping
)
{
if
(
th
at
.
db
)
{
if
(
th
is
.
db
)
{
try
{
th
at
.
buildTables
(
that
.
db
,
that
.
chatListKey
);
th
is
.
buildTables
(
this
.
db
,
this
.
chatListKey
);
console
.
log
(
`build index database for chat completed, 100%`
);
}
catch
(
e
)
{
this
.
setupError
=
true
;
console
.
error
(
e
);
reject
();
}
}
this
.
setuping
=
false
;
}
resolve
();
};
r
.
onsuccess
=
function
(
e
)
{
th
at
.
db
=
(
e
.
target
as
any
).
result
;
r
.
onsuccess
=
(
e
)
=>
{
th
is
.
db
=
(
e
.
target
as
any
).
result
;
console
.
log
(
`index database init comepleted`
);
setupDb
();
};
r
.
onupgradeneeded
=
function
(
e
)
{
th
at
.
db
=
(
e
.
target
as
any
).
result
;
r
.
onupgradeneeded
=
(
e
)
=>
{
th
is
.
db
=
(
e
.
target
as
any
).
result
;
console
.
log
(
`upgrade database comepleted`
);
setupDb
();
};
r
.
onerror
=
function
(
e
)
{
r
.
onerror
=
(
e
)
=>
{
console
.
log
(
`index database init failed,
${
e
}
`
);
this
.
setupError
=
true
;
reject
();
};
}
else
{
resolve
();
...
...
@@ -128,7 +131,11 @@ class ChatCacheDatabaseController {
}
private
buildTransaction
(
key
:
string
)
{
return
this
.
db
.
transaction
(
key
,
"readwrite"
);
try
{
return
this
.
db
.
transaction
(
key
,
"readwrite"
);
}
catch
{
window
.
location
.
reload
();
throw
new
Error
(
`transition failed`
);
}
}
private
buildStore
(
key
:
string
)
{
...
...
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