Skip to content

Commit 32ce11a

Browse files
sirpengignprice
authored andcommitted
msglist: Add stream icon to recipient headers
Fixes: #220
1 parent 1a4f0da commit 32ce11a

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

lib/widgets/message_list.dart

+13-2
Original file line numberDiff line numberDiff line change
@@ -556,16 +556,19 @@ class StreamMessageRecipientHeader extends StatelessWidget {
556556
final subscription = store.subscriptions[message.streamId];
557557
final Color backgroundColor;
558558
final Color contrastingColor;
559+
final Color iconColor;
559560
if (subscription != null) {
560561
final swatch = subscription.colorSwatch();
561562
backgroundColor = swatch.barBackground;
562563
contrastingColor =
563564
(ThemeData.estimateBrightnessForColor(swatch.barBackground) == Brightness.dark)
564565
? Colors.white
565566
: Colors.black;
567+
iconColor = swatch.iconOnBarBackground;
566568
} else {
567569
backgroundColor = _kFallbackStreamColor;
568570
contrastingColor = Colors.black;
571+
iconColor = Colors.black;
569572
}
570573
final textStyle = TextStyle(
571574
color: contrastingColor,
@@ -589,8 +592,16 @@ class StreamMessageRecipientHeader extends StatelessWidget {
589592
child: Row(
590593
crossAxisAlignment: CrossAxisAlignment.center,
591594
children: [
592-
const SizedBox(width: 16),
593-
// TODO globe/lock icons for web-public and private streams
595+
Padding(
596+
// Figma specifies 5px horizontal spacing around an icon that's
597+
// 18x18 and includes 1px padding. The icon SVG is flush with
598+
// the edges, so make it 16x16 with 6px horizontal padding.
599+
// Bottom padding added here to shift icon up to
600+
// match alignment with text visually.
601+
padding: const EdgeInsets.only(left: 6, right: 6, bottom: 3),
602+
child: Icon(size: 16, color: iconColor,
603+
// A null [Icon.icon] makes a blank space.
604+
(stream != null) ? iconDataForStream(stream) : null)),
594605
Padding(
595606
padding: const EdgeInsets.symmetric(vertical: 11),
596607
child: Text(streamName,

test/widgets/message_list_test.dart

+49
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:zulip/model/localizations.dart';
1414
import 'package:zulip/model/narrow.dart';
1515
import 'package:zulip/model/store.dart';
1616
import 'package:zulip/widgets/content.dart';
17+
import 'package:zulip/widgets/icons.dart';
1718
import 'package:zulip/widgets/message_list.dart';
1819
import 'package:zulip/widgets/sticky_header.dart';
1920
import 'package:zulip/widgets/store.dart';
@@ -249,6 +250,54 @@ void main() {
249250
matching: find.byType(ColoredBox),
250251
))).color.equals(swatch.barBackground);
251252
});
253+
254+
testWidgets('color of stream icon', (tester) async {
255+
final stream = eg.stream(isWebPublic: true);
256+
final subscription = eg.subscription(stream, color: Colors.red.value);
257+
final swatch = subscription.colorSwatch();
258+
await setupMessageListPage(tester,
259+
messages: [eg.streamMessage(stream: subscription)],
260+
subscriptions: [subscription]);
261+
await tester.pump();
262+
check(tester.widget<Icon>(find.byIcon(ZulipIcons.globe)))
263+
.color.equals(swatch.iconOnBarBackground);
264+
});
265+
266+
testWidgets('normal streams show hash icon', (tester) async {
267+
final stream = eg.stream(isWebPublic: false, inviteOnly: false);
268+
await setupMessageListPage(tester,
269+
messages: [eg.streamMessage(stream: stream)],
270+
streams: [stream]);
271+
await tester.pump();
272+
check(find.descendant(
273+
of: find.byType(StreamMessageRecipientHeader),
274+
matching: find.byIcon(ZulipIcons.hash_sign),
275+
).evaluate()).length.equals(1);
276+
});
277+
278+
testWidgets('public streams show globe icon', (tester) async {
279+
final stream = eg.stream(isWebPublic: true);
280+
await setupMessageListPage(tester,
281+
messages: [eg.streamMessage(stream: stream)],
282+
streams: [stream]);
283+
await tester.pump();
284+
check(find.descendant(
285+
of: find.byType(StreamMessageRecipientHeader),
286+
matching: find.byIcon(ZulipIcons.globe),
287+
).evaluate()).length.equals(1);
288+
});
289+
290+
testWidgets('private streams show lock icon', (tester) async {
291+
final stream = eg.stream(inviteOnly: true);
292+
await setupMessageListPage(tester,
293+
messages: [eg.streamMessage(stream: stream)],
294+
streams: [stream]);
295+
await tester.pump();
296+
check(find.descendant(
297+
of: find.byType(StreamMessageRecipientHeader),
298+
matching: find.byIcon(ZulipIcons.lock),
299+
).evaluate()).length.equals(1);
300+
});
252301
});
253302

254303
testWidgets('show stream name from message when stream unknown', (tester) async {

0 commit comments

Comments
 (0)