diff --git a/lib/api/model/model.dart b/lib/api/model/model.dart index 460adcfe1c6..8f8aab817cb 100644 --- a/lib/api/model/model.dart +++ b/lib/api/model/model.dart @@ -332,7 +332,7 @@ class Subscription extends ZulipStream { /// As an int that dart:ui's Color constructor will take: /// @JsonKey(readValue: _readColor) - final int color; // TODO(#135) Clear out _swatch cache on changes to this + int color; // TODO(#135) Clear out _swatch cache on changes to this static Object? _readColor(Map json, String key) { final str = (json[key] as String); assert(RegExp(r'^#[0-9a-f]{6}$').hasMatch(str)); @@ -347,6 +347,10 @@ class Subscription extends ZulipStream { // material [ColorScheme] class or something. But it works for now. StreamColorSwatch colorSwatch() => _swatch ??= StreamColorSwatch(color); + void clearSwatch() { + _swatch = null; + } + @visibleForTesting @JsonKey(includeToJson: false) StreamColorSwatch? get debugCachedSwatchValue => _swatch; diff --git a/lib/model/store.dart b/lib/model/store.dart index fc8d1648085..09fca58407f 100644 --- a/lib/model/store.dart +++ b/lib/model/store.dart @@ -323,7 +323,8 @@ class PerAccountStore extends ChangeNotifier { if (subscription == null) return; // TODO(log) switch (event.property) { case SubscriptionProperty.color: - subscription.color = event.value as String; + subscription.color = event.value as int; + subscription.clearSwatch(); case SubscriptionProperty.isMuted: subscription.isMuted = event.value as bool; case SubscriptionProperty.inHomeView: diff --git a/test/api/model/model_test.dart b/test/api/model/model_test.dart index 562df0e13fe..a1a574e0ee7 100644 --- a/test/api/model/model_test.dart +++ b/test/api/model/model_test.dart @@ -107,7 +107,7 @@ void main() { test('converts color to int', () { Subscription subWithColor(String color) { return Subscription.fromJson( - deepToJson(eg.subscription(stream: eg.stream())) as Map + deepToJson(eg.subscription(eg.stream())) as Map ..['color'] = color, ); } @@ -117,7 +117,7 @@ void main() { }); test('colorSwatch caching', () { - final sub = eg.subscription(stream: eg.stream(), color: 0xffffffff); + final sub = eg.subscription(eg.stream(), color: 0xffffffff); check(sub.debugCachedSwatchValue).isNull(); sub.colorSwatch(); check(sub.debugCachedSwatchValue).isNotNull().base.equals(const Color(0xffffffff)); diff --git a/test/model/store_test.dart b/test/model/store_test.dart index f1f53714a8f..1cbce445e20 100644 --- a/test/model/store_test.dart +++ b/test/model/store_test.dart @@ -186,15 +186,15 @@ void main() { test('SubscriptionProperty.color updates with a string value', () { final store = eg.store(initialSnapshot: eg.initialSnapshot( streams: [stream], - subscriptions: [eg.subscription(stream, color: "#FF0000")], + subscriptions: [eg.subscription(stream, color: 0xffff0000)], )); - check(store.subscriptions[stream.streamId]!.color).equals('#FF0000'); + check(store.subscriptions[stream.streamId]!.color).equals(0xffff0000); store.handleEvent(SubscriptionUpdateEvent(id: 1, streamId: stream.streamId, property: SubscriptionProperty.color, - value: "#FF00FF")); - check(store.subscriptions[stream.streamId]!.color).equals('#FF00FF'); + value: 0xffff00ff)); + check(store.subscriptions[stream.streamId]!.color).equals(0xffff00ff); }); test('SubscriptionProperty.isMuted updates with a boolean value', () {