Format code

parent 3daf3860
......@@ -35,55 +35,53 @@ import 'ui/main/overview/create/group/create_group_details_page.dart';
final routes = {
Routes.root: (Object params) => platformPageRoute(
settings: RouteSettings(name: Routes.root),
builder: (context) => InitialPage()
),
settings: RouteSettings(name: Routes.root),
builder: (context) => InitialPage(),
),
Routes.chats: (Object arguments) => platformPageRoute(
settings: RouteSettings(name: Routes.chats),
builder: (context) {
if (arguments is Room) {
return ChatPage(arguments);
} else {
return ChatOverviewPage();
}
}
),
settings: RouteSettings(name: Routes.chats),
builder: (context) {
if (arguments is Room) {
return ChatPage(arguments);
} else {
return ChatOverviewPage();
}
},
),
Routes.chatsSettings: (Object arguments) => platformPageRoute(
settings: RouteSettings(name: Routes.chatsSettings),
builder: (context) => ChatSettingsPage(arguments)
),
settings: RouteSettings(name: Routes.chatsSettings),
builder: (context) => ChatSettingsPage(arguments),
),
Routes.chatsNew: (Object arguments) => platformPageRoute(
settings: RouteSettings(name: Routes.chatsNew),
builder: (context) => CreateGroupMembersPage()
),
settings: RouteSettings(name: Routes.chatsNew),
builder: (context) => CreateGroupMembersPage(),
),
Routes.chatsNewDetails: (Object arguments) => platformPageRoute(
settings: RouteSettings(name: Routes.chatsNewDetails),
builder: (context) => CreateGroupDetailsPage()
),
settings: RouteSettings(name: Routes.chatsNewDetails),
builder: (context) => CreateGroupDetailsPage(),
),
Routes.image: (Object arguments) => platformPageRoute(
settings: RouteSettings(name: Routes.image),
builder: (context) => ImagePage(arguments)
),
settings: RouteSettings(name: Routes.image),
builder: (context) => ImagePage(arguments)),
Routes.start: (Object params) => platformPageRoute(
settings: RouteSettings(name: Routes.start),
builder: (context) => StartPage()
),
settings: RouteSettings(name: Routes.start),
builder: (context) => StartPage(),
),
Routes.startAdvanced: (Object params) => platformPageRoute(
settings: RouteSettings(name: Routes.startAdvanced),
builder: (context) => AdvancedPage()
),
settings: RouteSettings(name: Routes.startAdvanced),
builder: (context) => AdvancedPage(),
),
Routes.startUsername: (Object params) => platformPageRoute(
settings: RouteSettings(name: Routes.startUsername),
builder: (context) => UsernamePage()
),
settings: RouteSettings(name: Routes.startUsername),
builder: (context) => UsernamePage(),
),
Routes.startPassword: (Object params) => platformPageRoute(
settings: RouteSettings(name: Routes.startPassword),
builder: (context) => PasswordPage()
),
settings: RouteSettings(name: Routes.startPassword),
builder: (context) => PasswordPage(),
),
};
class Routes {
Routes._();
static const root = '/';
......@@ -100,7 +98,6 @@ class Routes {
static const chatsNewDetails = '/chats/new/details';
}
class App extends StatelessWidget {
// This widget is the root of your application.
@override
......@@ -123,10 +120,8 @@ class App extends StatelessWidget {
theme: lightTheme,
),
ios: (_) => CupertinoAppData(
theme: MaterialBasedCupertinoThemeData(
materialTheme: lightTheme
)
theme: MaterialBasedCupertinoThemeData(materialTheme: lightTheme),
),
);
}
}
\ No newline at end of file
}
......@@ -25,8 +25,7 @@ final inj = Injector();
Homeserver getHomeserver() => inj.getDependency<Homeserver>();
void registerHomeserver(Homeserver homeserver) {
inj.registerSingleton<Homeserver>((_)
=> homeserver, override: true);
inj.registerSingleton<Homeserver>((_) => homeserver, override: true);
}
Future<void> registerHomeserverWith(Url url) async {
......@@ -44,11 +43,9 @@ Store getStore() => inj.getDependency<Store>();
void registerStore() {
final store = SqfliteStore(path: 'pattle.sqlite');
inj.registerSingleton<Store>((_)
=> store, override: true);
inj.registerSingleton<Store>((_) => store, override: true);
}
LocalUser getLocalUser() => inj.getDependency<LocalUser>();
void registerLocalUser(LocalUser user) {
......@@ -57,13 +54,16 @@ void registerLocalUser(LocalUser user) {
}
const use24HourDependencyName = 'use24HourFormat';
bool getUse24HourFormat() => inj.getDependency<bool>(
dependencyName: use24HourDependencyName
) ?? false;
bool getUse24HourFormat() =>
inj.getDependency<bool>(
dependencyName: use24HourDependencyName,
) ??
false;
void registerUse24HourFormat(bool use24HourFormat) {
inj.registerSingleton((_) => use24HourFormat,
inj.registerSingleton(
(_) => use24HourFormat,
override: true,
dependencyName: use24HourDependencyName
dependencyName: use24HourDependencyName,
);
}
\ No newline at end of file
}
......@@ -32,7 +32,6 @@ SentryClient _sentry;
Future<void> _reportError(dynamic error, dynamic stackTrace) async {
print('Caught error: $error');
if (_isInDebugMode) {
if (error is Response) {
print('statusCode: ${error.statusCode}');
print('headers: ${error.headers}');
......@@ -44,7 +43,6 @@ Future<void> _reportError(dynamic error, dynamic stackTrace) async {
if (stackTrace != null) {
print(stackTrace);
}
} else {
if (error is Response) {
var body;
......@@ -61,9 +59,9 @@ Future<void> _reportError(dynamic error, dynamic stackTrace) async {
extra: {
'status_code': error.statusCode,
'headers': error.headers,
'body': body
}
)
'body': body,
},
),
);
} else if (error is matrix.MatrixException) {
_sentry.capture(
......@@ -72,8 +70,8 @@ Future<void> _reportError(dynamic error, dynamic stackTrace) async {
stackTrace: stackTrace,
extra: {
'body': error.body,
}
)
},
),
);
} else {
_sentry.captureException(
......@@ -103,9 +101,7 @@ Future<Event> get _environment async {
if (Platform.isAndroid) {
final info = await deviceInfo.androidInfo;
user = User(
id: info.androidId
);
user = User(id: info.androidId);
os = Os(
name: 'Android',
......@@ -117,15 +113,12 @@ Future<Event> get _environment async {
model: info.model,
manufacturer: info.manufacturer,
brand: info.brand,
simulator: !info.isPhysicalDevice
simulator: !info.isPhysicalDevice,
);
} else if (Platform.isIOS){
} else if (Platform.isIOS) {
final info = await deviceInfo.iosInfo;
user = User(
id: info.identifierForVendor
);
user = User(id: info.identifierForVendor);
os = Os(
name: 'iOS',
......@@ -135,7 +128,7 @@ Future<Event> get _environment async {
device = Device(
family: info.model,
model: info.utsname.machine,
simulator: !info.isPhysicalDevice
simulator: !info.isPhysicalDevice,
);
}
......@@ -151,8 +144,8 @@ Future<Event> get _environment async {
app: App(
build: packageInfo.buildNumber,
buildType: DotEnv().env['BUILD_TYPE'],
)
)
),
),
);
}
......@@ -161,7 +154,7 @@ Future<void> init() async {
_sentry = SentryClient(
dsn: DotEnv().env['SENTRY_DSN'],
environmentAttributes: await _environment
environmentAttributes: await _environment,
);
FlutterError.onError = (FlutterErrorDetails details) {
......@@ -175,9 +168,12 @@ Future<void> init() async {
}
void wrap(Function run) {
runZoned<Future<void>>(() async {
run();
}, onError: (error, stackTrace) {
_reportError(error, stackTrace);
});
}
\ No newline at end of file
runZoned<Future<void>>(
() async {
run();
},
onError: (error, stackTrace) {
_reportError(error, stackTrace);
},
);
}
......@@ -24,10 +24,8 @@ import 'package:respect_24_hour/respect_24_hour.dart';
final bloc = InitialBloc();
class InitialBloc {
final _loggedInSubj = BehaviorSubject<bool>();
Observable<bool> get loggedIn
=> _loggedInSubj.stream;
Observable<bool> get loggedIn => _loggedInSubj.stream;
// General app initialization
void init() async {
......@@ -45,4 +43,4 @@ class InitialBloc {
_loggedInSubj.add(localUser != null);
}
}
\ No newline at end of file
}
......@@ -21,7 +21,6 @@ import 'package:pattle/src/app.dart';
import 'package:pattle/src/ui/initial/initial_bloc.dart';
class InitialPageState extends State<InitialPage> {
StreamSubscription<bool> subscription;
@override
......@@ -59,7 +58,6 @@ class InitialPageState extends State<InitialPage> {
}
class InitialPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => InitialPageState();
}
\ No newline at end of file
}
......@@ -25,7 +25,6 @@ import 'package:rxdart/rxdart.dart';
import 'package:pattle/src/di.dart' as di;
class ChatBloc {
final Room room;
StreamSubscription syncSub;
......@@ -61,7 +60,7 @@ class ChatBloc {
// Remember: 'previous' is actually next in time
RoomEvent previousEvent;
RoomEvent event;
for(event in events) {
for (event in events) {
var shouldIgnore = false;
// In direct chats, don't show the invite event between this user
// and the direct user.
......@@ -70,23 +69,22 @@ class ChatBloc {
// and the direct user.
if (room.isDirect) {
if (event is InviteEvent) {
final iInvitedYou = event.sender == me
&& event.content.subject == room.directUser;
final iInvitedYou =
event.sender == me && event.content.subject == room.directUser;
final youInvitedMe = event.sender == room.directUser
&& event.content.subject == me;
final youInvitedMe =
event.sender == room.directUser && event.content.subject == me;
shouldIgnore = iInvitedYou || youInvitedMe;
} else if (event is JoinEvent) {
final subject = event.content.subject;
shouldIgnore = subject == me
|| subject == room.directUser;
shouldIgnore = subject == me || subject == room.directUser;
}
}
shouldIgnore |=
event is JoinEvent && event is! DisplayNameChangeEvent
&& room.creator == event.content.subject;
shouldIgnore |= event is JoinEvent &&
event is! DisplayNameChangeEvent &&
room.creator == event.content.subject;
// Don't show creation events in rooms that are replacements
shouldIgnore |= event is RoomCreationEvent && room.isReplacement;
......@@ -96,8 +94,9 @@ class ChatBloc {
}
// Insert DateHeader if there's a day difference
if (previousEvent != null && event != null
&& previousEvent.time.day != event.time.day) {
if (previousEvent != null &&
event != null &&
previousEvent.time.day != event.time.day) {
chatItems.add(DateItem(previousEvent.time));
}
......@@ -138,7 +137,6 @@ class ChatBloc {
}
}
bool _notifying = false;
bool _typing = false;
final _stopwatch = Stopwatch();
......@@ -179,8 +177,7 @@ class ChatBloc {
});
}
void cleanUp() {
syncSub.cancel();
}
}
\ No newline at end of file
}
This diff is collapsed.
......@@ -14,14 +14,13 @@
//
// 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:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/ui/main/models/chat_item.dart';
import 'package:pattle/src/ui/main/sync_bloc.dart';
import 'package:pattle/src/ui/util/room.dart';
import 'package:rxdart/rxdart.dart';
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/ui/main/models/chat_item.dart';
import 'package:pattle/src/ui/main/sync_bloc.dart';
import 'package:pattle/src/ui/util/room.dart';
import 'package:rxdart/rxdart.dart';
class ImageBloc {
Room room;
ImageMessageEvent event;
......@@ -46,8 +45,8 @@ class ImageBloc {
}
}
PublishSubject<List<ImageMessageEvent>> _eventSubj
= PublishSubject<List<ImageMessageEvent>>();
PublishSubject<List<ImageMessageEvent>> _eventSubj =
PublishSubject<List<ImageMessageEvent>>();
Stream<List<ImageMessageEvent>> get events => _eventSubj.stream;
Future<void> startLoadingEvents() async {
......
......@@ -29,7 +29,6 @@ import 'package:photo_view/photo_view_gallery.dart';
import 'package:pattle/src/di.dart' as di;
class ImagePageState extends State<ImagePage> {
final me = di.getLocalUser();
ImageBloc bloc;
final ImageMessageEvent message;
......@@ -52,7 +51,7 @@ class ImagePageState extends State<ImagePage> {
@override
void didChangeDependencies() {
_date =
'${formatAsDate(context, message.time)}, ${formatAsTime(message.time)}';
'${formatAsDate(context, message.time)}, ${formatAsTime(message.time)}';
}
@override
......@@ -75,25 +74,29 @@ class ImagePageState extends State<ImagePage> {
SizedBox(height: 2),
Text(
_date,
style: Theme.of(context).textTheme.body1.copyWith(
color: Colors.white,
)
style: Theme.of(context)
.textTheme
.body1
.copyWith(color: Colors.white),
),
],
),
backgroundColor: Color(0x64000000),
),
)
]
)
],
),
);
}
Widget _buildPhotoViewList() {
return StreamBuilder<List<ImageMessageEvent>>(
stream: bloc.events,
builder: (BuildContext context, AsyncSnapshot<List<ImageMessageEvent>> snapshot) {
switch(snapshot.connectionState) {
builder: (
BuildContext context,
AsyncSnapshot<List<ImageMessageEvent>> snapshot,
) {
switch (snapshot.connectionState) {
case ConnectionState.none:
case ConnectionState.waiting:
return Center(child: CircularProgressIndicator());
......@@ -107,27 +110,27 @@ class ImagePageState extends State<ImagePage> {
return PhotoViewGalleryPageOptions(
imageProvider: MatrixImage(events[index].content.url),
heroTag: message.id,
minScale: PhotoViewComputedScale.contained
minScale: PhotoViewComputedScale.contained,
);
},
onPageChanged: (index) {
setState(() {
_messageSender = events[index].sender;
_date =
'${formatAsDate(context, events[index].time)}, ${formatAsTime(events[index].time)}';
_date = '${formatAsDate(context, events[index].time)}, '
'${formatAsTime(events[index].time)}';
});
},
pageController:
PageController(initialPage: events.indexOf(message))
pageController: PageController(
initialPage: events.indexOf(message),
),
);
}
}
},
);
}
}
class ImagePage extends StatefulWidget {
final ImageMessageEvent message;
ImagePage(this.message);
......
......@@ -25,14 +25,11 @@ import 'package:rxdart/rxdart.dart';
import 'package:pattle/src/di.dart' as di;
class ChatSettingsBloc {
final Room room;
ChatSettingsBloc(this.room);
FutureOr<List<User>> getMembers({bool all = false}) {
FutureOr<List<User>> filter(Iterable<User> members) {
final list = members.toList();
......@@ -51,7 +48,8 @@ class ChatSettingsBloc {
}
}
final futureOrMembers = room.members.get(upTo: !all ? 6 : room.members.count);
final futureOrMembers =
room.members.get(upTo: !all ? 6 : room.members.count);
if (futureOrMembers is Future<Iterable<User>>) {
return futureOrMembers.then(filter);
......@@ -59,4 +57,4 @@ class ChatSettingsBloc {
return filter(futureOrMembers);
}
}
}
\ No newline at end of file
}
......@@ -32,9 +32,7 @@ import 'package:pattle/src/ui/util/matrix_image.dart';
import 'package:pattle/src/ui/util/room.dart';
import 'package:pattle/src/ui/util/user.dart';
class ChatSettingsPageState extends State<ChatSettingsPage> {
final me = di.getLocalUser();
final ChatSettingsBloc bloc;
final Room room;
......@@ -66,16 +64,22 @@ class ChatSettingsPageState extends State<ChatSettingsPage> {
floating: false,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
title: ChatName(room: room, style: TextStyle(
shadows: [Shadow(
offset: Offset(0.25, 0.25),
blurRadius: 1,
)],
),),
title: ChatName(
room: room,
style: TextStyle(
shadows: [
Shadow(
offset: Offset(0.25, 0.25),
blurRadius: 1,
)
],
),
),
background: Image(
image: MatrixImage(avatarUrlOf(room)),
fit: BoxFit.cover,
)),
),
),
),
];
},
......@@ -85,11 +89,11 @@ class ChatSettingsPageState extends State<ChatSettingsPage> {
delegate: SliverChildListDelegate.fixed([
_buildDescription(),
SizedBox(height: 16),
_buildMembers()
_buildMembers(),
]),
)
],
)
),
),
);
}
......@@ -118,10 +122,12 @@ class ChatSettingsPageState extends State<ChatSettingsPage> {
),
),
SizedBox(height: 4),
Text(room.topic ?? l(context).noDescriptionSet,
Text(
room.topic ?? l(context).noDescriptionSet,
style: TextStyle(
fontStyle: room.topic == null
? FontStyle.italic : FontStyle.normal
? FontStyle.italic
: FontStyle.normal,
),
),
],
......@@ -161,18 +167,18 @@ class ChatSettingsPageState extends State<ChatSettingsPage> {
FutureOrBuilder<Iterable<User>>(
futureOr: bloc.getMembers(all: !previewMembers),
builder: (
BuildContext context,
AsyncSnapshot<Iterable<User>> snapshot,
) {
BuildContext context,
AsyncSnapshot<Iterable<User>> snapshot,
) {
if (!snapshot.hasData) {
return Container(height: 0);
}
final members = snapshot.data.toList(growable: false);
final isWaiting = snapshot.connectionState == ConnectionState.waiting;
bool allShown = members.length == bloc.room.members.count;
final isWaiting =
snapshot.connectionState == ConnectionState.waiting;
final allShown = members.length == bloc.room.members.count;
return MediaQuery.removePadding(
context: context,
......@@ -188,7 +194,11 @@ class ChatSettingsPageState extends State<ChatSettingsPage> {
itemBuilder: (BuildContext context, int index) {
// Item after all members
if (index == members.length) {
return _buildShowMoreItem(context, members.length, isWaiting);
return _buildShowMoreItem(
context,
members.length,
isWaiting,
);
}
return UserItem(
......@@ -197,7 +207,7 @@ class ChatSettingsPageState extends State<ChatSettingsPage> {
},
),
);
}
},
),
],
),
......@@ -217,15 +227,13 @@ class ChatSettingsPageState extends State<ChatSettingsPage> {
}),
);
}
}
class ChatSettingsPage extends StatefulWidget {
final Room room;
ChatSettingsPage(this.room);
@override
State<StatefulWidget> createState() => ChatSettingsPageState(room);
}
\ No newline at end of file
}
......@@ -20,29 +20,30 @@ import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/ui/resources/localizations.dart';
import 'package:pattle/src/ui/util/user.dart';
List<TextSpan> spanFor(BuildContext context, MemberChangeEvent event,
{TextStyle style = const TextStyle(
fontWeight: FontWeight.bold
)}) {
List<TextSpan> spanFor(
BuildContext context,
MemberChangeEvent event, {
TextStyle style = const TextStyle(fontWeight: FontWeight.bold),
}) {
final sender = TextSpan(
text: displayNameOf(event.sender),
style: style
style: style,
);
final subject = TextSpan(
text: displayNameOf(event.content.subject),
style: style
style: style,
);
var text;
if (event is DisplayNameChangeEvent) {
final oldName = TextSpan(
text: displayNameOrId(event.content.subject.id, event.oldSubjectName),
style: style
style: style,
);
final newName = TextSpan(
text: displayNameOf(event.content.subject),
style: style
style: style,
);
text = l(context).changedTheirNameTo(oldName, newName);
......@@ -57,4 +58,4 @@ List<TextSpan> spanFor(BuildContext context, MemberChangeEvent event,
}
return text;
}
\ No newline at end of file
}