fix: useMessageFeed
This commit is contained in:
+17
-14
@@ -24,21 +24,24 @@ const messageSlice = createSlice({
|
||||
// 如果是正发送,并且已存在,则不覆盖
|
||||
if (sending && state[mid]) return;
|
||||
const isFile = content_type == ContentTypes.file;
|
||||
if (!sending && isFile) {
|
||||
data.file_path = content;
|
||||
data.content = `${BASE_URL}/resource/file?file_path=${encodeURIComponent(
|
||||
data.file_path
|
||||
)}`;
|
||||
data.download = `${BASE_URL}/resource/file?file_path=${encodeURIComponent(
|
||||
data.file_path
|
||||
)}&download=true`;
|
||||
// image
|
||||
const props = properties ?? {};
|
||||
const isPic = isImage(props.content_type, props.size);
|
||||
if (isPic) {
|
||||
data.thumbnail = `${BASE_URL}/resource/file?file_path=${encodeURIComponent(
|
||||
// image
|
||||
const isPic = isImage(properties.content_type, properties.size);
|
||||
if (isFile) {
|
||||
if (!sending) {
|
||||
data.file_path = content;
|
||||
data.content = `${BASE_URL}/resource/file?file_path=${encodeURIComponent(
|
||||
data.file_path
|
||||
)}&thumbnail=true`;
|
||||
)}`;
|
||||
data.download = `${BASE_URL}/resource/file?file_path=${encodeURIComponent(
|
||||
data.file_path
|
||||
)}&download=true`;
|
||||
data.thumbnail = isPic
|
||||
? `${BASE_URL}/resource/file?file_path=${encodeURIComponent(
|
||||
data.file_path
|
||||
)}&thumbnail=true`
|
||||
: "";
|
||||
} else if (isPic) {
|
||||
data.thumbnail = content;
|
||||
}
|
||||
}
|
||||
state[mid] = data;
|
||||
|
||||
@@ -81,8 +81,8 @@ export default function useMessageFeed({ context = "channel", id = null }) {
|
||||
}, [items, context, id]);
|
||||
useEffect(() => {
|
||||
const serverMids = mids.filter((id) => {
|
||||
const ts = new Date().getTime();
|
||||
return Math.abs(ts - id) > 5 * 1000;
|
||||
const ts = +new Date();
|
||||
return Math.abs(ts - id) > 10 * 1000;
|
||||
});
|
||||
if (listRef.current.length == 0 && serverMids.length) {
|
||||
// 初次
|
||||
@@ -97,11 +97,12 @@ export default function useMessageFeed({ context = "channel", id = null }) {
|
||||
console.log("message pageInfo", serverMids, pageInfo);
|
||||
} else {
|
||||
// 追加
|
||||
const lastMid = listRef.current.slice(-1);
|
||||
const sorteds = serverMids.slice(0).sort((a, b) => {
|
||||
const [lastMid] = listRef.current.slice(-1);
|
||||
const sorteds = mids.slice(0).sort((a, b) => {
|
||||
return Number(a) - Number(b);
|
||||
});
|
||||
const appends = sorteds.filter((s) => s > lastMid);
|
||||
console.log("appends", appends, sorteds, lastMid, mids);
|
||||
if (appends.length) {
|
||||
setAppends(appends);
|
||||
const [newestMsgId] = appends.slice(-1);
|
||||
@@ -122,7 +123,6 @@ export default function useMessageFeed({ context = "channel", id = null }) {
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log("appends", appends, listRef.current);
|
||||
}
|
||||
}, [mids, messageData, loginUid]);
|
||||
const pullUp = async () => {
|
||||
|
||||
Reference in New Issue
Block a user