feat(ads): server-driven ad-banner backend, wire & admin console (PR1)
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 14s
CI / ui (pull_request) Successful in 49s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m12s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 14s
CI / ui (pull_request) Successful in 49s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m12s
Turn the gated-off mock banner into a real advertising subsystem (backend + admin half; the UI rotation lands in PR2). - internal/ads: campaigns (percent weight + validity window; a perpetual, undeletable default that fills the remainder up to 100%), 1..N bilingual messages (en+ru), global display timings; ActiveSet computes the window-filtered, default-remainder, GCD-reduced, language-resolved rotation feed. Smooth-weighted-round-robin math is unit-tested. - migration 00006 (+ jetgen): ad_campaigns / ad_messages / ad_settings, seeded default campaign + house message + default timings. - eligibility = !paid_account && hint_balance==0 && !no_banner role (new role; guests qualify). The resolved feed rides the profile.get response (no new RPC, works for guests, nothing distinct to filter); language by service_language. - live update: a notify `banner` sub-kind (re-poll signal) published when an operator grants hints or grants/revokes no_banner, so the client shows/hides in place. - admin console /_gm/banners (+ /_gm/banner-settings): campaign + message CRUD with reorder, default protection, clamped timings. - wire: fbs BannerInfo/BannerCampaign on Profile; gateway transcode forwards it. - docs: ARCHITECTURE §10, FUNCTIONAL (+ _ru), backend README, PRERELEASE tracker (incl. the deferred app.load aggregator note).
This commit is contained in:
@@ -58,7 +58,8 @@ func encodeAck(ok bool) []byte {
|
||||
return b.FinishedBytes()
|
||||
}
|
||||
|
||||
// encodeProfile builds a Profile payload.
|
||||
// encodeProfile builds a Profile payload, including the advertising-banner block
|
||||
// when the backend marked the viewer eligible.
|
||||
func encodeProfile(p backendclient.ProfileResp) []byte {
|
||||
b := flatbuffers.NewBuilder(192)
|
||||
uid := b.CreateString(p.UserID)
|
||||
@@ -67,6 +68,12 @@ func encodeProfile(p backendclient.ProfileResp) []byte {
|
||||
tz := b.CreateString(p.TimeZone)
|
||||
awayStart := b.CreateString(p.AwayStart)
|
||||
awayEnd := b.CreateString(p.AwayEnd)
|
||||
// Build the banner table (and its children) before opening Profile: FlatBuffers
|
||||
// forbids a nested table while another is under construction.
|
||||
var banner flatbuffers.UOffsetT
|
||||
if p.Banner != nil {
|
||||
banner = encodeBanner(b, *p.Banner)
|
||||
}
|
||||
fb.ProfileStart(b)
|
||||
fb.ProfileAddUserId(b, uid)
|
||||
fb.ProfileAddDisplayName(b, name)
|
||||
@@ -79,10 +86,51 @@ func encodeProfile(p backendclient.ProfileResp) []byte {
|
||||
fb.ProfileAddAwayStart(b, awayStart)
|
||||
fb.ProfileAddAwayEnd(b, awayEnd)
|
||||
fb.ProfileAddNotificationsInAppOnly(b, p.NotificationsInAppOnly)
|
||||
if p.Banner != nil {
|
||||
fb.ProfileAddBanner(b, banner)
|
||||
}
|
||||
b.Finish(fb.ProfileEnd(b))
|
||||
return b.FinishedBytes()
|
||||
}
|
||||
|
||||
// encodeBanner builds a BannerInfo table from the resolved banner block and
|
||||
// returns its offset. It is bottom-up: each campaign's messages vector and table
|
||||
// are built first, then the campaigns vector, then the BannerInfo table. The
|
||||
// caller must invoke it with no table under construction.
|
||||
func encodeBanner(b *flatbuffers.Builder, banner backendclient.BannerResp) flatbuffers.UOffsetT {
|
||||
campOffsets := make([]flatbuffers.UOffsetT, len(banner.Campaigns))
|
||||
for i, c := range banner.Campaigns {
|
||||
msgOffsets := make([]flatbuffers.UOffsetT, len(c.Messages))
|
||||
for j, m := range c.Messages {
|
||||
msgOffsets[j] = b.CreateString(m)
|
||||
}
|
||||
fb.BannerCampaignStartMessagesVector(b, len(msgOffsets))
|
||||
for j := len(msgOffsets) - 1; j >= 0; j-- {
|
||||
b.PrependUOffsetT(msgOffsets[j])
|
||||
}
|
||||
msgs := b.EndVector(len(msgOffsets))
|
||||
fb.BannerCampaignStart(b)
|
||||
fb.BannerCampaignAddWeight(b, int32(c.Weight))
|
||||
fb.BannerCampaignAddMessages(b, msgs)
|
||||
campOffsets[i] = fb.BannerCampaignEnd(b)
|
||||
}
|
||||
fb.BannerInfoStartCampaignsVector(b, len(campOffsets))
|
||||
for i := len(campOffsets) - 1; i >= 0; i-- {
|
||||
b.PrependUOffsetT(campOffsets[i])
|
||||
}
|
||||
camps := b.EndVector(len(campOffsets))
|
||||
t := banner.Timings
|
||||
fb.BannerInfoStart(b)
|
||||
fb.BannerInfoAddCampaigns(b, camps)
|
||||
fb.BannerInfoAddHoldMs(b, int32(t.HoldMs))
|
||||
fb.BannerInfoAddEdgePauseMs(b, int32(t.EdgePauseMs))
|
||||
fb.BannerInfoAddScrollPxPerSec(b, int32(t.ScrollPxPerSec))
|
||||
fb.BannerInfoAddFadeOutMs(b, int32(t.FadeOutMs))
|
||||
fb.BannerInfoAddGapMs(b, int32(t.GapMs))
|
||||
fb.BannerInfoAddFadeInMs(b, int32(t.FadeInMs))
|
||||
return fb.BannerInfoEnd(b)
|
||||
}
|
||||
|
||||
// encodeBlockStatus builds a BlockStatus payload.
|
||||
func encodeBlockStatus(s backendclient.BlockStatusResp) []byte {
|
||||
b := flatbuffers.NewBuilder(128)
|
||||
|
||||
Reference in New Issue
Block a user