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
8b24464a
authored
Dec 23, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update db
parent
00d93de0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
37 deletions
database/index.ts
model/index.ts
store/index.ts
xim/xim.ts
database/index.ts
View file @
8b24464a
...
...
@@ -32,16 +32,17 @@ class ChatCacheDatabaseController {
}
public
setup
(
uid
:
string
)
{
if
(
this
.
db
)
{
return
Promise
.
resolve
();
}
if
(
this
.
setuping
)
{
return
this
.
waitSetupCompleted
();
}
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
if
(
uid
&&
indexedDB
)
{
this
.
setuping
=
true
;
const
r
=
indexedDB
.
open
(
"u-"
+
(
this
.
uid
=
uid
),
this
.
listVersion
);
const
key
=
"u-"
+
(
this
.
uid
=
uid
);
const
r
=
indexedDB
.
open
(
key
,
this
.
listVersion
);
const
setupDb
=
()
=>
{
if
(
this
.
setuping
)
{
if
(
this
.
db
)
{
...
...
@@ -99,17 +100,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
}
`
);
...
...
model/index.ts
View file @
8b24464a
...
...
@@ -195,6 +195,7 @@ export interface BaseChatItem extends BaseChatItemBusinessData {
create_time
:
number
;
update_time
:
number
;
last_msg_ts
:
number
;
last_msg_sender
:
string
;
members_updated
:
number
;
user_updated
:
number
;
}
...
...
store/index.ts
View file @
8b24464a
...
...
@@ -94,6 +94,10 @@ function buildChatItem(chat: RawChatItem) {
const
b
=
JSON
.
parse
(
chat
.
business_data
)
as
BaseChatItemBusinessData
;
b
.
detail_name
&&
(
chat
.
detail_name
=
b
.
detail_name
);
}
// 系统发的自动消息,重新校准未读消息数为0
if
(
!+
chat
.
last_msg_sender
&&
chat
.
msg_id
===
1
)
{
chat
.
unread_msg_count
=
0
;
}
return
{
...
chat
,
chat_id
:
chat
.
id
}
as
ChatType
;
}
...
...
@@ -553,29 +557,25 @@ export default {
},
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES
]({
state
,
commit
,
getters
})
{
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
const
chat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
const
chat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
const
isMember
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
];
if
(
!
chatId
)
return
;
let
data
:
Message
[]
=
[];
const
getMessages
=
async
()
=>
{
const
o
=
{
const
getMessages
=
async
()
=>
await
xim
.
queryLastPageMsg
(
chatType
,
chatId
,
20
,
{
model
:
chat
.
model_name
,
obj
:
chat
.
obj_id
,
isMember
,
};
data
=
await
xim
.
queryLastPageMsg
(
chatType
,
chatId
,
20
,
o
);
};
});
if
(
isMember
)
{
const
cache
=
await
dbController
.
getChatMessages
(
chatId
);
if
(
cache
&&
cache
.
length
)
{
data
=
cache
;
}
else
{
await
getMessages
();
data
=
await
getMessages
();
}
}
else
{
await
getMessages
();
data
=
await
getMessages
();
}
try
{
...
...
@@ -614,7 +614,7 @@ export default {
dbController
.
appendMessages
(
chatId
,
data
);
return
data
;
},
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID
](
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID
](
{
state
,
commit
,
getters
},
msgId
:
Parameters
<
ChatStore
.
ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID
>
[
0
]
)
{
...
...
@@ -639,7 +639,7 @@ export default {
dbController
.
appendMessages
(
chatId
,
data
);
return
data
;
},
async
[
ChatStore
.
ACTION_SEND_MESSAGE
](
async
[
ChatStore
.
ACTION_SEND_MESSAGE
](
{
state
,
dispatch
,
getters
,
commit
},
params
:
Parameters
<
ChatStore
.
ACTION_SEND_MESSAGE
>
[
0
]
)
{
...
...
@@ -667,7 +667,7 @@ export default {
return
Promise
.
reject
(
error
);
}
},
async
[
ChatStore
.
ACTION_GET_FRESH_MESSAGE
]({
async
[
ChatStore
.
ACTION_GET_FRESH_MESSAGE
]({
state
,
dispatch
,
commit
,
...
...
@@ -687,7 +687,7 @@ export default {
await
preCacheImgs
(
newMsgsArr
);
commit
(
ChatStore
.
MUTATION_SCROLL_TO_BOTTOM
);
},
async
[
ChatStore
.
ACTION_CREATE_NEW_CHAT_BY_SERVICE_MAN
](
async
[
ChatStore
.
ACTION_CREATE_NEW_CHAT_BY_SERVICE_MAN
](
{
commit
,
dispatch
},
params
:
Parameters
<
ChatStore
.
ACTION_CREATE_NEW_CHAT_BY_SERVICE_MAN
>
[
0
]
)
{
...
...
@@ -704,7 +704,7 @@ export default {
);
return
{
chatId
,
catalog
};
},
async
[
ChatStore
.
ACTION_CREATE_NEW_CHAT_BY_CLIENT
](
async
[
ChatStore
.
ACTION_CREATE_NEW_CHAT_BY_CLIENT
](
{
commit
,
dispatch
},
params
:
Parameters
<
ChatStore
.
ACTION_CREATE_NEW_CHAT_BY_CLIENT
>
[
0
]
)
{
...
...
@@ -722,7 +722,7 @@ export default {
dispatch
(
ChatStore
.
ACTION_GET_MY_CHAT_LIST
);
return
chatId
;
},
async
[
ChatStore
.
ACTION_REGISTER_EVENT
]({
async
[
ChatStore
.
ACTION_REGISTER_EVENT
]({
dispatch
,
commit
,
state
,
...
...
@@ -732,7 +732,7 @@ export default {
const
onNewMsg
=
(
e
:
Message
)
=>
{
const
thenAction
=
()
=>
{
if
(
e
.
type
===
MessageType
.
Withdraw
)
{
commit
(
ChatStore
.
MUTATION_WITHDRAW
,
[
+
e
.
msg
]);
commit
(
ChatStore
.
MUTATION_WITHDRAW
,
e
.
msg
.
startsWith
(
'['
)
?
JSON
.
parse
(
e
.
msg
)
:
[
+
e
.
msg
]);
}
const
scroll
=
()
=>
state
[
ChatStore
.
STATE_FUNC_ON_NEW_MSG
](
e
);
...
...
@@ -813,7 +813,7 @@ export default {
xim
.
on
(
"chat_notify"
,
"read"
,
onMsgRead
);
xim
.
on
(
"chat_notify"
,
"user.input"
,
onInputing
);
},
async
[
ChatStore
.
ACTION_SAVE_CURRENT_CHAT_ID_VERSION
](
async
[
ChatStore
.
ACTION_SAVE_CURRENT_CHAT_ID_VERSION
](
{
state
,
commit
,
dispatch
},
chatId
:
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
)
{
...
...
@@ -879,7 +879,7 @@ export default {
commit
(
ChatStore
.
MUTATION_SCROLL_TO_BOTTOM
);
(
<
any
>
state
)[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_ERROR
]
=
null
;
},
async
[
ChatStore
.
ACTION_CLEAR_CURRENT_CHAT_DATA
]({
commit
,
state
})
{
async
[
ChatStore
.
ACTION_CLEAR_CURRENT_CHAT_DATA
]({
commit
,
state
})
{
commit
(
ChatStore
.
MUTATION_CLEAR_CURRENT_CHAT_ID
);
commit
(
ChatStore
.
MUTATION_CLEAR_MYSELF_ID
);
commit
(
ChatStore
.
MUTATION_CLEAR_CHAT_MSG_HISTORY
);
...
...
@@ -887,7 +887,7 @@ export default {
commit
(
ChatStore
.
MUTATION_CLEAR_CURRENT_CHAT_MEMBERS
);
(
<
any
>
state
)[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_ERROR
]
=
null
;
},
async
[
ChatStore
.
ACTION_GET_CHAT_MEMBERS
]({
commit
,
state
})
{
async
[
ChatStore
.
ACTION_GET_CHAT_MEMBERS
]({
commit
,
state
})
{
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
if
(
!
chatId
)
return
;
const
getChatMembersResult
=
await
xim
.
fetchChatMembers
(
chatId
);
...
...
@@ -930,7 +930,7 @@ export default {
})
);
},
async
[
ChatStore
.
ACTION_TERINATE_CHAT
]({
state
,
dispatch
})
{
async
[
ChatStore
.
ACTION_TERINATE_CHAT
]({
state
,
dispatch
})
{
const
v
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_VERSION
];
if
(
v
==
null
)
return
;
const
id
=
Number
(
...
...
@@ -958,7 +958,7 @@ export default {
firstChat
.
chat_id
);
},
async
[
ChatStore
.
ACTION_CHAT_START_RECEPTION
]({
getters
,
dispatch
})
{
async
[
ChatStore
.
ACTION_CHAT_START_RECEPTION
]({
getters
,
dispatch
})
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
...
...
@@ -982,7 +982,7 @@ export default {
);
});
},
async
[
ChatStore
.
ACTION_CHAT_FINISH_RECEPTION
]({
getters
,
dispatch
})
{
async
[
ChatStore
.
ACTION_CHAT_FINISH_RECEPTION
]({
getters
,
dispatch
})
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
...
...
@@ -999,7 +999,7 @@ export default {
.
finishChat
()
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
},
async
[
ChatStore
.
ACTION_CHAT_USER_EXIT
]({
getters
,
dispatch
})
{
async
[
ChatStore
.
ACTION_CHAT_USER_EXIT
]({
getters
,
dispatch
})
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
...
...
@@ -1017,7 +1017,7 @@ export default {
.
userExitChat
()
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
},
async
[
ChatStore
.
ACTION_CHAT_CS_EXIT
]({
getters
,
dispatch
})
{
async
[
ChatStore
.
ACTION_CHAT_CS_EXIT
]({
getters
,
dispatch
})
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
...
...
@@ -1035,7 +1035,7 @@ export default {
.
csExitChat
()
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
},
async
[
ChatStore
.
ACTION_CHAT_ADD_MEMBERS
](
async
[
ChatStore
.
ACTION_CHAT_ADD_MEMBERS
](
{
getters
,
dispatch
},
uids
:
Parameters
<
ChatStore
.
ACTION_CHAT_ADD_MEMBERS
>
[
0
]
)
{
...
...
@@ -1055,7 +1055,7 @@ export default {
.
addMember
(
uids
.
map
((
id
)
=>
+
id
))
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
},
async
[
ChatStore
.
ACTION_CHAT_REMOVE_MEMBER
](
async
[
ChatStore
.
ACTION_CHAT_REMOVE_MEMBER
](
{
getters
,
dispatch
},
uids
:
Parameters
<
ChatStore
.
ACTION_CHAT_REMOVE_MEMBER
>
[
0
]
)
{
...
...
@@ -1075,7 +1075,7 @@ export default {
.
removeMember
(
uids
.
map
((
id
)
=>
+
id
))
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
},
async
[
ChatStore
.
ACTION_CHAT_ADD_CS
](
async
[
ChatStore
.
ACTION_CHAT_ADD_CS
](
{
getters
,
dispatch
},
uids
:
Parameters
<
ChatStore
.
ACTION_CHAT_ADD_CS
>
[
0
]
)
{
...
...
@@ -1095,7 +1095,7 @@ export default {
.
addCs
(
uids
.
map
((
id
)
=>
Number
(
id
)))
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
},
async
[
ChatStore
.
ACTION_CHAT_REMOVE_CS
](
async
[
ChatStore
.
ACTION_CHAT_REMOVE_CS
](
{
getters
,
dispatch
},
uids
:
Parameters
<
ChatStore
.
ACTION_CHAT_REMOVE_CS
>
[
0
]
)
{
...
...
xim/xim.ts
View file @
8b24464a
...
...
@@ -200,7 +200,9 @@ export class Xim {
}
private
setMessagesRead
(
chatId
:
number
,
msg
:
Message
[])
{
if
(
msg
.
length
===
0
)
return
;
if
(
!
msg
.
length
)
{
return
this
.
setRead
(
chatId
,
1
,
1
);
}
return
this
.
setRead
(
chatId
,
msg
[
0
].
id
,
msg
[
msg
.
length
-
1
].
id
);
}
...
...
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