fix: useMessageFeed

This commit is contained in:
zerosoul
2022-06-10 20:26:03 +08:00
parent b2c4f17eae
commit 64229a8011
2 changed files with 22 additions and 19 deletions
+17 -14
View File
@@ -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;
+5 -5
View File
@@ -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 () => {