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
1ee879ff
authored
Dec 23, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update
parent
8b24464a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
42 deletions
components/chat-room.vue
store/index.ts
xim/index.ts
components/chat-room.vue
View file @
1ee879ff
...
...
@@ -31,7 +31,7 @@
class=
"chat-input flex-none h-100"
v-if=
"hasInput"
>
<message-input
@
error=
"onError"
/>
<message-input
@
error=
"onError"
@
sent=
"onMessageSent"
/>
</div>
</div>
</div>
...
...
@@ -70,6 +70,11 @@
@
chatStore
.
State
(
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_ERROR
)
private
readonly
chatError
!
:
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_ERROR
;
@
chatStore
.
Getter
(
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
)
private
readonly
currentChat
!
:
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
;
private
setting
=
0
;
private
get
hasInput
()
{
return
this
.
isChatMember
&&
this
.
chatError
!==
this
.
chatId
;
}
...
...
@@ -131,6 +136,21 @@
private
openPayMessage
(
id
:
number
)
{
this
.
$emit
(
"open-pay-message"
,
id
);
}
private
onMessageSent
()
{
if
(
this
.
setting
)
{
clearTimeout
(
this
.
setting
);
}
this
.
setting
=
setTimeout
(
()
=>
this
.
currentChat
&&
Chat
.
setRead
(
this
.
currentChat
.
model_name
,
this
.
currentChat
.
obj_id
),
300
);
}
}
</
script
>
...
...
store/index.ts
View file @
1ee879ff
...
...
@@ -15,7 +15,7 @@ import { getChatModelInfo } from "../utils/chat-info";
import
{
getUserInfo
}
from
"../utils/user-info"
;
import
Chat
from
"../xim"
;
import
{
Chat
as
ChatType
,
Message
}
from
"../xim/models/chat"
;
import
xim
,
{
ChatNotifyListener
}
from
"../xim/xim"
;
import
xim
,
{
ChatNotifyListener
,
Xim
}
from
"../xim/xim"
;
import
{
decodeJwt
}
from
"uniplat-sdk"
;
import
{
ChatStatus
,
ChatStore
,
ChatStoreState
}
from
"./model"
;
...
...
@@ -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
);
});
}
...
...
@@ -366,7 +366,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
,
...
...
@@ -480,7 +480,9 @@ export default {
items
);
}
dispatch
(
ChatStore
.
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
).
finally
(
resolve
);
dispatch
(
ChatStore
.
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
).
finally
(
resolve
);
})
.
catch
(
reject
);
});
...
...
@@ -508,7 +510,9 @@ export default {
ChatStore
.
MUTATION_SAVE_CHAT_LIST
,
items
);
dispatch
(
ChatStore
.
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
).
finally
(
resolve
);
dispatch
(
ChatStore
.
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
).
finally
(
resolve
);
})
.
catch
(
reject
);
});
...
...
@@ -547,8 +551,8 @@ export default {
p
:
{
chat
:
number
;
unread
:
number
}
)
{
const
list
=
state
[
ChatStore
.
STATE_MY_CHAT_ROOM_LIST
]
as
ChatType
[];
const
t
=
list
.
find
(
i
=>
i
.
id
===
p
.
chat
)
t
&&
(
t
.
unread_msg_count
=
p
.
unread
)
const
t
=
list
.
find
(
(
i
)
=>
i
.
id
===
p
.
chat
);
t
&&
(
t
.
unread_msg_count
=
p
.
unread
)
;
return
dbController
.
updateChat4UnreadCount
(
p
.
chat
,
p
.
unread
)
.
then
(()
=>
...
...
@@ -557,7 +561,9 @@ 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
[]
=
[];
...
...
@@ -614,7 +620,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 +645,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 +673,7 @@ export default {
return
Promise
.
reject
(
error
);
}
},
async
[
ChatStore
.
ACTION_GET_FRESH_MESSAGE
]({
async
[
ChatStore
.
ACTION_GET_FRESH_MESSAGE
]({
state
,
dispatch
,
commit
,
...
...
@@ -687,7 +693,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 +710,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 +728,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 +738,10 @@ export default {
const
onNewMsg
=
(
e
:
Message
)
=>
{
const
thenAction
=
()
=>
{
if
(
e
.
type
===
MessageType
.
Withdraw
)
{
commit
(
ChatStore
.
MUTATION_WITHDRAW
,
e
.
msg
.
startsWith
(
'['
)
?
JSON
.
parse
(
e
.
msg
)
:
[
+
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
);
...
...
@@ -746,7 +755,10 @@ export default {
};
if
(
e
.
type
===
MessageType
.
Withdraw
)
{
dbController
.
removeMessage
(
e
.
chat_id
,
e
.
msg
.
startsWith
(
'['
)
?
JSON
.
parse
(
e
.
msg
)
:
[
+
e
.
msg
])
.
removeMessage
(
e
.
chat_id
,
e
.
msg
.
startsWith
(
"["
)
?
JSON
.
parse
(
e
.
msg
)
:
[
+
e
.
msg
]
)
.
finally
(()
=>
thenAction
());
}
else
{
thenAction
();
...
...
@@ -813,7 +825,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
)
{
...
...
@@ -878,8 +890,9 @@ export default {
commit
(
ChatStore
.
MUTATION_INITING_CHAT_DONE
);
commit
(
ChatStore
.
MUTATION_SCROLL_TO_BOTTOM
);
(
<
any
>
state
)[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_ERROR
]
=
null
;
Chat
.
setRead
(
wantedChatRoom
.
model_name
,
wantedChatRoom
.
obj_id
);
},
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 +900,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
);
...
...
@@ -925,12 +938,12 @@ 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
);
})
);
},
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 +971,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 +995,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 +1012,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 +1030,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 +1048,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 +1068,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 +1088,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 +1108,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
]
)
{
...
...
@@ -1182,8 +1195,8 @@ export default {
p
.
read_count
=
option
.
all
?
p
.
total_read_count
:
option
.
readed
?
option
.
readed
:
p
.
read_count
+
1
;
?
option
.
readed
:
p
.
read_count
+
1
;
}
}
}
else
{
...
...
@@ -1192,8 +1205,8 @@ export default {
p
.
read_count
=
option
.
all
?
p
.
total_read_count
:
option
.
readed
?
option
.
readed
:
p
.
read_count
+
1
;
?
option
.
readed
:
p
.
read_count
+
1
;
}
}
}
...
...
xim/index.ts
View file @
1ee879ff
...
...
@@ -146,14 +146,16 @@ class Chat {
return
Promise
.
resolve
(
uri
);
}
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
xim
.
open
(
uri
,
this
.
token
).
catch
(
reject
).
finally
(()
=>
{
this
.
registerXimEvent
();
if
(
xim
.
isConnected
())
{
resolve
();
}
else
{
reject
(
new
Error
(
`xim is not connected`
));
}
});
xim
.
open
(
uri
,
this
.
token
)
.
catch
(
reject
)
.
finally
(()
=>
{
this
.
registerXimEvent
();
if
(
xim
.
isConnected
())
{
resolve
();
}
else
{
reject
(
new
Error
(
`xim is not connected`
));
}
});
});
}
...
...
@@ -203,6 +205,15 @@ class Chat {
public
getAvatar
()
{
return
this
.
defaultAvatar
;
}
public
setRead
(
model
:
string
,
obj
:
string
)
{
if
(
this
.
isBackend
())
{
const
sdk
=
this
.
getSdk
();
if
(
sdk
)
{
sdk
.
getAxios
().
post
(
`/general/xim/model/
${
model
}
/
${
obj
}
/read`
);
}
}
}
}
export
default
new
Chat
();
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