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
Show 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 {
...
@@ -14,12 +14,13 @@ class ChatCacheDatabaseController {
private
readonly
chatMessageKey
=
"chat-message"
;
private
readonly
chatMessageKey
=
"chat-message"
;
private
setuping
=
false
;
private
setuping
=
false
;
private
setupError
=
false
;
private
waitSetupCompleted
()
{
private
waitSetupCompleted
()
{
return
new
Promise
<
void
>
((
resolve
)
=>
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
const
checker
=
()
=>
{
const
checker
=
()
=>
{
if
(
!
this
.
setuping
)
{
if
(
!
this
.
setuping
)
{
resolve
();
this
.
setupError
?
reject
(
new
Error
(
`IM index database setup failed`
))
:
resolve
();
}
else
{
}
else
{
setTimeout
(()
=>
checker
(),
200
);
setTimeout
(()
=>
checker
(),
200
);
}
}
...
@@ -32,43 +33,45 @@ class ChatCacheDatabaseController {
...
@@ -32,43 +33,45 @@ class ChatCacheDatabaseController {
if
(
this
.
setuping
)
{
if
(
this
.
setuping
)
{
return
this
.
waitSetupCompleted
();
return
this
.
waitSetupCompleted
();
}
}
return
new
Promise
<
void
>
((
resolve
)
=>
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
if
(
uid
&&
indexedDB
)
{
if
(
uid
&&
indexedDB
)
{
this
.
setuping
=
true
;
this
.
setuping
=
true
;
const
r
=
indexedDB
.
open
(
const
r
=
indexedDB
.
open
(
"u-"
+
(
this
.
uid
=
uid
),
"u-"
+
(
this
.
uid
=
uid
),
this
.
listVersion
this
.
listVersion
);
);
// eslint-disable-next-line @typescript-eslint/no-this-alias
const
that
=
this
;
const
setupDb
=
()
=>
{
const
setupDb
=
()
=>
{
if
(
this
.
setuping
)
{
if
(
this
.
setuping
)
{
if
(
th
at
.
db
)
{
if
(
th
is
.
db
)
{
try
{
try
{
th
at
.
buildTables
(
that
.
db
,
that
.
chatListKey
);
th
is
.
buildTables
(
this
.
db
,
this
.
chatListKey
);
console
.
log
(
console
.
log
(
`build index database for chat completed, 100%`
`build index database for chat completed, 100%`
);
);
}
catch
(
e
)
{
}
catch
(
e
)
{
this
.
setupError
=
true
;
console
.
error
(
e
);
console
.
error
(
e
);
reject
();
}
}
}
}
this
.
setuping
=
false
;
this
.
setuping
=
false
;
}
}
resolve
();
resolve
();
};
};
r
.
onsuccess
=
function
(
e
)
{
r
.
onsuccess
=
(
e
)
=>
{
th
at
.
db
=
(
e
.
target
as
any
).
result
;
th
is
.
db
=
(
e
.
target
as
any
).
result
;
console
.
log
(
`index database init comepleted`
);
console
.
log
(
`index database init comepleted`
);
setupDb
();
setupDb
();
};
};
r
.
onupgradeneeded
=
function
(
e
)
{
r
.
onupgradeneeded
=
(
e
)
=>
{
th
at
.
db
=
(
e
.
target
as
any
).
result
;
th
is
.
db
=
(
e
.
target
as
any
).
result
;
console
.
log
(
`upgrade database comepleted`
);
console
.
log
(
`upgrade database comepleted`
);
setupDb
();
setupDb
();
};
};
r
.
onerror
=
function
(
e
)
{
r
.
onerror
=
(
e
)
=>
{
console
.
log
(
`index database init failed,
${
e
}
`
);
console
.
log
(
`index database init failed,
${
e
}
`
);
this
.
setupError
=
true
;
reject
();
};
};
}
else
{
}
else
{
resolve
();
resolve
();
...
@@ -128,7 +131,11 @@ class ChatCacheDatabaseController {
...
@@ -128,7 +131,11 @@ class ChatCacheDatabaseController {
}
}
private
buildTransaction
(
key
:
string
)
{
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
)
{
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