mirror of
https://github.com/xfgryujk/blivechat.git
synced 2024-12-27 13:20:29 +08:00
修复有时消息不能正确合并的问题
This commit is contained in:
parent
a22496c355
commit
a7faac5425
@ -118,44 +118,63 @@ export default {
|
|||||||
addMessages(messages) {
|
addMessages(messages) {
|
||||||
this.enqueueMessages(messages)
|
this.enqueueMessages(messages)
|
||||||
},
|
},
|
||||||
mergeSimilar(content) {
|
mergeSimilarText(content) {
|
||||||
let remainNum = 5
|
let res = false
|
||||||
for (let arr of [this.messagesBuffer, this.messages]) {
|
this.forEachRecentMessage(5, message => {
|
||||||
for (let i = arr.length - 1; i >= 0 && --remainNum > 0; i--) {
|
if (message.type !== constants.MESSAGE_TYPE_TEXT) {
|
||||||
let message = arr[i]
|
return true
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
let longer, shorter
|
||||||
return false
|
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) {
|
mergeSimilarGift(authorName, price) {
|
||||||
let remainNum = 5
|
let res = false
|
||||||
for (let arr of [this.messagesBuffer, this.messages]) {
|
this.forEachRecentMessage(5, message => {
|
||||||
for (let i = arr.length - 1; i >= 0 && --remainNum > 0; i--) {
|
if (message.type === constants.MESSAGE_TYPE_SUPER_CHAT
|
||||||
let message = arr[i]
|
&& message.content === ''
|
||||||
if (message.type === constants.MESSAGE_TYPE_SUPER_CHAT
|
&& message.authorName === authorName
|
||||||
&& message.content === ''
|
) {
|
||||||
&& message.authorName === authorName
|
message.price += price
|
||||||
) {
|
res = true
|
||||||
message.price += price
|
return false
|
||||||
return true
|
}
|
||||||
|
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) {
|
delMessage(id) {
|
||||||
this.delMessages([id])
|
this.delMessages([id])
|
||||||
|
@ -100,7 +100,7 @@ export default {
|
|||||||
let time = data.timestamp ? new Date(data.timestamp * 1000) : new Date()
|
let time = data.timestamp ? new Date(data.timestamp * 1000) : new Date()
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case COMMAND_ADD_TEXT:
|
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
|
break
|
||||||
}
|
}
|
||||||
message = {
|
message = {
|
||||||
@ -206,11 +206,11 @@ export default {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
mergeSimilar(content) {
|
mergeSimilarText(content) {
|
||||||
if (!this.config.mergeSimilarDanmaku) {
|
if (!this.config.mergeSimilarDanmaku) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return this.$refs.renderer.mergeSimilar(content)
|
return this.$refs.renderer.mergeSimilarText(content)
|
||||||
},
|
},
|
||||||
mergeSimilarGift(authorName, price) {
|
mergeSimilarGift(authorName, price) {
|
||||||
if (!this.config.mergeSimilarDanmaku) {
|
if (!this.config.mergeSimilarDanmaku) {
|
||||||
|
Loading…
Reference in New Issue
Block a user