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
ae024595
authored
Nov 02, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update
parent
9aed20af
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
136 additions
and
20 deletions
store/index.ts
xim/index.ts
xim/xim.ts
store/index.ts
View file @
ae024595
...
...
@@ -31,7 +31,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
);
});
}
...
...
@@ -327,7 +327,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
,
...
...
@@ -457,7 +457,7 @@ export default {
items
.
forEach
((
i
)
=>
(
sum
+=
i
.
unread_msg_count
));
state
[
ChatStore
.
STATE_CURRENT_UNREAD_MESSAGE_COUNT
]
=
sum
;
},
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES
]({
state
,
commit
})
{
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES
]({
state
,
commit
,
getters
})
{
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
if
(
chatId
==
null
)
return
;
let
data
:
Message
[]
=
[];
...
...
@@ -465,12 +465,25 @@ export default {
if
(
cache
&&
cache
.
length
)
{
data
=
cache
;
}
else
{
const
current
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
]
as
boolean
;
if
(
current
)
{
data
=
await
xim
.
queryLastPageMsg
(
chatType
,
chatId
,
20
,
!
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
]
);
}
else
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
data
=
await
xim
.
queryLastPageMsgWhenNotMember
({
model
:
currentChat
.
model_name
,
obj
:
currentChat
.
obj_id
,
});
}
}
try
{
commit
(
ChatStore
.
MUTATION_PUSH_CHAT_MSG_HISTORY
,
data
);
...
...
@@ -484,35 +497,69 @@ export default {
}
},
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES_BEFORE_SPECIFIC_ID
](
{
state
,
commit
},
{
state
,
commit
,
getters
},
msgId
:
Parameters
<
ChatStore
.
ACTION_GET_CHAT_MESSAGES_BEFORE_SPECIFIC_ID
>
[
0
]
)
{
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
if
(
chatId
==
null
)
return
;
const
data
=
await
xim
.
queryPrevPageMsg
(
const
current
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
]
as
boolean
;
let
data
:
Message
[]
=
[];
if
(
current
)
{
data
=
await
xim
.
queryPrevPageMsg
(
chatType
,
chatId
,
msgId
,
10
,
!
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
]
);
}
else
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
data
=
await
xim
.
queryPreviousPageMsgWhenNotMember
(
{
model
:
currentChat
.
model_name
,
obj
:
currentChat
.
obj_id
,
},
msgId
);
}
commit
(
ChatStore
.
MUTATION_UNSHIFT_CHAT_MSG_HISTORY
,
data
);
dbController
.
appendMessages
(
chatId
,
data
);
return
data
;
},
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID
](
{
state
,
commit
},
{
state
,
commit
,
getters
},
msgId
:
Parameters
<
ChatStore
.
ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID
>
[
0
]
)
{
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
if
(
chatId
==
null
)
return
;
const
data
=
await
xim
.
queryNextPageMsg
(
const
current
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
]
as
boolean
;
let
data
:
Message
[]
=
[];
if
(
current
)
{
data
=
await
xim
.
queryNextPageMsg
(
chatType
,
chatId
,
msgId
,
10
,
!
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
]
);
}
else
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
data
=
await
xim
.
queryNextPageMsgWhenNotMember
(
{
model
:
currentChat
.
model_name
,
obj
:
currentChat
.
obj_id
,
},
msgId
);
}
commit
(
ChatStore
.
MUTATION_PUSH_CHAT_MSG_HISTORY
,
data
);
dbController
.
appendMessages
(
chatId
,
data
);
return
data
;
...
...
@@ -527,7 +574,9 @@ export default {
}
}
try
{
const
chat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
chat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
const
data
=
await
Chat
.
getSdk
()
.
model
(
chat
.
model_name
)
.
chat
(
chat
.
obj_id
,
orgId
())
...
...
@@ -760,7 +809,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
);
})
);
...
...
@@ -790,7 +839,9 @@ export default {
);
},
async
[
ChatStore
.
ACTION_CHAT_START_RECEPTION
]({
getters
,
dispatch
})
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
if
(
!
currentChat
||
!
currentChat
.
model_name
||
...
...
@@ -805,7 +856,9 @@ export default {
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
},
async
[
ChatStore
.
ACTION_CHAT_FINISH_RECEPTION
]({
getters
,
dispatch
})
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
if
(
!
currentChat
||
!
currentChat
.
model_name
||
...
...
@@ -820,7 +873,9 @@ export default {
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
},
async
[
ChatStore
.
ACTION_CHAT_USER_EXIT
]({
getters
,
dispatch
})
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
if
(
!
currentChat
||
!
currentChat
.
model_name
||
...
...
@@ -835,7 +890,9 @@ export default {
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
},
async
[
ChatStore
.
ACTION_CHAT_CS_EXIT
]({
getters
,
dispatch
})
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
if
(
!
currentChat
||
!
currentChat
.
model_name
||
...
...
@@ -853,7 +910,9 @@ export default {
{
getters
,
dispatch
},
uids
:
Parameters
<
ChatStore
.
ACTION_CHAT_ADD_MEMBERS
>
[
0
]
)
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
if
(
!
currentChat
||
!
currentChat
.
model_name
||
...
...
@@ -871,7 +930,9 @@ export default {
{
getters
,
dispatch
},
uids
:
Parameters
<
ChatStore
.
ACTION_CHAT_REMOVE_MEMBER
>
[
0
]
)
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
if
(
!
currentChat
||
!
currentChat
.
model_name
||
...
...
@@ -889,7 +950,9 @@ export default {
{
getters
,
dispatch
},
uids
:
Parameters
<
ChatStore
.
ACTION_CHAT_ADD_CS
>
[
0
]
)
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
if
(
!
currentChat
||
!
currentChat
.
model_name
||
...
...
@@ -907,7 +970,9 @@ export default {
{
getters
,
dispatch
},
uids
:
Parameters
<
ChatStore
.
ACTION_CHAT_REMOVE_CS
>
[
0
]
)
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
]
as
ChatType
;
if
(
!
currentChat
||
!
currentChat
.
model_name
||
...
...
xim/index.ts
View file @
ae024595
...
...
@@ -63,7 +63,7 @@ class Chat implements ChatMessageController {
option
.
message
&&
(
this
.
messageController
=
option
.
message
);
this
.
setupIndexDb
();
await
this
.
setupIndexDb
();
this
.
token
=
async
()
=>
option
.
sdk
().
global
.
jwtToken
;
tokenManager
.
save
(
this
.
token
);
...
...
@@ -92,7 +92,7 @@ class Chat implements ChatMessageController {
s
.
global
.
uid
+
"-"
+
(
s
.
global
.
initData
.
orgId
||
0
)
);
}
return
Promise
.
reject
(
new
Error
(
'Sdk is not defined'
));
return
Promise
.
reject
(
new
Error
(
"Sdk is not defined"
));
}
public
resetup
(
org
:
()
=>
string
|
number
)
{
...
...
xim/xim.ts
View file @
ae024595
...
...
@@ -7,6 +7,7 @@ import { Message, NotifyMessage } from "./models/chat";
import
chat
from
"./index"
;
import
{
STATUS
}
from
"xchat-client/dist/xchat"
;
import
{
AxiosInstance
}
from
"axios"
;
wampDebug
(
true
);
...
...
@@ -203,6 +204,55 @@ export class Xim {
return
data
;
}
public
async
queryLastPageMsgWhenNotMember
(
chatParameter
:
{
model
:
string
;
obj
:
string
;
})
{
return
this
.
queryMessagesWhenNotMember
(
chatParameter
,
0
,
0
,
20
,
1
);
}
public
async
queryPreviousPageMsgWhenNotMember
(
chatParameter
:
{
model
:
string
;
obj
:
string
;
},
start
:
number
)
{
return
this
.
queryMessagesWhenNotMember
(
chatParameter
,
0
,
start
,
20
,
1
);
}
public
async
queryNextPageMsgWhenNotMember
(
chatParameter
:
{
model
:
string
;
obj
:
string
;
},
end
:
number
)
{
return
this
.
queryMessagesWhenNotMember
(
chatParameter
,
end
,
0
,
20
,
0
);
}
private
queryMessagesWhenNotMember
(
chatParameter
:
{
model
:
string
;
obj
:
string
},
lid
:
number
,
rid
:
number
,
limit
:
number
,
desc
:
number
)
{
const
sdk
=
chat
.
getSdk
();
const
query
=
sdk
.
getAxios
()
as
AxiosInstance
;
const
q
=
[
`lid=
${
lid
}
`
,
`rid=
${
rid
}
`
,
`limit=
${
limit
}
`
,
`desc=
${
desc
}
`
,
];
return
query
.
get
<
any
,
Message
[]
>
(
`
${
sdk
.
global
.
baseUrl
}
general/xim/model/
${
chatParameter
.
model
}
/
${
chatParameter
.
obj
}
/msgs?
${
q
.
join
(
"&"
)}
`
);
}
/** 查询上一页消息 */
public
async
queryPrevPageMsg
(
chatType
:
string
,
...
...
@@ -398,7 +448,8 @@ export class Xim {
}
private
debug
(
message
:
any
,
...
params
:
any
[])
{
ChatLoggerService
.
logger
&&
ChatLoggerService
.
logger
.
debug
(
message
,
params
);
ChatLoggerService
.
logger
&&
ChatLoggerService
.
logger
.
debug
(
message
,
params
);
}
public
registerOnMessage
(
vue
:
Vue
,
action
:
(
e
:
Message
)
=>
void
)
{
...
...
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