mirror of
https://github.com/xfgryujk/blivechat.git
synced 2024-12-26 21:00:15 +08:00
修复有时消息不能正确合并的问题
This commit is contained in:
parent
a22496c355
commit
a7faac5425
@ -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])
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user