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
8c3c9d5a
authored
Dec 22, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update
parent
3f147148
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
82 additions
and
41 deletions
components/message-list.vue
components/message.vue
database/index.ts
model/index.ts
store/index.ts
store/model.ts
components/message-list.vue
View file @
8c3c9d5a
...
...
@@ -191,9 +191,10 @@
this
.
handleScrollWrapper
();
this
.
onNewMessage
((
e
)
=>
{
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
.
removeMessage
(
e
.
chat_id
,
e
.
ref_id
)
.
removeMessage
(
e
.
chat_id
,
ids
)
.
finally
(()
=>
this
.
refresh
());
}
});
...
...
@@ -339,6 +340,23 @@
// eslint-disable-next-line no-console
console
.
log
(
"没有更多新消息了"
);
}
const
removingIds
=
[];
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
.
endLoadingNew
();
})
...
...
components/message.vue
View file @
8c3c9d5a
...
...
@@ -486,15 +486,14 @@
}
private
withdraw
()
{
if
(
new
Date
().
valueOf
()
-
this
.
data
.
ts
*
1000
>
twoMinutes
)
{
Xim
.
error
(
"超过两分钟的消息不能撤回"
);
return
;
if
(
!
this
.
hoverWithdraw
())
{
return
Xim
.
error
(
"不能撤回"
);
}
ximInstance
.
withdraw
(
this
.
chatId
!
,
this
.
data
.
id
).
finally
(()
=>
{
ximInstance
.
withdraw
(
this
.
chatId
,
this
.
data
.
id
).
finally
(()
=>
{
dbController
.
removeMessage
(
this
.
chatId
!
,
this
.
data
.
id
)
.
removeMessage
(
this
.
chatId
,
[
this
.
data
.
id
]
)
.
finally
(()
=>
{
this
.
executeWithDraw
(
this
.
data
.
id
);
this
.
executeWithDraw
(
[
this
.
data
.
id
]
);
this
.
$emit
(
"withdraw"
,
this
.
data
.
id
);
});
});
...
...
@@ -502,11 +501,11 @@
private
hoverWithdraw
()
{
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
<
twoHours
;
:
new
Date
().
valueOf
()
-
this
.
data
.
ts
*
1000
<
twoHours
)
;
}
private
openReaderList
(
e
:
MouseEvent
)
{
...
...
database/index.ts
View file @
8c3c9d5a
...
...
@@ -20,7 +20,9 @@ class ChatCacheDatabaseController {
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
const
checker
=
()
=>
{
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
{
setTimeout
(()
=>
checker
(),
200
);
}
...
...
@@ -97,17 +99,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
}
`
);
...
...
@@ -131,8 +133,9 @@ class ChatCacheDatabaseController {
}
private
buildTransaction
(
key
:
string
)
{
try
{
return
this
.
db
.
transaction
(
key
,
"readwrite"
);
}
catch
{
try
{
return
this
.
db
.
transaction
(
key
,
"readwrite"
);
}
catch
{
window
.
location
.
reload
();
throw
new
Error
(
`transition failed`
);
}
...
...
@@ -329,7 +332,7 @@ class ChatCacheDatabaseController {
const
r
=
store
.
getAll
();
r
.
onsuccess
=
(
o
)
=>
{
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
);
});
...
...
@@ -379,13 +382,22 @@ class ChatCacheDatabaseController {
});
}
public
removeMessage
(
chat
:
number
,
msg
:
number
)
{
public
removeMessage
(
chat
:
number
,
msg
s
:
number
[]
)
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
if
(
this
.
db
)
{
const
store
=
this
.
buildChatMessageStore
(
chat
);
const
d
=
store
.
delete
(
msg
);
d
.
onsuccess
=
()
=>
setTimeout
(()
=>
resolve
(),
100
);
d
.
onerror
=
()
=>
reject
();
let
count
=
0
;
const
action
=
()
=>
{
count
++
;
if
(
count
===
msgs
.
length
)
{
resolve
();
}
};
for
(
const
item
of
msgs
)
{
const
d
=
store
.
delete
(
item
);
d
.
onsuccess
=
()
=>
action
();
d
.
onerror
=
()
=>
action
();
}
}
else
{
resolve
();
}
...
...
@@ -396,7 +408,10 @@ class ChatCacheDatabaseController {
for
(
const
item
of
source2
)
{
const
t
=
source1
.
find
((
i
)
=>
i
.
id
===
item
.
id
);
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
);
source1
[
index
]
=
item
;
}
else
{
...
...
model/index.ts
View file @
8c3c9d5a
import
type
{
UniplatSdk
}
from
"uniplat-sdk"
;
export
*
from
"./order"
;
export
*
from
"./order-product"
export
*
from
"./order-product"
;
export
const
enum
ChatRole
{
Default
=
25
,
...
...
@@ -115,12 +115,12 @@ export const enum MessageType {
Action
=
"action"
,
Notify
=
"notify"
,
MpNavigate
=
"mp-navigate"
,
PayV1
=
'gpay'
,
PayV1
=
"gpay"
,
Pay
=
"gpay2"
,
PayResult
=
"gresult"
,
RefundV1
=
'grefund'
,
RefundV1
=
"grefund"
,
Refund
=
"grefund2"
,
Card
=
'card'
Card
=
"card"
,
}
export
const
enum
MessageHandled
{
...
...
store/index.ts
View file @
8c3c9d5a
...
...
@@ -32,7 +32,7 @@ function uniqueMessages(
messages
:
NonNullable
<
ChatStore
.
STATE_CHAT_MSG_HISTORY
>
)
{
const
arr
=
[...
messages
];
return
unique
(
arr
,
function
(
item
,
all
)
{
return
unique
(
arr
,
function
(
item
,
all
)
{
return
all
.
findIndex
((
k
)
=>
k
.
id
===
item
.
id
);
});
}
...
...
@@ -362,7 +362,7 @@ export default {
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
}
=
{};
return
(
state
:
ChatStoreState
,
...
...
@@ -409,12 +409,12 @@ export default {
)
=>
{
Vue
.
set
(
state
[
ChatStore
.
STATE_CHAT_USERNAME
],
param
.
id
,
param
.
name
);
},
[
ChatStore
.
MUTATION_WITHDRAW
]:
(
state
,
id
:
number
)
=>
{
[
ChatStore
.
MUTATION_WITHDRAW
]:
(
state
,
id
s
:
number
[]
)
=>
{
const
old
=
state
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
]
||
[];
const
chatid
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
if
(
chatid
==
null
)
return
;
state
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
]
=
old
.
filter
(
(
i
)
=>
i
.
id
!==
id
(
i
)
=>
!
ids
.
includes
(
i
.
id
)
);
},
},
...
...
@@ -471,11 +471,14 @@ export default {
const
execute
=
()
=>
new
Promise
<
ChatType
[]
>
((
resolve
,
reject
)
=>
{
Chat
.
onReady
(()
=>
{
xim
.
fetchChatListAfter
(
last
)
!
.
then
((
r
)
=>
{
xim
.
fetchChatListAfter
(
last
)
!
.
then
((
r
)
=>
{
const
list
=
filterActiveChats
(
r
.
args
[
0
]
as
RawChatItem
[]
);
const
items
=
list
.
map
((
i
)
=>
buildChatItem
(
i
));
const
items
=
list
.
map
((
i
)
=>
buildChatItem
(
i
)
);
if
(
items
&&
items
.
length
)
{
cache
=
dbController
.
mergeChatList
(
cache
,
...
...
@@ -483,7 +486,8 @@ export default {
);
}
resolve
(
buildUnreadMessage
(
cache
));
}).
catch
(
reject
);
})
.
catch
(
reject
);
});
}).
finally
(()
=>
(
loadingChatList
=
false
));
...
...
@@ -493,7 +497,8 @@ export default {
const
execute
=
()
=>
new
Promise
<
ChatType
[]
>
((
resolve
,
reject
)
=>
{
Chat
.
onReady
(()
=>
{
xim
.
fetchChatList
().
then
((
data
)
=>
{
xim
.
fetchChatList
()
.
then
((
data
)
=>
{
if
(
!
data
)
{
return
resolve
([]);
}
...
...
@@ -504,9 +509,13 @@ export default {
buildChatItem
(
chat
)
);
dbController
.
saveChatList
(
items
);
commit
(
ChatStore
.
MUTATION_SAVE_CHAT_LIST
,
items
);
commit
(
ChatStore
.
MUTATION_SAVE_CHAT_LIST
,
items
);
resolve
(
buildUnreadMessage
(
items
));
}).
catch
(
reject
);
})
.
catch
(
reject
);
});
}).
finally
(()
=>
(
loadingChatList
=
false
));
...
...
@@ -729,7 +738,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
]
);
}
const
scroll
=
()
=>
state
[
ChatStore
.
STATE_FUNC_ON_NEW_MSG
](
e
);
...
...
@@ -743,7 +752,7 @@ export default {
};
if
(
e
.
type
===
MessageType
.
Withdraw
)
{
dbController
.
removeMessage
(
e
.
chat_id
,
+
e
.
msg
)
.
removeMessage
(
e
.
chat_id
,
[
+
e
.
msg
]
)
.
finally
(()
=>
thenAction
());
}
else
{
thenAction
();
...
...
@@ -922,7 +931,7 @@ export default {
}
commit
(
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_MEMBERS
,
unique
(
newChatMembers
,
function
(
item
,
all
)
{
unique
(
newChatMembers
,
function
(
item
,
all
)
{
return
all
.
findIndex
((
k
)
=>
k
.
eid
===
item
.
eid
);
})
);
...
...
store/model.ts
View file @
8c3c9d5a
...
...
@@ -169,7 +169,7 @@ export namespace ChatStore {
export
type
MUTATION_CLEAR_CURRENT_CHAT_UNIPLAT_ID
=
()
=>
void
;
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
=
"保存我的id:聊天窗口显示在右边那个人的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