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
658a858a
authored
Dec 07, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
u
parent
3d47c0d0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
16 deletions
store/index.ts
store/model.ts
store/index.ts
View file @
658a858a
...
@@ -32,7 +32,7 @@ function uniqueMessages(
...
@@ -32,7 +32,7 @@ function uniqueMessages(
messages
:
NonNullable
<
ChatStore
.
STATE_CHAT_MSG_HISTORY
>
messages
:
NonNullable
<
ChatStore
.
STATE_CHAT_MSG_HISTORY
>
)
{
)
{
const
arr
=
[...
messages
];
const
arr
=
[...
messages
];
return
unique
(
arr
,
function
(
item
,
all
)
{
return
unique
(
arr
,
function
(
item
,
all
)
{
return
all
.
findIndex
((
k
)
=>
k
.
id
===
item
.
id
);
return
all
.
findIndex
((
k
)
=>
k
.
id
===
item
.
id
);
});
});
}
}
...
@@ -203,8 +203,12 @@ export default {
...
@@ -203,8 +203,12 @@ export default {
if
(
chatid
)
{
if
(
chatid
)
{
// 移除撤回的消息
// 移除撤回的消息
const
newItems
=
data
||
[];
const
newItems
=
data
||
[];
const
withdraw
=
newItems
.
filter
(
i
=>
i
.
type
===
MessageType
.
Withdraw
).
map
(
i
=>
+
i
.
msg
);
const
withdraw
=
newItems
const
filterout
=
newItems
.
filter
(
i
=>
!
withdraw
.
includes
(
i
.
id
));
.
filter
((
i
)
=>
i
.
type
===
MessageType
.
Withdraw
)
.
map
((
i
)
=>
+
i
.
msg
);
const
filterout
=
newItems
.
filter
(
(
i
)
=>
!
withdraw
.
includes
(
i
.
id
)
);
state
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
]
=
Object
.
freeze
(
state
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
]
=
Object
.
freeze
(
filterMessages
([...
old
,
...
filterout
],
chatid
)
filterMessages
([...
old
,
...
filterout
],
chatid
)
);
);
...
@@ -341,7 +345,7 @@ export default {
...
@@ -341,7 +345,7 @@ export default {
state
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
]
=
[...
current
];
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
}
=
{};
const
setTimeoutId
:
{
[
key
:
string
]:
number
}
=
{};
return
(
return
(
state
:
ChatStoreState
,
state
:
ChatStoreState
,
...
@@ -483,16 +487,41 @@ export default {
...
@@ -483,16 +487,41 @@ export default {
return
await
execute
().
then
((
d
)
=>
d
);
return
await
execute
().
then
((
d
)
=>
d
);
},
},
async
[
ChatStore
.
ACTION_FORCE_RELOAD_CHAT_LIST
]({
commit
})
{
return
new
Promise
<
ChatType
[]
>
((
resolve
)
=>
{
Chat
.
onReady
(()
=>
{
xim
.
fetchChatList
().
then
((
data
)
=>
{
if
(
!
data
)
{
return
resolve
([]);
}
const
chatList
=
filterActiveChats
(
data
.
args
[
0
]
as
RawChatItem
[]
);
const
items
=
chatList
.
map
((
chat
)
=>
buildChatItem
(
chat
)
);
dbController
.
saveChatList
(
items
);
commit
(
ChatStore
.
MUTATION_SAVE_CHAT_LIST
,
items
);
resolve
(
items
);
});
});
});
},
async
[
ChatStore
.
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
]({
state
})
{
async
[
ChatStore
.
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
]({
state
})
{
let
items
=
await
dbController
.
getChatList
();
let
items
=
await
dbController
.
getChatList
();
let
sum
=
0
;
let
sum
=
0
;
items
.
forEach
((
i
)
=>
(
sum
+=
i
.
unread_msg_count
));
items
.
forEach
((
i
)
=>
(
sum
+=
i
.
unread_msg_count
));
state
[
ChatStore
.
STATE_CURRENT_UNREAD_MESSAGE_COUNT
]
=
sum
;
state
[
ChatStore
.
STATE_CURRENT_UNREAD_MESSAGE_COUNT
]
=
sum
;
},
},
async
[
ChatStore
.
ACTION_UPDATE_CHAT_UNREAD_MESSAGE_COUNT
]({
dispatch
},
p
:
{
chat
:
number
;
unread
:
number
})
{
async
[
ChatStore
.
ACTION_UPDATE_CHAT_UNREAD_MESSAGE_COUNT
](
{
dispatch
},
p
:
{
chat
:
number
;
unread
:
number
}
)
{
dbController
dbController
.
updateChat4UnreadCount
(
p
.
chat
,
p
.
unread
)
.
updateChat4UnreadCount
(
p
.
chat
,
p
.
unread
)
.
then
(()
=>
dispatch
(
ChatStore
.
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
))
.
then
(()
=>
dispatch
(
ChatStore
.
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
)
);
},
},
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES
]({
state
,
commit
,
getters
})
{
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES
]({
state
,
commit
,
getters
})
{
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
...
@@ -677,15 +706,20 @@ export default {
...
@@ -677,15 +706,20 @@ export default {
if
(
e
.
type
===
MessageType
.
Withdraw
)
{
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
);
const
scroll
=
()
=>
state
[
ChatStore
.
STATE_FUNC_ON_NEW_MSG
](
e
);
if
(
e
.
chat_id
===
chatId
)
{
if
(
e
.
chat_id
===
chatId
)
{
dispatch
(
ChatStore
.
ACTION_GET_FRESH_MESSAGE
).
finally
(()
=>
scroll
());
dispatch
(
ChatStore
.
ACTION_GET_FRESH_MESSAGE
).
finally
(
()
=>
scroll
()
);
}
else
{
}
else
{
scroll
();
scroll
();
}
}
};
};
if
(
e
.
type
===
MessageType
.
Withdraw
)
{
if
(
e
.
type
===
MessageType
.
Withdraw
)
{
dbController
.
removeMessage
(
e
.
chat_id
,
+
e
.
msg
).
finally
(()
=>
thenAction
());
dbController
.
removeMessage
(
e
.
chat_id
,
+
e
.
msg
)
.
finally
(()
=>
thenAction
());
}
else
{
}
else
{
thenAction
();
thenAction
();
}
}
...
@@ -863,7 +897,7 @@ export default {
...
@@ -863,7 +897,7 @@ export default {
}
}
commit
(
commit
(
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_MEMBERS
,
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_MEMBERS
,
unique
(
newChatMembers
,
function
(
item
,
all
)
{
unique
(
newChatMembers
,
function
(
item
,
all
)
{
return
all
.
findIndex
((
k
)
=>
k
.
eid
===
item
.
eid
);
return
all
.
findIndex
((
k
)
=>
k
.
eid
===
item
.
eid
);
})
})
);
);
...
@@ -1113,8 +1147,8 @@ export default {
...
@@ -1113,8 +1147,8 @@ export default {
p
.
read_count
=
option
.
all
p
.
read_count
=
option
.
all
?
p
.
total_read_count
?
p
.
total_read_count
:
option
.
readed
:
option
.
readed
?
option
.
readed
?
option
.
readed
:
p
.
read_count
+
1
;
:
p
.
read_count
+
1
;
}
}
}
}
}
else
{
}
else
{
...
@@ -1123,8 +1157,8 @@ export default {
...
@@ -1123,8 +1157,8 @@ export default {
p
.
read_count
=
option
.
all
p
.
read_count
=
option
.
all
?
p
.
total_read_count
?
p
.
total_read_count
:
option
.
readed
:
option
.
readed
?
option
.
readed
?
option
.
readed
:
p
.
read_count
+
1
;
:
p
.
read_count
+
1
;
}
}
}
}
}
}
...
...
store/model.ts
View file @
658a858a
...
@@ -247,6 +247,9 @@ export namespace ChatStore {
...
@@ -247,6 +247,9 @@ export namespace ChatStore {
keyword
?:
string
keyword
?:
string
)
=>
Promise
<
ChatType
[]
>
;
)
=>
Promise
<
ChatType
[]
>
;
export
const
ACTION_FORCE_RELOAD_CHAT_LIST
=
"重新获取我的会话列表"
;
export
type
ACTION_FORCE_RELOAD_CHAT_LIST
=
()
=>
Promise
<
ChatType
[]
>
;
export
const
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
=
"重新计算未读消息数"
;
export
const
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
=
"重新计算未读消息数"
;
export
type
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
=
()
=>
void
;
export
type
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
=
()
=>
void
;
...
@@ -379,8 +382,12 @@ export namespace ChatStore {
...
@@ -379,8 +382,12 @@ export namespace ChatStore {
export
const
ACTION_UPDATE_CHAT
=
"更新会话信息"
;
export
const
ACTION_UPDATE_CHAT
=
"更新会话信息"
;
export
type
ACTION_UPDATE_CHAT
=
(
p
:
ChatUpdateParameter
)
=>
void
;
export
type
ACTION_UPDATE_CHAT
=
(
p
:
ChatUpdateParameter
)
=>
void
;
export
const
ACTION_UPDATE_CHAT_UNREAD_MESSAGE_COUNT
=
"更新Chat会话未读消息并重新计数总数"
;
export
const
ACTION_UPDATE_CHAT_UNREAD_MESSAGE_COUNT
=
export
type
ACTION_UPDATE_CHAT_UNREAD_MESSAGE_COUNT
=
(
p
:
{
chat
:
number
;
unread
:
number
})
=>
void
;
"更新Chat会话未读消息并重新计数总数"
;
export
type
ACTION_UPDATE_CHAT_UNREAD_MESSAGE_COUNT
=
(
p
:
{
chat
:
number
;
unread
:
number
;
})
=>
void
;
}
}
export
interface
ChatStoreState
{
export
interface
ChatStoreState
{
...
...
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