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
7abbf4ee
authored
Dec 23, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'master' into pre
parents
257f730d
8b24464a
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
31 deletions
components/message-list.vue
components/message.vue
database/index.ts
model/index.ts
store/index.ts
store/model.ts
xim/xim.ts
components/message-list.vue
View file @
7abbf4ee
...
@@ -191,9 +191,10 @@
...
@@ -191,9 +191,10 @@
this
.
handleScrollWrapper
();
this
.
handleScrollWrapper
();
this
.
onNewMessage
((
e
)
=>
{
this
.
onNewMessage
((
e
)
=>
{
if
(
e
.
type
===
MessageType
.
Withdraw
)
{
if
(
e
.
type
===
MessageType
.
Withdraw
)
{
this
.
executeWithDraw
(
e
.
ref_id
);
const
ids
=
e
.
ref_id
?
[
e
.
ref_id
]
:
JSON
.
parse
(
e
.
msg
);
this
.
executeWithDraw
(
ids
);
dbController
dbController
.
removeMessage
(
e
.
chat_id
,
e
.
ref_id
)
.
removeMessage
(
e
.
chat_id
,
ids
)
.
finally
(()
=>
this
.
refresh
());
.
finally
(()
=>
this
.
refresh
());
}
}
});
});
...
@@ -339,6 +340,23 @@
...
@@ -339,6 +340,23 @@
// eslint-disable-next-line no-console
// eslint-disable-next-line no-console
console
.
log
(
"没有更多新消息了"
);
console
.
log
(
"没有更多新消息了"
);
}
}
const
removingIds
:
number
[]
=
[];
for
(
const
item
of
data
)
{
if
(
item
.
type
===
MessageType
.
Withdraw
)
{
item
.
msg
&&
removingIds
.
push
(...
JSON
.
parse
(
item
.
msg
));
}
}
if
(
removingIds
.
length
)
{
dbController
.
removeMessage
(
this
.
chatId
,
removingIds
)
.
then
(()
=>
{
this
.
refresh
();
this
.
executeWithDraw
(
removingIds
);
});
}
this
.
$emit
(
"next-page"
,
msgId
);
this
.
$emit
(
"next-page"
,
msgId
);
this
.
endLoadingNew
();
this
.
endLoadingNew
();
})
})
...
...
components/message.vue
View file @
7abbf4ee
...
@@ -486,15 +486,14 @@
...
@@ -486,15 +486,14 @@
}
}
private
withdraw
()
{
private
withdraw
()
{
if
(
new
Date
().
valueOf
()
-
this
.
data
.
ts
*
1000
>
twoMinutes
)
{
if
(
!
this
.
hoverWithdraw
())
{
Xim
.
error
(
"超过两分钟的消息不能撤回"
);
return
Xim
.
error
(
"不能撤回"
);
return
;
}
}
ximInstance
.
withdraw
(
this
.
chatId
!
,
this
.
data
.
id
).
finally
(()
=>
{
ximInstance
.
withdraw
(
this
.
chatId
,
this
.
data
.
id
).
finally
(()
=>
{
dbController
dbController
.
removeMessage
(
this
.
chatId
!
,
this
.
data
.
id
)
.
removeMessage
(
this
.
chatId
,
[
this
.
data
.
id
]
)
.
finally
(()
=>
{
.
finally
(()
=>
{
this
.
executeWithDraw
(
this
.
data
.
id
);
this
.
executeWithDraw
(
[
this
.
data
.
id
]
);
this
.
$emit
(
"withdraw"
,
this
.
data
.
id
);
this
.
$emit
(
"withdraw"
,
this
.
data
.
id
);
});
});
});
});
...
@@ -502,11 +501,11 @@
...
@@ -502,11 +501,11 @@
private
hoverWithdraw
()
{
private
hoverWithdraw
()
{
if
(
!
this
.
isWithdraw
||
!
this
.
isMyMessage
)
{
if
(
!
this
.
isWithdraw
||
!
this
.
isMyMessage
)
{
return
;
return
false
;
}
}
this
.
isWithdraw
=
this
.
needReadTip
return
(
this
.
isWithdraw
=
this
.
needReadTip
?
new
Date
().
valueOf
()
-
this
.
data
.
ts
*
1000
<
twoMinutes
?
new
Date
().
valueOf
()
-
this
.
data
.
ts
*
1000
<
twoMinutes
:
new
Date
().
valueOf
()
-
this
.
data
.
ts
*
1000
<
twoHours
;
:
new
Date
().
valueOf
()
-
this
.
data
.
ts
*
1000
<
twoHours
)
;
}
}
private
openReaderList
(
e
:
MouseEvent
)
{
private
openReaderList
(
e
:
MouseEvent
)
{
...
...
database/index.ts
View file @
7abbf4ee
...
@@ -20,7 +20,9 @@ class ChatCacheDatabaseController {
...
@@ -20,7 +20,9 @@ class ChatCacheDatabaseController {
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
const
checker
=
()
=>
{
const
checker
=
()
=>
{
if
(
!
this
.
setuping
)
{
if
(
!
this
.
setuping
)
{
this
.
setupError
?
reject
(
new
Error
(
`IM index database setup failed`
))
:
resolve
();
this
.
setupError
?
reject
(
new
Error
(
`IM index database setup failed`
))
:
resolve
();
}
else
{
}
else
{
setTimeout
(()
=>
checker
(),
200
);
setTimeout
(()
=>
checker
(),
200
);
}
}
...
@@ -30,16 +32,17 @@ class ChatCacheDatabaseController {
...
@@ -30,16 +32,17 @@ class ChatCacheDatabaseController {
}
}
public
setup
(
uid
:
string
)
{
public
setup
(
uid
:
string
)
{
if
(
this
.
db
)
{
return
Promise
.
resolve
();
}
if
(
this
.
setuping
)
{
if
(
this
.
setuping
)
{
return
this
.
waitSetupCompleted
();
return
this
.
waitSetupCompleted
();
}
}
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
if
(
uid
&&
indexedDB
)
{
if
(
uid
&&
indexedDB
)
{
this
.
setuping
=
true
;
this
.
setuping
=
true
;
const
r
=
indexedDB
.
open
(
const
key
=
"u-"
+
(
this
.
uid
=
uid
);
"u-"
+
(
this
.
uid
=
uid
),
const
r
=
indexedDB
.
open
(
key
,
this
.
listVersion
);
this
.
listVersion
);
const
setupDb
=
()
=>
{
const
setupDb
=
()
=>
{
if
(
this
.
setuping
)
{
if
(
this
.
setuping
)
{
if
(
this
.
db
)
{
if
(
this
.
db
)
{
...
@@ -131,8 +134,9 @@ class ChatCacheDatabaseController {
...
@@ -131,8 +134,9 @@ class ChatCacheDatabaseController {
}
}
private
buildTransaction
(
key
:
string
)
{
private
buildTransaction
(
key
:
string
)
{
try
{
return
this
.
db
.
transaction
(
key
,
"readwrite"
);
}
try
{
catch
{
return
this
.
db
.
transaction
(
key
,
"readwrite"
);
}
catch
{
window
.
location
.
reload
();
window
.
location
.
reload
();
throw
new
Error
(
`transition failed`
);
throw
new
Error
(
`transition failed`
);
}
}
...
@@ -329,7 +333,7 @@ class ChatCacheDatabaseController {
...
@@ -329,7 +333,7 @@ class ChatCacheDatabaseController {
const
r
=
store
.
getAll
();
const
r
=
store
.
getAll
();
r
.
onsuccess
=
(
o
)
=>
{
r
.
onsuccess
=
(
o
)
=>
{
const
items
=
(
o
.
target
as
any
).
result
as
Chat
[];
const
items
=
(
o
.
target
as
any
).
result
as
Chat
[];
resolve
(
items
.
find
(
i
=>
i
.
biz_type_code
===
code
)
as
Chat
);
resolve
(
items
.
find
(
(
i
)
=>
i
.
biz_type_code
===
code
)
as
Chat
);
};
};
r
.
onerror
=
()
=>
resolve
(
null
);
r
.
onerror
=
()
=>
resolve
(
null
);
});
});
...
@@ -379,13 +383,22 @@ class ChatCacheDatabaseController {
...
@@ -379,13 +383,22 @@ class ChatCacheDatabaseController {
});
});
}
}
public
removeMessage
(
chat
:
number
,
msg
:
number
)
{
public
removeMessage
(
chat
:
number
,
msg
s
:
number
[]
)
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
if
(
this
.
db
)
{
if
(
this
.
db
)
{
const
store
=
this
.
buildChatMessageStore
(
chat
);
const
store
=
this
.
buildChatMessageStore
(
chat
);
const
d
=
store
.
delete
(
msg
);
let
count
=
0
;
d
.
onsuccess
=
()
=>
setTimeout
(()
=>
resolve
(),
100
);
const
action
=
()
=>
{
d
.
onerror
=
()
=>
reject
();
count
++
;
if
(
count
===
msgs
.
length
)
{
resolve
();
}
};
for
(
const
item
of
msgs
)
{
const
d
=
store
.
delete
(
item
);
d
.
onsuccess
=
()
=>
action
();
d
.
onerror
=
()
=>
action
();
}
}
else
{
}
else
{
resolve
();
resolve
();
}
}
...
@@ -396,7 +409,10 @@ class ChatCacheDatabaseController {
...
@@ -396,7 +409,10 @@ class ChatCacheDatabaseController {
for
(
const
item
of
source2
)
{
for
(
const
item
of
source2
)
{
const
t
=
source1
.
find
((
i
)
=>
i
.
id
===
item
.
id
);
const
t
=
source1
.
find
((
i
)
=>
i
.
id
===
item
.
id
);
if
(
t
)
{
if
(
t
)
{
item
.
unread_msg_count
=
Math
.
max
(
item
.
unread_msg_count
,
t
.
unread_msg_count
);
item
.
unread_msg_count
=
Math
.
max
(
item
.
unread_msg_count
,
t
.
unread_msg_count
);
const
index
=
source1
.
indexOf
(
t
);
const
index
=
source1
.
indexOf
(
t
);
source1
[
index
]
=
item
;
source1
[
index
]
=
item
;
}
else
{
}
else
{
...
...
model/index.ts
View file @
7abbf4ee
import
type
{
UniplatSdk
}
from
"uniplat-sdk"
;
import
type
{
UniplatSdk
}
from
"uniplat-sdk"
;
export
*
from
"./order"
;
export
*
from
"./order"
;
export
*
from
"./order-product"
export
*
from
"./order-product"
;
export
const
enum
ChatRole
{
export
const
enum
ChatRole
{
Default
=
25
,
Default
=
25
,
...
@@ -115,12 +115,12 @@ export const enum MessageType {
...
@@ -115,12 +115,12 @@ export const enum MessageType {
Action
=
"action"
,
Action
=
"action"
,
Notify
=
"notify"
,
Notify
=
"notify"
,
MpNavigate
=
"mp-navigate"
,
MpNavigate
=
"mp-navigate"
,
PayV1
=
'gpay'
,
PayV1
=
"gpay"
,
Pay
=
"gpay2"
,
Pay
=
"gpay2"
,
PayResult
=
"gresult"
,
PayResult
=
"gresult"
,
RefundV1
=
'grefund'
,
RefundV1
=
"grefund"
,
Refund
=
"grefund2"
,
Refund
=
"grefund2"
,
Card
=
'card'
Card
=
"card"
,
}
}
export
const
enum
MessageHandled
{
export
const
enum
MessageHandled
{
...
@@ -195,6 +195,7 @@ export interface BaseChatItem extends BaseChatItemBusinessData {
...
@@ -195,6 +195,7 @@ export interface BaseChatItem extends BaseChatItemBusinessData {
create_time
:
number
;
create_time
:
number
;
update_time
:
number
;
update_time
:
number
;
last_msg_ts
:
number
;
last_msg_ts
:
number
;
last_msg_sender
:
string
;
members_updated
:
number
;
members_updated
:
number
;
user_updated
:
number
;
user_updated
:
number
;
}
}
...
...
store/index.ts
View file @
7abbf4ee
This diff is collapsed.
Click to expand it.
store/model.ts
View file @
7abbf4ee
...
@@ -31,7 +31,7 @@ export namespace ChatStore {
...
@@ -31,7 +31,7 @@ export namespace ChatStore {
export
type
STATE_CHAT_SENDING_MESSAGE
=
dto
.
Message
;
export
type
STATE_CHAT_SENDING_MESSAGE
=
dto
.
Message
;
export
const
STATE_CHAT_CURRENT_CHAT_ID
=
"当前chat-id"
;
export
const
STATE_CHAT_CURRENT_CHAT_ID
=
"当前chat-id"
;
export
type
STATE_CHAT_CURRENT_CHAT_ID
=
number
|
null
;
export
type
STATE_CHAT_CURRENT_CHAT_ID
=
number
;
export
const
STATE_CHAT_CURRENT_CHAT_VERSION
=
"当前chat的Uniplat version"
;
export
const
STATE_CHAT_CURRENT_CHAT_VERSION
=
"当前chat的Uniplat version"
;
export
type
STATE_CHAT_CURRENT_CHAT_VERSION
=
number
|
null
;
export
type
STATE_CHAT_CURRENT_CHAT_VERSION
=
number
|
null
;
export
const
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
=
"是否是当前chat的成员"
;
export
const
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
=
"是否是当前chat的成员"
;
...
@@ -169,7 +169,7 @@ export namespace ChatStore {
...
@@ -169,7 +169,7 @@ export namespace ChatStore {
export
type
MUTATION_CLEAR_CURRENT_CHAT_UNIPLAT_ID
=
()
=>
void
;
export
type
MUTATION_CLEAR_CURRENT_CHAT_UNIPLAT_ID
=
()
=>
void
;
export
const
MUTATION_WITHDRAW
=
"撤回"
;
export
const
MUTATION_WITHDRAW
=
"撤回"
;
export
type
MUTATION_WITHDRAW
=
(
id
:
number
)
=>
void
;
export
type
MUTATION_WITHDRAW
=
(
id
s
:
number
[]
)
=>
void
;
export
const
MUTATION_SAVE_MYSELF_ID
=
export
const
MUTATION_SAVE_MYSELF_ID
=
"保存我的id:聊天窗口显示在右边那个人的id"
;
"保存我的id:聊天窗口显示在右边那个人的id"
;
...
...
xim/xim.ts
View file @
7abbf4ee
...
@@ -200,7 +200,9 @@ export class Xim {
...
@@ -200,7 +200,9 @@ export class Xim {
}
}
private
setMessagesRead
(
chatId
:
number
,
msg
:
Message
[])
{
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
);
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