显示免费礼物、最低显示打赏价格默认值改为0.1

This commit is contained in:
John Smith 2024-02-05 01:24:56 +08:00
parent 263bf80546
commit 17915faa07
12 changed files with 57 additions and 25 deletions

View File

@ -312,6 +312,12 @@ class ChatHandler(tornado.websocket.WebSocketHandler):
gift_data['totalCoin'] = 1245000
gift_data['giftName'] = '小电视飞船'
self.send_cmd_data(Command.ADD_GIFT, gift_data)
gift_data['id'] = uuid.uuid4().hex
gift_data['totalCoin'] = 0
gift_data['totalFreeCoin'] = 1000
gift_data['giftName'] = '辣条'
gift_data['num'] = 10
self.send_cmd_data(Command.ADD_GIFT, gift_data)
class RoomInfoHandler(api.base.ApiHandler):

View File

@ -182,16 +182,14 @@ export default class ChatClientDirectOpenLive extends ChatClientOfficialBase {
sendGiftCallback(command) {
let data = command.data
if (!data.paid) { // 丢人
return
}
let totalCoin = data.price * data.gift_num
data = new chatModels.AddGiftMsg({
id: data.msg_id,
avatarUrl: chat.processAvatarUrl(data.uface),
timestamp: data.timestamp,
authorName: data.uname,
totalCoin: data.price * data.gift_num,
totalCoin: data.paid ? totalCoin : 0,
totalFreeCoin: !data.paid ? totalCoin : 0,
giftName: data.gift_name,
num: data.gift_num
})

View File

@ -107,15 +107,13 @@ export default class ChatClientDirectWeb extends ChatClientOfficialBase {
sendGiftCallback(command) {
let data = command.data
if (data.coin_type !== 'gold') { // 丢人
return
}
let isPaidGift = data.coin_type === 'gold'
data = new chatModels.AddGiftMsg({
avatarUrl: chat.processAvatarUrl(data.face),
timestamp: data.timestamp,
authorName: data.uname,
totalCoin: data.total_coin,
totalCoin: isPaidGift ? data.total_coin : 0,
totalFreeCoin: !isPaidGift ? data.total_coin : 0,
giftName: data.giftName,
num: data.num
})

View File

@ -144,10 +144,6 @@ export default class ChatClientRelay {
break
}
case COMMAND_ADD_GIFT: {
// TODO 显示免费礼物
if (data.totalCoin === 0) { // 丢人
return
}
data = new chatModels.AddGiftMsg(data)
this.msgHandler.onAddGift(data)
break

View File

@ -87,6 +87,7 @@ function randGuardInfo() {
}
const GIFT_INFO_LIST = [
{ giftName: '辣条', totalFreeCoin: 1000, num: 10 },
{ giftName: 'B坷垃', totalCoin: 9900 },
{ giftName: '礼花', totalCoin: 28000 },
{ giftName: '花式夸夸', totalCoin: 39000 },

View File

@ -43,6 +43,7 @@ export class AddGiftMsg {
timestamp = new Date().getTime() / 1000,
authorName = '',
totalCoin = 0,
totalFreeCoin = 0,
giftName = '',
num = 1,
} = {}) {
@ -51,6 +52,7 @@ export class AddGiftMsg {
this.timestamp = timestamp
this.authorName = authorName
this.totalCoin = totalCoin
this.totalFreeCoin = totalFreeCoin
this.giftName = giftName
this.num = num
}

View File

@ -3,7 +3,7 @@ import _ from 'lodash'
import { mergeConfig } from '@/utils'
export const DEFAULT_CONFIG = {
minGiftPrice: 7, // $1
minGiftPrice: 0.1,
showDanmaku: true,
showGift: true,
showGiftName: false,

View File

@ -18,7 +18,7 @@
<div id="header-content" class="style-scope yt-live-chat-paid-message-renderer">
<div id="header-content-primary-column" class="style-scope yt-live-chat-paid-message-renderer">
<div id="author-name" class="style-scope yt-live-chat-paid-message-renderer">{{ authorName }}</div>
<div id="purchase-amount" class="style-scope yt-live-chat-paid-message-renderer">{{ priceText }}</div>
<div id="purchase-amount" class="style-scope yt-live-chat-paid-message-renderer">{{ showPriceText }}</div>
</div>
<span id="timestamp" class="style-scope yt-live-chat-paid-message-renderer">{{ timeText }}</span>
</div>
@ -44,6 +44,7 @@ export default {
avatarUrl: String,
authorName: String,
price: Number, //
priceText: String,
time: Date,
content: String
},
@ -54,8 +55,8 @@ export default {
color() {
return this.priceConfig.colors
},
priceText() {
return `CN¥${utils.formatCurrency(this.price)}`
showPriceText() {
return this.priceText || `CN¥${utils.formatCurrency(this.price)}`
},
timeText() {
return utils.getTimeTextHourMin(this.time)

View File

@ -138,6 +138,20 @@ export const PRICE_CONFIGS = [
pinTime: 0,
priceLevel: 1,
},
// $0淡蓝
{
price: 0,
colors: {
contentBg: 'rgba(153, 236, 255, 1)',
headerBg: 'rgba(153, 236, 255, 1)',
header: 'rgba(255,255,255,1)',
authorName: 'rgba(255,255,255,0.701961)',
time: 'rgba(255,255,255,0.501961)',
content: 'rgba(255,255,255,1)'
},
pinTime: 0,
priceLevel: 0,
},
]
export function getPriceConfig(price) {
@ -174,6 +188,10 @@ export function getGiftShowContent(message, showGiftName) {
return i18n.i18n.t('chat.sendGift', { giftName: message.giftName, num: message.num })
}
export function getGiftShowNameAndNum(message) {
return `${message.giftName}x${message.num}`
}
export function getShowAuthorName(message) {
if (message.authorNamePronunciation && message.authorNamePronunciation !== message.authorName) {
return `${message.authorName}(${message.authorNamePronunciation})`

View File

@ -26,7 +26,8 @@
:avatarUrl="message.avatarUrl"
:authorName="getShowAuthorName(message)"
:price="message.price"
:content="getGiftShowContent(message)"
:priceText="message.price <= 0 ? getGiftShowNameAndNum(message) : ''"
:content="message.price <= 0 ? '' : getGiftShowContent(message)"
></paid-message>
<membership-item :key="message.id" v-else-if="message.type === MESSAGE_TYPE_MEMBER"
class="style-scope yt-live-chat-item-list-renderer"
@ -150,6 +151,7 @@ export default {
getGiftShowContent(message) {
return constants.getGiftShowContent(message, this.showGiftName)
},
getGiftShowNameAndNum: constants.getGiftShowNameAndNum,
getShowContent: constants.getShowContent,
getShowRichContent: constants.getShowRichContent,
getShowAuthorName: constants.getShowAuthorName,
@ -190,7 +192,7 @@ export default {
}
return false
},
mergeSimilarGift(authorName, price, giftName, num) {
mergeSimilarGift(authorName, price, _freePrice, giftName, num) {
for (let message of this.iterRecentMessages(5)) {
if (
message.type === constants.MESSAGE_TYPE_GIFT
@ -199,6 +201,7 @@ export default {
) {
this.updateMessage(message.id, { $add: {
price: price,
// freePrice: freePrice, //
num: num
} })
return true

View File

@ -21,6 +21,14 @@ export function toInt(val, _default) {
return res
}
export function toFloat(val, _default) {
let res = parseFloat(val)
if (isNaN(res)) {
res = _default
}
return res
}
export function formatCurrency(price) {
return new Intl.NumberFormat('zh-CN', {
minimumFractionDigits: price < 100 ? 2 : 0

View File

@ -4,7 +4,7 @@
<script>
import * as i18n from '@/i18n'
import { mergeConfig, toBool, toInt } from '@/utils'
import { mergeConfig, toBool, toInt, toFloat } from '@/utils'
import * as trie from '@/utils/trie'
import * as pronunciation from '@/utils/pronunciation'
import * as chatConfig from '@/api/chatConfig'
@ -153,7 +153,7 @@ export default {
}
cfg = mergeConfig(cfg, chatConfig.deepCloneDefaultConfig())
cfg.minGiftPrice = toInt(cfg.minGiftPrice, chatConfig.DEFAULT_CONFIG.minGiftPrice)
cfg.minGiftPrice = toFloat(cfg.minGiftPrice, chatConfig.DEFAULT_CONFIG.minGiftPrice)
cfg.showDanmaku = toBool(cfg.showDanmaku)
cfg.showGift = toBool(cfg.showGift)
cfg.showGiftName = toBool(cfg.showGiftName)
@ -270,7 +270,7 @@ export default {
return
}
let price = data.totalCoin / 1000
if (this.mergeSimilarGift(data.authorName, price, data.giftName, data.num)) {
if (this.mergeSimilarGift(data.authorName, price, data.totalFreeCoin, data.giftName, data.num)) {
return
}
if (price < this.config.minGiftPrice) { //
@ -284,6 +284,7 @@ export default {
authorName: data.authorName,
authorNamePronunciation: this.getPronunciation(data.authorName),
price: price,
// freePrice: data.totalFreeCoin, //
giftName: data.giftName,
num: data.num
}
@ -391,11 +392,11 @@ export default {
}
return this.$refs.renderer.mergeSimilarText(content)
},
mergeSimilarGift(authorName, price, giftName, num) {
mergeSimilarGift(authorName, price, freePrice, giftName, num) {
if (!this.config.mergeGift) {
return false
}
return this.$refs.renderer.mergeSimilarGift(authorName, price, giftName, num)
return this.$refs.renderer.mergeSimilarGift(authorName, price, freePrice, giftName, num)
},
getPronunciation(text) {
if (this.pronunciationConverter === null) {