修复有时消息不能正确合并的问题

This commit is contained in:
John Smith 2019-11-30 23:57:52 +08:00
parent a22496c355
commit a7faac5425
2 changed files with 54 additions and 35 deletions

View File

@ -118,44 +118,63 @@ export default {
addMessages(messages) {
this.enqueueMessages(messages)
},
mergeSimilar(content) {
let remainNum = 5
for (let arr of [this.messagesBuffer, this.messages]) {
for (let i = arr.length - 1; i >= 0 && --remainNum > 0; i--) {
let message = arr[i]
let longer, shorter
if (message.content.length > content.length) {
longer = message.content
shorter = content
} else {
longer = content
shorter = message.content
}
if (longer.indexOf(shorter) !== -1 //
&& longer.length - shorter.length < shorter.length //
) {
message.repeated++
return true
}
mergeSimilarText(content) {
let res = false
this.forEachRecentMessage(5, message => {
if (message.type !== constants.MESSAGE_TYPE_TEXT) {
return true
}
}
return false
let longer, shorter
if (message.content.length > content.length) {
longer = message.content
shorter = content
} else {
longer = content
shorter = message.content
}
if (longer.indexOf(shorter) !== -1 //
&& longer.length - shorter.length < shorter.length //
) {
message.repeated++
res = true
return false
}
return true
})
return res
},
mergeSimilarGift(authorName, price) {
let remainNum = 5
for (let arr of [this.messagesBuffer, this.messages]) {
for (let i = arr.length - 1; i >= 0 && --remainNum > 0; i--) {
let message = arr[i]
if (message.type === constants.MESSAGE_TYPE_SUPER_CHAT
&& message.content === ''
&& message.authorName === authorName
) {
message.price += price
return true
let res = false
this.forEachRecentMessage(5, message => {
if (message.type === constants.MESSAGE_TYPE_SUPER_CHAT
&& message.content === ''
&& message.authorName === authorName
) {
message.price += price
res = true
return false
}
return true
})
return res
},
forEachRecentMessage(num, callback) {
// num
for (let i = this.smoothedMessageQueue.length - 1; i >= 0 && num > 0; i--) {
let messageGroup = this.smoothedMessageQueue[i]
for (let j = messageGroup.length - 1; j >= 0 && num-- > 0; j--) {
if (!callback(messageGroup[j])) {
return
}
}
}
for (let arr of [this.messagesBuffer, this.messages]) {
for (let i = arr.length - 1; i >= 0 && num-- > 0; i--) {
if (!callback(arr[i])) {
return
}
}
}
return false
},
delMessage(id) {
this.delMessages([id])

View File

@ -100,7 +100,7 @@ export default {
let time = data.timestamp ? new Date(data.timestamp * 1000) : new Date()
switch (cmd) {
case COMMAND_ADD_TEXT:
if (!this.config.showDanmaku || !this.filterTextMessage(data) || this.mergeSimilar(data.content)) {
if (!this.config.showDanmaku || !this.filterTextMessage(data) || this.mergeSimilarText(data.content)) {
break
}
message = {
@ -206,11 +206,11 @@ export default {
}
return true
},
mergeSimilar(content) {
mergeSimilarText(content) {
if (!this.config.mergeSimilarDanmaku) {
return false
}
return this.$refs.renderer.mergeSimilar(content)
return this.$refs.renderer.mergeSimilarText(content)
},
mergeSimilarGift(authorName, price) {
if (!this.config.mergeSimilarDanmaku) {