no message

This commit is contained in:
kuaifan 2024-01-02 14:02:52 +08:00
parent 3b697e7400
commit 0daf06c06d
5 changed files with 65 additions and 81 deletions

View File

@ -100,6 +100,10 @@ export default {
type: Number, type: Number,
default: 0 default: 0
}, },
scrollIng: {
type: Number,
default: 0
},
readEnabled: { readEnabled: {
type: Boolean, type: Boolean,
default: false default: false
@ -150,6 +154,9 @@ export default {
windowActive() { windowActive() {
this.msgRead(); this.msgRead();
}, },
scrollIng() {
this.msgRead();
},
}, },
methods: { methods: {
@ -168,15 +175,6 @@ export default {
} }
// //
this.$store.dispatch("dialogMsgRead", this.source); this.$store.dispatch("dialogMsgRead", this.source);
//
if (this.isUnreadStart
&& $A.getDialogUnread(this.dialogData, true) > 0) {
this.$store.dispatch("dialogMsgMark", {
dialog_id: this.source.dialog_id,
type: 'read',
after_msg_id: this.source.id,
})
}
}, },
formatTodoUser(data) { formatTodoUser(data) {

View File

@ -10,7 +10,7 @@
@touchmove="onTouchMove" @touchmove="onTouchMove"
@touchend="onTouchEnd"> @touchend="onTouchEnd">
<!--顶部导航--> <!--顶部导航-->
<div class="dialog-nav" :style="navStyle"> <div ref="nav" class="dialog-nav">
<slot name="head"> <slot name="head">
<div class="nav-wrapper" :class="{completed: $A.dialogCompleted(dialogData)}"> <div class="nav-wrapper" :class="{completed: $A.dialogCompleted(dialogData)}">
<div class="dialog-back" @click="onBack"> <div class="dialog-back" @click="onBack">
@ -138,7 +138,7 @@
<!--跳转提示--> <!--跳转提示-->
<div v-if="positionShow && positionMsg" class="dialog-position" :class="{'down': tagShow}"> <div v-if="positionShow && positionMsg" class="dialog-position" :class="{'down': tagShow}">
<div class="position-label" @click="onPositionMark"> <div class="position-label" @click="onPositionMark(positionMsg.msg_id)">
<Icon v-if="positionLoad > 0" type="ios-loading" class="icon-loading"></Icon> <Icon v-if="positionLoad > 0" type="ios-loading" class="icon-loading"></Icon>
<i v-else class="taskfont">&#xe624;</i> <i v-else class="taskfont">&#xe624;</i>
{{positionMsg.label}} {{positionMsg.label}}
@ -156,7 +156,7 @@
:data-component="msgItem" :data-component="msgItem"
:item-class-add="itemClassAdd" :item-class-add="itemClassAdd"
:extra-props="{dialogData, operateVisible, operateItem, isMyDialog, msgId, unreadMsgId, readEnabled}" :extra-props="{dialogData, operateVisible, operateItem, isMyDialog, msgId, unreadMsgId, scrollIng, readEnabled}"
:estimate-size="dialogData.type=='group' ? 105 : 77" :estimate-size="dialogData.type=='group' ? 105 : 77"
:keeps="keeps" :keeps="keeps"
:disabled="scrollDisabled" :disabled="scrollDisabled"
@ -185,7 +185,7 @@
</VirtualList> </VirtualList>
<!--底部输入--> <!--底部输入-->
<div ref="footer" class="dialog-footer" :class="footerClass" :style="footerStyle" @click="onActive"> <div ref="footer" class="dialog-footer" :class="footerClass" @click="onActive">
<div class="dialog-newmsg" @click="onToBottom">{{$L(`${msgNew}条新消息`)}}</div> <div class="dialog-newmsg" @click="onToBottom">{{$L(`${msgNew}条新消息`)}}</div>
<div class="dialog-goto" @click="onToBottom"><i class="taskfont">&#xe72b;</i></div> <div class="dialog-goto" @click="onToBottom"><i class="taskfont">&#xe72b;</i></div>
<DialogUpload <DialogUpload
@ -637,6 +637,7 @@ export default {
msgNew: 0, msgNew: 0,
msgType: '', msgType: '',
loadIng: 0, loadIng: 0,
isFocus: false,
allMsgs: [], allMsgs: [],
tempMsgs: [], tempMsgs: [],
@ -679,8 +680,6 @@ export default {
disabledChoice: [] disabledChoice: []
}, },
navStyle: {},
operateClient: {x: 0, y: 0}, operateClient: {x: 0, y: 0},
operateVisible: false, operateVisible: false,
operatePreventScroll: 0, operatePreventScroll: 0,
@ -722,6 +721,7 @@ export default {
scrollDirection: null, scrollDirection: null,
scrollAction: 0, scrollAction: 0,
scrollTmp: 0, scrollTmp: 0,
scrollIng: 0,
approveDetails: {id: 0}, approveDetails: {id: 0},
approveDetailsShow: false, approveDetailsShow: false,
@ -732,9 +732,9 @@ export default {
unreadMsgId: 0, // id unreadMsgId: 0, // id
positionLoad: 0, // positionLoad: 0, //
positionShow: false, // positionShow: false, //
firstMsgLength: 0, // renderMsgLength: 0, //
msgPreparedStatus: false, // msgPreparedStatus: false, //
listPreparedStatus: false, // listPreparedStatus: false, //
selectedTextStatus: false, // selectedTextStatus: false, //
scrollToBottomAndRefresh: false, // scrollToBottomAndRefresh: false, //
} }
@ -776,8 +776,8 @@ export default {
'fileLinks', 'fileLinks',
'cacheEmojis', 'cacheEmojis',
'readReqNum', 'readLoadNum',
'readReqLoad', 'readTimeout',
'keyboardType', 'keyboardType',
'keyboardHeight', 'keyboardHeight',
'safeAreaBottom' 'safeAreaBottom'
@ -953,8 +953,9 @@ export default {
return null return null
}, },
footerPaddingBottom({keyboardType, keyboardHeight, safeAreaBottom, windowScrollY, isMessenger}) { footerPaddingBottom({keyboardType, keyboardHeight, safeAreaBottom, windowScrollY, isMessenger, isFocus}) {
if (windowScrollY === 0 if (windowScrollY === 0
&& isFocus
&& isMessenger && isMessenger
&& keyboardType === "show" && keyboardType === "show"
&& keyboardHeight > 0 && keyboardHeight > 0
@ -964,14 +965,6 @@ export default {
return 0; return 0;
}, },
footerStyle({footerPaddingBottom}) {
const style = {};
if (footerPaddingBottom) {
style.paddingBottom = `${footerPaddingBottom}px`;
}
return style;
},
msgUnreadOnly() { msgUnreadOnly() {
let num = 0; let num = 0;
this.cacheDialogs.some(dialog => { this.cacheDialogs.some(dialog => {
@ -1055,7 +1048,7 @@ export default {
return true return true
})) }))
if (item.label === '{UNREAD}') { if (item.label === '{UNREAD}') {
item.label = this.$L(`未读消息${unread}`) item.label = this.$L(`未读消息${unread - msgNew}`)
} }
return item return item
}, },
@ -1093,7 +1086,7 @@ export default {
this.positionShow = false this.positionShow = false
this.listPreparedStatus = false this.listPreparedStatus = false
this.scrollToBottomAndRefresh = false this.scrollToBottomAndRefresh = false
this.firstMsgLength = Math.min(this.keeps, Math.max(this.allMsgList.length, 1)) this.renderMsgLength = Math.min(this.keeps, Math.max(this.allMsgList.length, 1))
this.allMsgs = this.allMsgList this.allMsgs = this.allMsgList
// //
const tmpMsgA = this.allMsgList.map(({id, msg, emoji}) => { const tmpMsgA = this.allMsgList.map(({id, msg, emoji}) => {
@ -1106,15 +1099,22 @@ export default {
}).then(_ => { }).then(_ => {
this.openId = dialog_id this.openId = dialog_id
this.listPreparedStatus = true this.listPreparedStatus = true
//
const {position_msgs} = this.dialogData
if ($A.isArray(position_msgs)) {
this.unreadMsgId = position_msgs.find(item => item.label === '{UNREAD}')?.msg_id || 0
}
//
const tmpMsgB = this.allMsgList.map(({id, msg, emoji}) => { const tmpMsgB = this.allMsgList.map(({id, msg, emoji}) => {
return {id, msg, emoji} return {id, msg, emoji}
}) })
if (JSON.stringify(tmpMsgA) != JSON.stringify(tmpMsgB)) { if (JSON.stringify(tmpMsgA) != JSON.stringify(tmpMsgB)) {
this.firstMsgLength = Math.min(this.keeps, Math.max(this.allMsgList.length, 1)) this.renderMsgLength = Math.min(this.keeps, Math.max(this.allMsgList.length, 1))
} }
//
setTimeout(_ => { setTimeout(_ => {
this.positionShow = this.readReqLoad === 0
this.onSearchMsgId() this.onSearchMsgId()
this.positionShow = this.readTimeout === null
}, 100) }, 100)
}).catch(_ => {}); }).catch(_ => {});
// //
@ -1287,9 +1287,7 @@ export default {
windowScrollY(val) { windowScrollY(val) {
if ($A.isIos() && !this.$slots.head) { if ($A.isIos() && !this.$slots.head) {
const {tail} = this.scrollInfo(); const {tail} = this.scrollInfo();
this.navStyle = { this.$refs.nav.style.marginTop = `${val}px`
marginTop: val + 'px'
}
if (tail <= 55) { if (tail <= 55) {
requestAnimationFrame(this.onToBottom) requestAnimationFrame(this.onToBottom)
} }
@ -1309,7 +1307,7 @@ export default {
if (current < before if (current < before
&& $A.isEEUiApp && $A.isEEUiApp
&& $A.isAndroid() && $A.isAndroid()
&& this.$refs.input.isFocus) { && this.isFocus) {
const {tail} = this.scrollInfo(); const {tail} = this.scrollInfo();
if (tail <= 55 + (before - current)) { if (tail <= 55 + (before - current)) {
requestAnimationFrame(this.onToBottom) requestAnimationFrame(this.onToBottom)
@ -1329,18 +1327,12 @@ export default {
} }
}, },
positionMsg() { footerPaddingBottom(val) {
const {unread, position_msgs} = this.dialogData this.$refs.footer.style.paddingBottom = `${val}px`;
if (!$A.isArray(position_msgs) || unread < 2) { requestAnimationFrame(this.onFooterResize)
return
}
const msg = position_msgs.find(item => item.label === '{UNREAD}')
if (msg) {
this.unreadMsgId = msg.msg_id
}
}, },
readReqNum() { readLoadNum() {
this.positionShow = true this.positionShow = true
}, },
}, },
@ -1928,10 +1920,12 @@ export default {
}, },
onEventFocus() { onEventFocus() {
this.isFocus = true
this.$emit("on-focus") this.$emit("on-focus")
}, },
onEventBlur() { onEventBlur() {
this.isFocus = false
this.$emit("on-blur") this.$emit("on-blur")
}, },
@ -2179,8 +2173,8 @@ export default {
if (!this.$refs.scroller || !this.$refs.footer) { if (!this.$refs.scroller || !this.$refs.footer) {
return return
} }
if (this.firstMsgLength > 0 && this.$refs.scroller.getSizes() >= this.firstMsgLength) { if (this.renderMsgLength > 0 && this.$refs.scroller.getSizes() >= this.renderMsgLength) {
this.firstMsgLength = 0 this.renderMsgLength = 0
this.onFooterResize() this.onFooterResize()
this.onToBottom() this.onToBottom()
} }
@ -2476,6 +2470,9 @@ export default {
this.scrollAction = event.target.scrollTop; this.scrollAction = event.target.scrollTop;
this.scrollDirection = this.scrollTmp <= this.scrollAction ? 'down' : 'up'; this.scrollDirection = this.scrollTmp <= this.scrollAction ? 'down' : 'up';
setTimeout(_ => this.scrollTmp = this.scrollAction, 0); setTimeout(_ => this.scrollTmp = this.scrollAction, 0);
//
this.scrollIng++;
setTimeout(_=> this.scrollIng--, 100);
}, },
onRange(range) { onRange(range) {
@ -3191,36 +3188,13 @@ export default {
} }
}, },
onPositionMark() { onPositionMark(id) {
if (this.positionLoad > 0) { if (this.positionLoad > 0) {
return; return;
} }
this.positionLoad++ this.positionLoad++
// //
const positionMsgs = [] this.onPositionId(id).finally(_ => {
this.dialogData.position_msgs.forEach(item => {
if (!this.allMsgs.find(({id}) => id == item.msg_id)?.read_at) {
positionMsgs.push(item)
}
})
this.$store.dispatch("saveDialog", {
id: this.dialogData.id,
position_msgs: positionMsgs
});
//
const {msg_id} = this.positionMsg;
this.$store.dispatch("dialogMsgMark", {
dialog_id: this.dialogId,
type: 'read',
after_msg_id: msg_id,
}).then(_ => {
this.positionLoad++
this.onPositionId(msg_id).finally(_ => {
this.positionLoad--
})
}).catch(({msg}) => {
$A.modalError(msg)
}).finally(_ => {
this.positionLoad-- this.positionLoad--
}) })
}, },

View File

@ -997,8 +997,8 @@ export default {
handleReadClick() { handleReadClick() {
this.$store.dispatch("showSpinner", 600) this.$store.dispatch("showSpinner", 600)
this.$store.dispatch("dialogMsgMark", { this.$store.dispatch("dialogMsgMark", {
type: $A.getDialogUnread(this.operateItem, true) > 0 ? 'read' : 'unread',
dialog_id: this.operateItem.id, dialog_id: this.operateItem.id,
type: $A.getDialogUnread(this.operateItem, true) > 0 ? 'read' : 'unread'
}).catch(({msg}) => { }).catch(({msg}) => {
$A.modalError(msg) $A.modalError(msg)
}).finally(_ => { }).finally(_ => {

View File

@ -2889,13 +2889,12 @@ export default {
saveBefore() saveBefore()
const resData = result.data; const resData = result.data;
if ($A.isJson(resData.dialog)) { if ($A.isJson(resData.dialog)) {
setTimeout(_ => dispatch("saveDialog", resData.dialog), 10) // 延迟更新对话详情是因为等消息处理完
//
const ids = resData.list.map(({id}) => id) const ids = resData.list.map(({id}) => id)
state.dialogMsgs = state.dialogMsgs.filter(item => { state.dialogMsgs = state.dialogMsgs.filter(item => {
return item.dialog_id != data.dialog_id || ids.includes(item.id) || $A.Time(item.created_at) >= resData.time return item.dialog_id != data.dialog_id || ids.includes(item.id) || $A.Time(item.created_at) >= resData.time
}); });
$A.IDBSave("dialogMsgs", state.dialogMsgs, 600) $A.IDBSave("dialogMsgs", state.dialogMsgs, 600)
dispatch("saveDialog", resData.dialog)
} }
if ($A.isArray(resData.todo)) { if ($A.isArray(resData.todo)) {
state.dialogTodos = state.dialogTodos.filter(item => item.dialog_id != data.dialog_id) state.dialogTodos = state.dialogTodos.filter(item => item.dialog_id != data.dialog_id)
@ -2993,9 +2992,25 @@ export default {
if (data.read_at) return; if (data.read_at) return;
data.read_at = $A.formatDate(); data.read_at = $A.formatDate();
state.readWaitData[data.id] = data.id; state.readWaitData[data.id] = data.id;
//
const dialog = state.cacheDialogs.find(({id}) => id == data.dialog_id);
if (dialog && $A.isArray(dialog.position_msgs)) {
const index = dialog.position_msgs.findIndex(({msg_id}) => msg_id == data.id);
if (index > -1) {
dialog.position_msgs.splice(index, 1);
dispatch("saveDialog", dialog)
}
dispatch("dialogMsgMark", {
type: 'read',
dialog_id: data.dialog_id,
after_msg_id: data.id,
})
}
} }
clearTimeout(state.readTimeout); clearTimeout(state.readTimeout);
state.readTimeout = setTimeout(_ => { state.readTimeout = setTimeout(_ => {
state.readTimeout = null;
//
if (state.userId === 0) { if (state.userId === 0) {
return; return;
} }
@ -3005,7 +3020,6 @@ export default {
return return
} }
// //
state.readReqLoad++
dispatch("call", { dispatch("call", {
url: 'dialog/msg/read', url: 'dialog/msg/read',
data: { data: {
@ -3018,8 +3032,7 @@ export default {
state.readWaitData[id] = id; state.readWaitData[id] = id;
}) })
}).finally(_ => { }).finally(_ => {
state.readReqLoad-- state.readLoadNum++
state.readReqNum++
}); });
}, 50); }, 50);
}, },

View File

@ -124,8 +124,7 @@ export default {
messengerSearchKey: {dialog: '', contacts: ''}, messengerSearchKey: {dialog: '', contacts: ''},
// 阅读消息 // 阅读消息
readReqLoad: 0, readLoadNum: 0,
readReqNum: 0,
readTimeout: null, readTimeout: null,
readWaitData: {}, readWaitData: {},