fix:对齐金值的报名验证,商城入口逻辑对齐
This commit is contained in:
1 parent
3b089e2205
commit
7b1852d9a6
20 files changed
+682
-116
No files matched your search
@@ -19,7 +19,10 @@ class MallTabConfig {
|
||||
this.adId = '',
|
||||
this.trackingId = '',
|
||||
this.openMode = 'in_app',
|
||||
this.badgeText = '',
|
||||
this.entryPromoEnabled = false,
|
||||
this.entryBadgeText = '',
|
||||
this.entryTipTitle = '',
|
||||
this.entryTipBody = '',
|
||||
});
|
||||
|
||||
const MallTabConfig.disabled() : this(enabled: false, url: '');
|
||||
@@ -30,10 +33,19 @@ class MallTabConfig {
|
||||
final String adId;
|
||||
final String trackingId;
|
||||
final String openMode;
|
||||
final String badgeText;
|
||||
final bool entryPromoEnabled;
|
||||
final String entryBadgeText;
|
||||
final String entryTipTitle;
|
||||
final String entryTipBody;
|
||||
|
||||
bool get isVisible => enabled && initialUri != null;
|
||||
bool get opensInApp => openMode == 'in_app';
|
||||
bool get showsEntryBadge =>
|
||||
isVisible && entryPromoEnabled && entryBadgeText.trim().isNotEmpty;
|
||||
bool get showsEntryTip =>
|
||||
isVisible &&
|
||||
entryPromoEnabled &&
|
||||
(entryTipTitle.trim().isNotEmpty || entryTipBody.trim().isNotEmpty);
|
||||
|
||||
Uri? get initialUri => attributedUri(clickId: '');
|
||||
|
||||
@@ -91,24 +103,8 @@ class MallTabConfigController extends StateNotifier<MallTabConfig> {
|
||||
queryParameters: const {'placement': 'mall_tab'},
|
||||
options: protobufOptions(),
|
||||
);
|
||||
final reply = _ProtoMessage(response.data ?? const []).message(2);
|
||||
final enabled = _ProtoMessage(response.data ?? const []).integer(1) != 0;
|
||||
final trackedUrl = reply.string(14);
|
||||
final h5Url = reply.string(9);
|
||||
final url = _validUrl(trackedUrl) ?? _validUrl(h5Url);
|
||||
if (!enabled || url == null) {
|
||||
state = const MallTabConfig.disabled();
|
||||
return;
|
||||
}
|
||||
state = MallTabConfig(
|
||||
enabled: true,
|
||||
url: url,
|
||||
title: _nonEmpty(reply.string(4), '商城'),
|
||||
adId: reply.string(1),
|
||||
trackingId: reply.string(10),
|
||||
openMode: _openMode(reply.integer(15)),
|
||||
badgeText: reply.string(17).trim(),
|
||||
);
|
||||
state = parseMallTabConfigResponse(response.data ?? const []);
|
||||
if (!state.isVisible) return;
|
||||
await _report('ad_impression');
|
||||
} catch (_) {
|
||||
state = const MallTabConfig.disabled();
|
||||
@@ -216,6 +212,30 @@ String _openMode(int value) => switch (value) {
|
||||
_ => 'external',
|
||||
};
|
||||
|
||||
/// Parses the protobuf reply returned by `/api/v1/ads?placement=mall_tab`.
|
||||
MallTabConfig parseMallTabConfigResponse(List<int> bytes) {
|
||||
final response = _ProtoMessage(bytes);
|
||||
final reply = response.message(2);
|
||||
final trackedUrl = reply.string(14);
|
||||
final h5Url = reply.string(9);
|
||||
final url = _validUrl(trackedUrl) ?? _validUrl(h5Url);
|
||||
if (response.integer(1) == 0 || url == null) {
|
||||
return const MallTabConfig.disabled();
|
||||
}
|
||||
return MallTabConfig(
|
||||
enabled: true,
|
||||
url: url,
|
||||
title: _nonEmpty(reply.string(4), '商城'),
|
||||
adId: reply.string(1),
|
||||
trackingId: reply.string(10),
|
||||
openMode: _openMode(reply.integer(15)),
|
||||
entryPromoEnabled: reply.integer(16) != 0,
|
||||
entryBadgeText: reply.string(17).trim(),
|
||||
entryTipTitle: reply.string(18).trim(),
|
||||
entryTipBody: reply.string(19).trim(),
|
||||
);
|
||||
}
|
||||
|
||||
class _ProtoMessage {
|
||||
_ProtoMessage(this._bytes);
|
||||
final List<int> _bytes;
|
||||
|
||||
Reference in new issue
Block a user