Commit b3905c4e authored by Wilko Manger's avatar Wilko Manger

Handle room upgrades

parent 8bd943e4
...@@ -101,10 +101,13 @@ class ChatBloc { ...@@ -101,10 +101,13 @@ class ChatBloc {
} }
} }
shouldIgnore = shouldIgnore || shouldIgnore |=
event is JoinEvent && event is! DisplayNameChangeEvent event is JoinEvent && event is! DisplayNameChangeEvent
&& room.creator.isIdenticalTo(event.content.subject); && room.creator.isIdenticalTo(event.content.subject);
// Don't show creation events in rooms that are replacements
shouldIgnore |= event is RoomCreationEvent && room.isReplacement;
if (ignoredEvents.contains(event.runtimeType) || shouldIgnore) { if (ignoredEvents.contains(event.runtimeType) || shouldIgnore) {
continue; continue;
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:matrix_sdk/matrix_sdk.dart'; import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/ui/main/chat/widgets/state/creation_bubble.dart'; import 'package:pattle/src/ui/main/chat/widgets/state/creation_bubble.dart';
import 'package:pattle/src/ui/main/chat/widgets/state/upgrade_bubble.dart';
import 'package:pattle/src/ui/main/models/chat_item.dart'; import 'package:pattle/src/ui/main/models/chat_item.dart';
import 'image_bubble.dart'; import 'image_bubble.dart';
...@@ -94,6 +95,13 @@ abstract class Bubble extends Item { ...@@ -94,6 +95,13 @@ abstract class Bubble extends Item {
nextItem: nextItem, nextItem: nextItem,
isMine: isMine, isMine: isMine,
); );
} else if (item.event is RoomUpgradeEvent) {
return UpgradeBubble(
item: item,
previousItem: previousItem,
nextItem: nextItem,
isMine: isMine,
);
} else { } else {
return null; return null;
} }
......
...@@ -44,23 +44,14 @@ class CreationBubble extends StateBubble { ...@@ -44,23 +44,14 @@ class CreationBubble extends StateBubble {
isMine: isMine isMine: isMine
); );
@protected @protected
@override @override
Widget buildContent(BuildContext context) { List<TextSpan> buildContentSpans(BuildContext context) =>
// Keep default body1 font size so it is a bit smaller l(context).createdThisGroup(
// since it is less important than a message TextSpan(
// size 14 text: displayNameOf(event.room.creator),
return RichText( style: defaultEmphasisTextStyle
textAlign: TextAlign.center,
text: TextSpan(
style: Theme.of(context).textTheme.body1,
children: l(context).createdThisGroup(TextSpan(
text: displayNameOf(event.room.creator),
style: TextStyle(
fontWeight: FontWeight.w600
)
))
) )
); );
}
} }
\ No newline at end of file
...@@ -46,22 +46,11 @@ class MemberBubble extends StateBubble { ...@@ -46,22 +46,11 @@ class MemberBubble extends StateBubble {
isMine: isMine isMine: isMine
); );
@protected
@override @override
Widget buildContent(BuildContext context) { @protected
// Keep default body1 font size so it is a bit smaller List<TextSpan> buildContentSpans(BuildContext context) => spanFor(
// since it is less important than a message context,
// size 14 event,
return RichText( style: defaultEmphasisTextStyle
textAlign: TextAlign.center, );
text: TextSpan(
style: Theme.of(context).textTheme.body1,
children: spanFor(context, event,
style: TextStyle(
fontWeight: FontWeight.w600
)
)
)
);
}
} }
\ No newline at end of file
...@@ -43,8 +43,26 @@ abstract class StateBubble extends Bubble { ...@@ -43,8 +43,26 @@ abstract class StateBubble extends Bubble {
isMine: isMine isMine: isMine
); );
TextStyle defaultTextStyle(BuildContext context)
=> Theme.of(context).textTheme.body1;
TextStyle get defaultEmphasisTextStyle => TextStyle(
fontWeight: FontWeight.w600
);
@protected @protected
Widget buildContent(BuildContext context); List<TextSpan> buildContentSpans(BuildContext context);
@protected
Widget buildContent(BuildContext context) {
return RichText(
textAlign: TextAlign.center,
text: TextSpan(
style: defaultTextStyle(context),
children: buildContentSpans(context)
)
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
// Copyright (C) 2019 Wilko Manger
// Copyright (C) 2019 Mathieu Velten (FLA signed)
//
// This file is part of Pattle.
//
// Pattle is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pattle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Pattle. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/material.dart';
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/ui/main/models/chat_item.dart';
import 'package:pattle/src/ui/resources/localizations.dart';
import 'package:pattle/src/ui/util/user.dart';
import 'state_bubble.dart';
class UpgradeBubble extends StateBubble {
@override
final RoomUpgradeEvent event;
UpgradeBubble({
@required ChatEvent item,
@required ChatItem previousItem,
@required ChatItem nextItem,
@required bool isMine
}) :
event = item.event,
super(
item: item,
previousItem: previousItem,
nextItem: nextItem,
isMine: isMine
);
@protected
@override
List<TextSpan> buildContentSpans(BuildContext context) =>
l(context).upgradedThisGroup(
TextSpan(
text: displayNameOf(event.sender),
style: defaultEmphasisTextStyle
)
);
}
\ No newline at end of file
...@@ -36,6 +36,11 @@ class ChatOverviewBloc { ...@@ -36,6 +36,11 @@ class ChatOverviewBloc {
// Get all rooms and push them as a single list // Get all rooms and push them as a single list
await for(Room room in _user.rooms.get()) { await for(Room room in _user.rooms.get()) {
// Don't show rooms that have been upgraded
if (room.isUpgraded) {
continue;
}
final ignoredEvents = ignoredEventsOf(room, isOverview: true); final ignoredEvents = ignoredEventsOf(room, isOverview: true);
// TODO: Add optional filter argument to up to call // TODO: Add optional filter argument to up to call
......
...@@ -86,6 +86,10 @@ class Strings { ...@@ -86,6 +86,10 @@ class Strings {
List<TextSpan> createdThisGroup(TextSpan name) List<TextSpan> createdThisGroup(TextSpan name)
=> [name, TextSpan(text: ' created this group')]; => [name, TextSpan(text: ' created this group')];
// Room upgrade event
List<TextSpan> upgradedThisGroup(TextSpan name)
=> [name, TextSpan(text: ' upgraded this group')];
// Member change events // Member change events
List<TextSpan> changedTheirNameTo(TextSpan oldName, TextSpan newName) List<TextSpan> changedTheirNameTo(TextSpan oldName, TextSpan newName)
=> [oldName, TextSpan(text: ' changed their name to '), newName]; => [oldName, TextSpan(text: ' changed their name to '), newName];
......
...@@ -213,14 +213,14 @@ packages: ...@@ -213,14 +213,14 @@ packages:
name: matrix_sdk name: matrix_sdk
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.16.3" version: "0.17.1"
matrix_sdk_sqflite: matrix_sdk_sqflite:
dependency: "direct main" dependency: "direct main"
description: description:
name: matrix_sdk_sqflite name: matrix_sdk_sqflite
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.12.0" version: "0.13.0"
meta: meta:
dependency: transitive dependency: transitive
description: description:
......
...@@ -12,8 +12,8 @@ dependencies: ...@@ -12,8 +12,8 @@ dependencies:
injector: ^1.0.6 injector: ^1.0.6
matrix_sdk: ^0.16.3 matrix_sdk: ^0.17.1
matrix_sdk_sqflite: ^0.12.0 matrix_sdk_sqflite: ^0.13.0
rxdart: ^0.21.0 rxdart: ^0.21.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment