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
6342cc84
authored
Oct 13, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
chat event
parent
75a06366
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
4 deletions
components/chat-title.vue
components/controller/chat-event-handler.ts
components/controller/chat-list.ts
database/index.ts
store/index.ts
components/chat-title.vue
View file @
6342cc84
...
...
@@ -65,9 +65,16 @@ import { Component, Prop, Vue } from "vue-property-decorator";
import
ChatCreator
from
"@/customer-service/components/create-chat.vue"
;
import
{
ChatStore
,
chatStore
}
from
"@/customer-service/store/model"
;
import
{
ChatRole
}
from
"../model"
;
import
{
ChatChangedEvent
,
ChatEventHandler
,
}
from
"./controller/chat-event-handler"
;
@
Component
({
components
:
{
ChatCreator
}
})
export
default
class
ChatTitle
extends
Vue
{
@
chatStore
.
State
(
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
)
private
readonly
chatId
!
:
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
;
@
chatStore
.
Getter
(
ChatStore
.
GETTER_CURRENT_CHAT_PRESENT_MEMBERS
)
private
readonly
chatMembers
!
:
ChatStore
.
GETTER_CURRENT_CHAT_PRESENT_MEMBERS
;
...
...
@@ -159,7 +166,12 @@ export default class ChatTitle extends Vue {
private
async
startReception
()
{
try
{
await
this
.
_startReception
();
await
this
.
_startReception
().
then
(()
=>
ChatEventHandler
.
raiseChatChanged
(
ChatChangedEvent
.
Start
,
this
.
chatId
)
);
this
.
$emit
(
"updateActive"
,
"my_receiving"
);
}
catch
(
error
)
{
console
.
error
(
error
);
...
...
@@ -176,7 +188,9 @@ export default class ChatTitle extends Vue {
type
:
"warning"
,
}
);
await
this
.
_finishReception
();
await
this
.
_finishReception
().
then
(()
=>
ChatEventHandler
.
raiseChatChanged
(
ChatChangedEvent
.
End
,
this
.
chatId
)
);
this
.
hideChat
();
}
}
...
...
components/controller/chat-event-handler.ts
0 → 100644
View file @
6342cc84
export
const
enum
ChatChangedEvent
{
Start
=
1
,
End
,
}
export
class
ChatEventHandler
{
private
static
actions
:
{
key
:
string
;
action
:
(
e
:
ChatChangedEvent
,
chat
:
number
)
=>
void
;
}[]
=
[];
public
static
registerOnChatChanged
(
vue
:
Vue
,
action
:
(
e
:
ChatChangedEvent
,
chat
:
number
)
=>
void
)
{
const
key
=
`
${
new
Date
().
valueOf
()}
-
${
Math
.
random
()}
`
;
this
.
actions
.
push
({
key
,
action
});
vue
.
$once
(
"hook:beforeDestroy"
,
()
=>
{
const
t
=
this
.
actions
.
find
((
i
)
=>
i
.
key
===
key
);
if
(
t
)
{
this
.
actions
=
this
.
actions
.
filter
((
i
)
=>
i
!==
t
);
}
});
}
public
static
raiseChatChanged
(
e
:
ChatChangedEvent
,
chat
:
number
)
{
for
(
const
item
of
this
.
actions
)
{
item
.
action
(
e
,
chat
);
}
}
}
components/controller/chat-list.ts
View file @
6342cc84
...
...
@@ -47,6 +47,9 @@ export default class ChatList extends Vue {
@
chatStore
.
Action
(
ChatStore
.
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
)
protected
readonly
updateUnreadMessageCount
!
:
ChatStore
.
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
;
@
chatStore
.
Action
(
ChatStore
.
ACTION_CLEAR_CURRENT_CHAT_DATA
)
protected
readonly
reset
!
:
ChatStore
.
ACTION_CLEAR_CURRENT_CHAT_DATA
;
protected
parseMesage
(
data
:
ChatItem
)
{
if
(
data
.
last_msg_sender
&&
data
.
last_msg_sender
!==
"0"
)
{
if
(
!
this
.
userNames
[
data
.
last_msg_sender
])
{
...
...
database/index.ts
View file @
6342cc84
...
...
@@ -144,6 +144,21 @@ class ChatCacheDatabaseController {
}
};
t
.
onerror
=
()
=>
resolve
();
}
else
{
resolve
();
}
});
}
public
removeChatFromList
(
chat
:
number
)
{
return
new
Promise
<
void
>
((
resolve
)
=>
{
if
(
this
.
db
)
{
const
store
=
this
.
buildStore
(
this
.
chatListKey
);
const
t
=
store
.
delete
(
chat
);
t
.
onsuccess
=
()
=>
resolve
();
t
.
onerror
=
()
=>
resolve
();
}
else
{
resolve
();
}
});
}
...
...
store/index.ts
View file @
6342cc84
...
...
@@ -89,6 +89,12 @@ function buildChatItem(chat: RawChatItem) {
}
as
ChatType
;
}
const
filterActiveChats
=
(
items
:
RawChatItem
[])
=>
{
return
items
.
filter
(
(
i
)
=>
!
i
.
is_finish
&&
!
i
.
is_exited
&&
!
i
.
is_remove
&&
!
i
.
is_deleted
);
};
export
default
{
namespaced
:
true
,
state
:
()
=>
({
...
...
@@ -378,7 +384,7 @@ export default {
const
last
=
ts
[
ts
.
length
-
1
];
await
xim
.
fetchChatListAfter
(
last
)
!
.
then
((
r
)
=>
{
const
list
=
r
.
args
[
0
]
as
any
[]
;
const
list
=
filterActiveChats
(
r
.
args
[
0
]
as
RawChatItem
[])
;
const
items
=
list
.
map
((
i
)
=>
buildChatItem
(
i
));
if
(
items
&&
items
.
length
)
{
cache
=
dbController
.
mergeChatList
(
cache
,
items
);
...
...
@@ -390,7 +396,7 @@ export default {
const
data
=
await
xim
.
fetchChatList
();
if
(
data
==
null
)
return
;
const
chatList
=
data
.
args
[
0
]
as
RawChatItem
[]
;
const
chatList
=
filterActiveChats
(
data
.
args
[
0
]
as
RawChatItem
[])
;
const
items
=
chatList
.
map
((
chat
)
=>
buildChatItem
(
chat
));
dbController
.
saveChatList
(
items
);
commit
(
ChatStore
.
MUTATION_SAVE_CHAT_LIST
,
{
...
...
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