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
96f65282
authored
Dec 29, 2021
by
zhousil
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'master' into pre
parents
3cefc4fd
06f2486e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
8 deletions
database/index.ts
model/im.ts
store/index.ts
store/model.ts
database/index.ts
View file @
96f65282
...
@@ -16,7 +16,7 @@ class ChatCacheDatabaseController {
...
@@ -16,7 +16,7 @@ class ChatCacheDatabaseController {
private
setuping
=
false
;
private
setuping
=
false
;
private
setupError
=
false
;
private
setupError
=
false
;
public
readonly
historyOrderModelName
=
'order_info'
;
public
readonly
historyOrderModelName
=
"order_info"
;
private
waitSetupCompleted
()
{
private
waitSetupCompleted
()
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
...
@@ -459,6 +459,47 @@ class ChatCacheDatabaseController {
...
@@ -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
();
export
const
dbController
=
new
ChatCacheDatabaseController
();
model/im.ts
View file @
96f65282
This diff is collapsed.
Click to expand it.
store/index.ts
View file @
96f65282
...
@@ -32,7 +32,7 @@ function uniqueMessages(
...
@@ -32,7 +32,7 @@ function uniqueMessages(
messages
:
NonNullable
<
ChatStore
.
STATE_CHAT_MSG_HISTORY
>
messages
:
NonNullable
<
ChatStore
.
STATE_CHAT_MSG_HISTORY
>
)
{
)
{
const
arr
=
[...
messages
];
const
arr
=
[...
messages
];
return
unique
(
arr
,
function
(
item
,
all
)
{
return
unique
(
arr
,
function
(
item
,
all
)
{
return
all
.
findIndex
((
k
)
=>
k
.
id
===
item
.
id
);
return
all
.
findIndex
((
k
)
=>
k
.
id
===
item
.
id
);
});
});
}
}
...
@@ -138,6 +138,8 @@ function clearAction(value: ChatType[]) {
...
@@ -138,6 +138,8 @@ function clearAction(value: ChatType[]) {
return
value
;
return
value
;
}
}
let
synced
=
false
;
export
default
{
export
default
{
namespaced
:
true
,
namespaced
:
true
,
state
:
()
=>
({
state
:
()
=>
({
...
@@ -366,7 +368,7 @@ export default {
...
@@ -366,7 +368,7 @@ export default {
state
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
]
=
[...
current
];
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
}
=
{};
const
setTimeoutId
:
{
[
key
:
string
]:
number
}
=
{};
return
(
return
(
state
:
ChatStoreState
,
state
:
ChatStoreState
,
...
@@ -426,6 +428,8 @@ export default {
...
@@ -426,6 +428,8 @@ export default {
async
[
ChatStore
.
ACTION_GET_MY_CHAT_LIST
]({
commit
,
dispatch
})
{
async
[
ChatStore
.
ACTION_GET_MY_CHAT_LIST
]({
commit
,
dispatch
})
{
commit
(
ChatStore
.
MUTATION_SAVE_MYSELF_ID
);
commit
(
ChatStore
.
MUTATION_SAVE_MYSELF_ID
);
await
dispatch
(
ChatStore
.
ACTION_SYNC_MY_CHAT_LIST
);
if
(
loadingChatList
)
{
if
(
loadingChatList
)
{
return
new
Promise
<
ChatType
[]
>
((
resolve
)
=>
return
new
Promise
<
ChatType
[]
>
((
resolve
)
=>
cachedLoadingChatListAction
.
push
(
resolve
)
cachedLoadingChatListAction
.
push
(
resolve
)
...
@@ -520,6 +524,27 @@ export default {
...
@@ -520,6 +524,27 @@ export default {
return
await
execute
().
then
((
d
)
=>
clearAction
(
d
));
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
})
{
async
[
ChatStore
.
ACTION_FORCE_RELOAD_CHAT_LIST
]({
commit
})
{
return
new
Promise
<
ChatType
[]
>
((
resolve
)
=>
{
return
new
Promise
<
ChatType
[]
>
((
resolve
)
=>
{
Chat
.
onReady
(()
=>
{
Chat
.
onReady
(()
=>
{
...
@@ -940,7 +965,7 @@ export default {
...
@@ -940,7 +965,7 @@ export default {
}
}
commit
(
commit
(
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_MEMBERS
,
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_MEMBERS
,
unique
(
newChatMembers
,
function
(
item
,
all
)
{
unique
(
newChatMembers
,
function
(
item
,
all
)
{
return
all
.
findIndex
((
k
)
=>
k
.
eid
===
item
.
eid
);
return
all
.
findIndex
((
k
)
=>
k
.
eid
===
item
.
eid
);
})
})
);
);
...
@@ -1197,8 +1222,8 @@ export default {
...
@@ -1197,8 +1222,8 @@ export default {
p
.
read_count
=
option
.
all
p
.
read_count
=
option
.
all
?
p
.
total_read_count
?
p
.
total_read_count
:
option
.
readed
:
option
.
readed
?
option
.
readed
?
option
.
readed
:
p
.
read_count
+
1
;
:
p
.
read_count
+
1
;
}
}
}
}
}
else
{
}
else
{
...
@@ -1207,8 +1232,8 @@ export default {
...
@@ -1207,8 +1232,8 @@ export default {
p
.
read_count
=
option
.
all
p
.
read_count
=
option
.
all
?
p
.
total_read_count
?
p
.
total_read_count
:
option
.
readed
:
option
.
readed
?
option
.
readed
?
option
.
readed
:
p
.
read_count
+
1
;
:
p
.
read_count
+
1
;
}
}
}
}
}
}
...
...
store/model.ts
View file @
96f65282
...
@@ -247,6 +247,9 @@ export namespace ChatStore {
...
@@ -247,6 +247,9 @@ export namespace ChatStore {
keyword
?:
string
keyword
?:
string
)
=>
Promise
<
ChatType
[]
>
;
)
=>
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
const
ACTION_FORCE_RELOAD_CHAT_LIST
=
"重新获取我的会话列表"
;
export
type
ACTION_FORCE_RELOAD_CHAT_LIST
=
()
=>
Promise
<
ChatType
[]
>
;
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