Skip to content

Commit 13139c4

Browse files
refactor(audience-sample): centralise status messages in SampleAppUi.Messages
AudienceSample.cs had inline status strings at every RunAndLog "Ok" return and AppendLog call (SDK stopped, anonymous ID regenerated queue cleared, queue flushed, erasure request dispatched, backend acknowledged, plus two interpolated messages for track-dropped and flushInterval-clamped warnings). Adds five plain-string constants and two format-string constants (suffixed Fmt, used with string.Format) to the existing SampleAppUi.Messages catalogue alongside the consent-flow messages already centralised there. Migrates seven inline references in AudienceSample.cs. The two interpolated status strings used em-dashes; replaced with commas in the centralised form to match the project glyph rule. NoActiveIdentity (already in Messages) had the same em-dash artefact and gets the same comma replacement. Per the user's "everything random goes in a constant" stance. Follow-up to SDK-272 (centralisation of duplicated literals).
1 parent f1b7adb commit 13139c4

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

examples/audience/Assets/SampleApp/Scripts/AudienceSample.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,30 @@ private void OnShutdown() => RunAndLog(SampleAppUi.LogLabels.Shutdown, () =>
7171
_initialised = false;
7272
ResetIdentityMirror();
7373
OnSdkStateChanged();
74-
return "SDK stopped";
74+
return SampleAppUi.Messages.SdkStopped;
7575
});
7676

7777
private void OnReset() => RunAndLog(SampleAppUi.LogLabels.Reset, () =>
7878
{
7979
ImmutableAudience.Reset();
8080
ResetIdentityMirror();
8181
OnSdkStateChanged();
82-
return "anonymous ID regenerated, queue cleared";
82+
return SampleAppUi.Messages.AnonymousIdRegeneratedQueueCleared;
8383
});
8484

8585
private async Task OnFlushAsync()
8686
{
87-
try { await ImmutableAudience.FlushAsync(); AppendLog(SampleAppUi.LogLabels.Flush, "queue flushed", LogLevel.Ok, LogSource.App); OnSdkStateChanged(); }
87+
try { await ImmutableAudience.FlushAsync(); AppendLog(SampleAppUi.LogLabels.Flush, SampleAppUi.Messages.QueueFlushed, LogLevel.Ok, LogSource.App); OnSdkStateChanged(); }
8888
catch (Exception ex) { AppendLog(SampleAppUi.LogLabels.Flush, ex.Message, LogLevel.Err, LogSource.App); }
8989
}
9090

9191
private async Task OnDeleteDataAsync()
9292
{
93-
AppendLog(SampleAppUi.LogLabels.DeleteData, "erasure request dispatched", LogLevel.Info, LogSource.App);
93+
AppendLog(SampleAppUi.LogLabels.DeleteData, SampleAppUi.Messages.ErasureRequestDispatched, LogLevel.Info, LogSource.App);
9494
try
9595
{
9696
await ImmutableAudience.DeleteData();
97-
AppendLog(SampleAppUi.LogLabels.DeleteData, "backend acknowledged", LogLevel.Ok, LogSource.App);
97+
AppendLog(SampleAppUi.LogLabels.DeleteData, SampleAppUi.Messages.BackendAcknowledged, LogLevel.Ok, LogSource.App);
9898
}
9999
catch (Exception ex)
100100
{
@@ -288,7 +288,7 @@ private static void GuardConsentForTrack()
288288
var consent = ImmutableAudience.CurrentConsent;
289289
if (!consent.CanTrack())
290290
throw new InvalidOperationException(
291-
$"track dropped — consent is {consent.ToLowercaseString()}; raise to anonymous or full to queue events");
291+
string.Format(SampleAppUi.Messages.TrackDroppedConsentFmt, consent.ToLowercaseString()));
292292
}
293293

294294
// Refresh* are idempotent reads, so calling all four every time is
@@ -320,7 +320,7 @@ private AudienceConfig BuildAudienceConfig(InitForm form, Action<AudienceError>
320320
if (form.FlushIntervalMs is int flushMs && flushMs > 0)
321321
{
322322
if (flushMs < 1000)
323-
AppendLog(SampleAppUi.LogLabels.Init, $"flushInterval {flushMs}ms below 1s — clamped", LogLevel.Warn, LogSource.App);
323+
AppendLog(SampleAppUi.LogLabels.Init, string.Format(SampleAppUi.Messages.FlushIntervalBelowOneSecondClampedFmt, flushMs), LogLevel.Warn, LogSource.App);
324324
config.FlushIntervalSeconds = Math.Max(1, flushMs / 1000);
325325
}
326326
if (form.FlushSize is int flushSize && flushSize > 0)

examples/audience/Assets/SampleApp/Scripts/SampleAppUi.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,22 @@ internal static class Messages
182182
internal const string QueueStartedSessionCreated = "queue started, session created";
183183
internal const string QueuePurgedAnonymousIdCleared = "queue purged, anonymous ID cleared";
184184
internal const string UserIdCleared = "userId cleared";
185-
internal const string NoActiveIdentity = "no active identity call Identify first";
185+
internal const string NoActiveIdentity = "no active identity, call Identify first";
186186
internal const string TraitsRequired = "traits required";
187187
internal const string Ready = "Sample app loaded. Paste a publishable key and click Init.";
188+
189+
// Status messages emitted by AudienceSample's RunAndLog handlers.
190+
internal const string SdkStopped = "SDK stopped";
191+
internal const string AnonymousIdRegeneratedQueueCleared = "anonymous ID regenerated, queue cleared";
192+
internal const string QueueFlushed = "queue flushed";
193+
internal const string ErasureRequestDispatched = "erasure request dispatched";
194+
internal const string BackendAcknowledged = "backend acknowledged";
195+
196+
// Formatted variants for use with string.Format or interpolation.
197+
internal const string TrackDroppedConsentFmt =
198+
"track dropped, consent is {0}; raise to anonymous or full to queue events";
199+
internal const string FlushIntervalBelowOneSecondClampedFmt =
200+
"flushInterval {0}ms below 1s, clamped";
188201
}
189202

190203
// Mirrors AudienceSample.UI.cs PopulateTypedEventAccordions naming:

0 commit comments

Comments
 (0)