Skip to content

Commit

Permalink
hack: adhoc fixes to upstream inbox changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpengi committed Nov 17, 2023
1 parent dcefb85 commit a69b811
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 5 additions & 1 deletion lib/api/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class Subscription extends ZulipStream {
/// As an int that dart:ui's Color constructor will take:
/// <https://api.flutter.dev/flutter/dart-ui/Color/Color.html>
@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));
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions test/api/model/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic>
deepToJson(eg.subscription(eg.stream())) as Map<String, dynamic>
..['color'] = color,
);
}
Expand All @@ -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));
Expand Down
8 changes: 4 additions & 4 deletions test/model/store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down

0 comments on commit a69b811

Please sign in to comment.