feat: Implement new status feature

This commit is contained in:
Christian Pauly 2020-10-03 15:53:08 +02:00
parent d9c2d4f754
commit 090795fa77
10 changed files with 329 additions and 245 deletions

View file

@ -11,7 +11,7 @@ class ConnectionStatusHeader extends StatefulWidget {
class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> { class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
StreamSubscription _onSyncSub; StreamSubscription _onSyncSub;
StreamSubscription _onSyncErrorSub; StreamSubscription _onSyncErrorSub;
static bool _connected = false; static bool _connected = true;
set connected(bool connected) { set connected(bool connected) {
if (mounted) { if (mounted) {

View file

@ -1,63 +0,0 @@
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/utils/presence_extension.dart';
import 'package:fluffychat/views/chat.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import '../avatar.dart';
import '../matrix.dart';
class PresenceDialog extends StatelessWidget {
final Uri avatarUrl;
final String displayname;
final Presence presence;
const PresenceDialog(
this.presence, {
this.avatarUrl,
this.displayname,
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return AlertDialog(
title: ListTile(
contentPadding: EdgeInsets.zero,
leading: Avatar(avatarUrl, displayname),
title: Text(displayname),
subtitle: Text(presence.senderId),
),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(presence.getLocalizedStatusMessage(context)),
],
),
actions: <Widget>[
if (presence.senderId != Matrix.of(context).client.userID)
FlatButton(
child: Text(L10n.of(context).sendAMessage),
onPressed: () async {
final roomId = await User(
presence.senderId,
room: Room(id: '', client: Matrix.of(context).client),
).startDirectChat();
await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(
context,
ChatView(roomId),
),
(Route r) => r.isFirst);
},
),
FlatButton(
child: Text(L10n.of(context).close),
onPressed: () => Navigator.of(context).pop(),
),
],
);
}
}

View file

@ -1,109 +0,0 @@
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat.dart';
import 'package:fluffychat/views/presence_view.dart';
import 'package:flutter/material.dart';
import '../avatar.dart';
import '../matrix.dart';
class PresenceListItem extends StatelessWidget {
final Room room;
const PresenceListItem(this.room);
void _startChatAction(BuildContext context, String userId) async {
final roomId = await User(userId,
room: Room(client: Matrix.of(context).client, id: ''))
.startDirectChat();
await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(
context,
ChatView(roomId),
),
(Route r) => r.isFirst);
}
@override
Widget build(BuildContext context) {
final user = room.getUserByMXIDSync(room.directChatMatrixID);
final presence =
Matrix.of(context).client.presences[room.directChatMatrixID];
final hasStatus = presence?.presence?.statusMsg != null;
return InkWell(
borderRadius: BorderRadius.circular(8),
onTap: () => presence?.presence?.statusMsg == null
? _startChatAction(context, user.id)
: /*showDialog(
context: context,
builder: (_) => PresenceDialog(
presence,
avatarUrl: user.avatarUrl,
displayname: user.calcDisplayname(),
),
),*/
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => PresenceView(
presence: presence,
avatarUrl: user.avatarUrl,
displayname: user.calcDisplayname(),
),
),
),
child: Container(
width: 76,
child: Column(
children: <Widget>[
SizedBox(height: 10),
Container(
child: Stack(
children: [
Avatar(user.avatarUrl, user.calcDisplayname()),
if (presence?.presence?.currentlyActive == true)
Positioned(
bottom: 0,
right: 0,
child: Container(
width: 10,
height: 10,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.green,
),
),
),
],
),
decoration: BoxDecoration(
border: Border.all(
width: 1,
color: !hasStatus
? Theme.of(context).secondaryHeaderColor
: Theme.of(context).primaryColor,
),
borderRadius: BorderRadius.circular(80),
),
padding: EdgeInsets.all(2),
),
Padding(
padding: const EdgeInsets.only(left: 6.0, top: 0.0, right: 6.0),
child: Text(
user.calcDisplayname().trim().split(' ').first,
overflow: TextOverflow.clip,
maxLines: 1,
style: TextStyle(
color: Theme.of(context)
.textTheme
.bodyText2
.color
.withOpacity(hasStatus ? 1 : 0.66),
fontSize: 13,
),
),
),
],
),
),
);
}
}

View file

@ -0,0 +1,83 @@
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/user_status.dart';
import 'package:fluffychat/views/status_view.dart';
import 'package:flutter/material.dart';
import '../avatar.dart';
import '../matrix.dart';
class StatusListItem extends StatelessWidget {
final UserStatus status;
const StatusListItem(this.status, {Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
final client = Matrix.of(context).client;
return FutureBuilder<Profile>(
future: client.getProfileFromUserId(status.userId),
builder: (context, snapshot) {
final profile =
snapshot.data ?? Profile(client.userID, Uri.parse(''));
return InkWell(
borderRadius: BorderRadius.circular(8),
onTap: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => StatusView(
status: status,
avatarUrl: profile.avatarUrl,
displayname: profile.displayname,
),
),
),
child: Container(
width: 76,
child: Column(
children: <Widget>[
SizedBox(height: 10),
Container(
child: Stack(
children: [
Avatar(profile.avatarUrl, profile.displayname),
Positioned(
bottom: 0,
right: 0,
child: Container(
width: 10,
height: 10,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.green,
),
),
),
],
),
decoration: BoxDecoration(
border: Border.all(
width: 1,
color: Theme.of(context).primaryColor,
),
borderRadius: BorderRadius.circular(80),
),
padding: EdgeInsets.all(2),
),
Padding(
padding:
const EdgeInsets.only(left: 6.0, top: 0.0, right: 6.0),
child: Text(
profile.displayname.trim().split(' ').first,
overflow: TextOverflow.clip,
maxLines: 1,
style: TextStyle(
color: Theme.of(context).textTheme.bodyText2.color,
fontSize: 13,
),
),
),
],
),
),
);
});
}
}

View file

@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:famedlysdk/encryption.dart'; import 'package:famedlysdk/encryption.dart';
@ -7,6 +8,7 @@ import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
import 'package:fluffychat/utils/firebase_controller.dart'; import 'package:fluffychat/utils/firebase_controller.dart';
import 'package:fluffychat/utils/matrix_locals.dart'; import 'package:fluffychat/utils/matrix_locals.dart';
import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/user_status.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -17,6 +19,7 @@ import 'package:url_launcher/url_launcher.dart';
import '../utils/app_route.dart'; import '../utils/app_route.dart';
import '../utils/beautify_string_extension.dart'; import '../utils/beautify_string_extension.dart';
import '../utils/famedlysdk_store.dart'; import '../utils/famedlysdk_store.dart';
import '../utils/presence_extension.dart';
import '../views/key_verification.dart'; import '../views/key_verification.dart';
import 'avatar.dart'; import 'avatar.dart';
@ -106,6 +109,7 @@ class MatrixState extends State<Matrix> {
StreamSubscription onNotification; StreamSubscription onNotification;
StreamSubscription<html.Event> onFocusSub; StreamSubscription<html.Event> onFocusSub;
StreamSubscription<html.Event> onBlurSub; StreamSubscription<html.Event> onBlurSub;
StreamSubscription onPresenceSub;
void onJitsiCall(EventUpdate eventUpdate) { void onJitsiCall(EventUpdate eventUpdate) {
final event = Event.fromJson( final event = Event.fromJson(
@ -191,6 +195,16 @@ class MatrixState extends State<Matrix> {
@override @override
void initState() { void initState() {
store = widget.store ?? Store(); store = widget.store ?? Store();
store.getItem('fluffychat.user_statuses').then(
(json) {
userStatuses = json == null
? []
: (jsonDecode(json)['user_statuses'] as List)
.map((j) => UserStatus.fromJson(j))
.toList();
_cleanUpUserStatus();
},
);
if (widget.client == null) { if (widget.client == null) {
debugPrint('[Matrix] Init matrix client'); debugPrint('[Matrix] Init matrix client');
final Set verificationMethods = <KeyVerificationMethod>{ final Set verificationMethods = <KeyVerificationMethod>{
@ -206,6 +220,9 @@ class MatrixState extends State<Matrix> {
importantStateEvents: <String>{ importantStateEvents: <String>{
'im.ponies.room_emotes', // we want emotes to work properly 'im.ponies.room_emotes', // we want emotes to work properly
}); });
onPresenceSub ??= client.onPresence.stream
.where((p) => p.isUserStatus)
.listen(_storeUserStatus);
onJitsiCallSub ??= client.onEvent.stream onJitsiCallSub ??= client.onEvent.stream
.where((e) => .where((e) =>
e.type == 'timeline' && e.type == 'timeline' &&
@ -213,6 +230,7 @@ class MatrixState extends State<Matrix> {
e.content['content']['msgtype'] == Matrix.callNamespace && e.content['content']['msgtype'] == Matrix.callNamespace &&
e.content['sender'] != client.userID) e.content['sender'] != client.userID)
.listen(onJitsiCall); .listen(onJitsiCall);
onRoomKeyRequestSub ??= onRoomKeyRequestSub ??=
client.onRoomKeyRequest.stream.listen((RoomKeyRequest request) async { client.onRoomKeyRequest.stream.listen((RoomKeyRequest request) async {
final room = request.room; final room = request.room;
@ -285,11 +303,54 @@ class MatrixState extends State<Matrix> {
super.initState(); super.initState();
} }
List<UserStatus> userStatuses = [];
void _storeUserStatus(Presence presence) {
final currentStatusIndex =
userStatuses.indexWhere((u) => u.userId == presence.senderId);
final newUserStatus = UserStatus()
..receivedAt = DateTime.now().millisecondsSinceEpoch
..statusMsg = presence.presence.statusMsg
..userId = presence.senderId;
if (currentStatusIndex == -1) {
userStatuses.add(newUserStatus);
} else if (userStatuses[currentStatusIndex].statusMsg !=
presence.presence.statusMsg) {
if (presence.presence.statusMsg.trim().isEmpty) {
userStatuses.removeAt(currentStatusIndex);
} else {
userStatuses[currentStatusIndex] = newUserStatus;
}
} else {
return;
}
_cleanUpUserStatus();
}
void _cleanUpUserStatus() {
final now = DateTime.now().millisecondsSinceEpoch;
userStatuses
.removeWhere((u) => (now - u.receivedAt) > (1000 * 60 * 60 * 24));
userStatuses.sort((a, b) => b.receivedAt.compareTo(a.receivedAt));
if (userStatuses.length > 40) {
userStatuses.removeRange(40, userStatuses.length);
}
store.setItem(
'fluffychat.user_statuses',
jsonEncode(
{
'user_statuses': userStatuses.map((i) => i.toJson()).toList(),
},
),
);
}
@override @override
void dispose() { void dispose() {
onRoomKeyRequestSub?.cancel(); onRoomKeyRequestSub?.cancel();
onKeyVerificationRequestSub?.cancel(); onKeyVerificationRequestSub?.cancel();
onJitsiCallSub?.cancel(); onJitsiCallSub?.cancel();
onPresenceSub?.cancel();
onNotification?.cancel(); onNotification?.cancel();
onFocusSub?.cancel(); onFocusSub?.cancel();
onBlurSub?.cancel(); onBlurSub?.cancel();

View file

@ -1,10 +1,7 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
extension ClientPresenceExtension on Client { extension ClientPresenceExtension on Client {
static final Map<String, Profile> presencesCache = {}; List<Presence> get statuses => presences.values
.where((p) => p.presence.statusMsg?.isNotEmpty ?? false)
Future<Profile> requestProfileCached(String senderId) async { .toList();
presencesCache[senderId] ??= await getProfileFromUserId(senderId);
return presencesCache[senderId];
}
} }

View file

@ -5,6 +5,8 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'date_time_extension.dart'; import 'date_time_extension.dart';
extension PresenceExtension on Presence { extension PresenceExtension on Presence {
bool get isUserStatus => presence?.statusMsg?.isNotEmpty ?? false;
String getLocalizedStatusMessage(BuildContext context) { String getLocalizedStatusMessage(BuildContext context) {
if (presence.statusMsg?.isNotEmpty ?? false) { if (presence.statusMsg?.isNotEmpty ?? false) {
return presence.statusMsg; return presence.statusMsg;

View file

@ -0,0 +1,21 @@
class UserStatus {
String statusMsg;
String userId;
int receivedAt;
UserStatus();
UserStatus.fromJson(Map<String, dynamic> json) {
statusMsg = json['status_msg'];
userId = json['user_id'];
receivedAt = json['received_at'];
}
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
data['status_msg'] = statusMsg;
data['user_id'] = userId;
data['received_at'] = receivedAt;
return data;
}
}

View file

@ -3,12 +3,13 @@ import 'dart:io';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:famedlysdk/matrix_api.dart'; import 'package:famedlysdk/matrix_api.dart';
import 'package:fluffychat/components/avatar.dart';
import 'package:fluffychat/components/connection_status_header.dart'; import 'package:fluffychat/components/connection_status_header.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
import 'package:fluffychat/components/list_items/presence_list_item.dart'; import 'package:fluffychat/components/list_items/status_list_item.dart';
import 'package:fluffychat/components/list_items/public_room_list_item.dart'; import 'package:fluffychat/components/list_items/public_room_list_item.dart';
import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/views/presence_view.dart'; import 'package:fluffychat/views/status_view.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -197,17 +198,25 @@ class _ChatListState extends State<ChatList> {
); );
} }
void _setStatus(BuildContext context) async { void _setStatus(BuildContext context, {bool fromDrawer = false}) async {
Navigator.of(context).pop(); if (fromDrawer) Navigator.of(context).pop();
final ownProfile = await SimpleDialogs(context) final ownProfile = await SimpleDialogs(context)
.tryRequestWithLoadingDialog(Matrix.of(context).client.ownProfile); .tryRequestWithLoadingDialog(Matrix.of(context).client.ownProfile);
String composeText;
if (Matrix.of(context).shareContent != null &&
Matrix.of(context).shareContent['msgtype'] == 'm.text') {
composeText = Matrix.of(context).shareContent['body'];
Matrix.of(context).shareContent = null;
}
if (ownProfile is Profile) { if (ownProfile is Profile) {
await Navigator.of(context).push( await Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (_) => PresenceView( builder: (_) => StatusView(
composeMode: true, composeMode: true,
avatarUrl: ownProfile.avatarUrl, avatarUrl: ownProfile.avatarUrl,
displayname: ownProfile.displayname, displayname: ownProfile.displayname ??
Matrix.of(context).client.userID.localpart,
composeText: composeText,
), ),
), ),
); );
@ -293,7 +302,8 @@ class _ChatListState extends State<ChatList> {
ListTile( ListTile(
leading: Icon(Icons.edit), leading: Icon(Icons.edit),
title: Text(L10n.of(context).setStatus), title: Text(L10n.of(context).setStatus),
onTap: () => _setStatus(context), onTap: () =>
_setStatus(context, fromDrawer: true),
), ),
Divider(height: 1), Divider(height: 1),
ListTile( ListTile(
@ -414,14 +424,32 @@ class _ChatListState extends State<ChatList> {
(AdaptivePageLayout.columnMode(context) || (AdaptivePageLayout.columnMode(context) ||
selectMode != SelectMode.normal) selectMode != SelectMode.normal)
? null ? null
: FloatingActionButton( : Column(
child: Icon(Icons.add), mainAxisSize: MainAxisSize.min,
backgroundColor: Theme.of(context).primaryColor, children: [
onPressed: () => Navigator.of(context) FloatingActionButton(
.pushAndRemoveUntil( heroTag: null,
AppRoute.defaultRoute( child: Icon(
context, NewPrivateChatView()), Icons.edit,
(r) => r.isFirst), color: Theme.of(context).primaryColor,
),
elevation: 1,
backgroundColor:
Theme.of(context).secondaryHeaderColor,
onPressed: () => _setStatus(context),
),
SizedBox(height: 16.0),
FloatingActionButton(
child: Icon(Icons.add),
backgroundColor:
Theme.of(context).primaryColor,
onPressed: () => Navigator.of(context)
.pushAndRemoveUntil(
AppRoute.defaultRoute(
context, NewPrivateChatView()),
(r) => r.isFirst),
),
],
), ),
body: Column( body: Column(
children: [ children: [
@ -432,7 +460,8 @@ class _ChatListState extends State<ChatList> {
.client .client
.onSync .onSync
.stream .stream
.where((s) => s.hasRoomUpdate), .where((s) =>
s.hasRoomUpdate || s.hasPresenceUpdate),
builder: (context, snapshot) { builder: (context, snapshot) {
return FutureBuilder<void>( return FutureBuilder<void>(
future: waitForFirstSync(context), future: waitForFirstSync(context),
@ -475,19 +504,6 @@ class _ChatListState extends State<ChatList> {
0); 0);
final totalCount = final totalCount =
rooms.length + publicRoomsCount; rooms.length + publicRoomsCount;
final directChats = rooms
.where((r) => r.isDirectChat)
.toList();
final presences =
Matrix.of(context).client.presences;
directChats.sort((a, b) => presences[
b.directChatMatrixID]
?.presence
?.statusMsg !=
null
? 1
: b.lastEvent.originServerTs.compareTo(
a.lastEvent.originServerTs));
return ListView.separated( return ListView.separated(
controller: _scrollController, controller: _scrollController,
separatorBuilder: (BuildContext context, separatorBuilder: (BuildContext context,
@ -511,31 +527,70 @@ class _ChatListState extends State<ChatList> {
itemBuilder: itemBuilder:
(BuildContext context, int i) { (BuildContext context, int i) {
if (i == 0) { if (i == 0) {
final displayPresences = directChats final displayPresences =
.isNotEmpty && Matrix.of(context)
selectMode == SelectMode.normal; .userStatuses
.isNotEmpty &&
selectMode ==
SelectMode.normal;
final displayShareStatus =
selectMode ==
SelectMode.share &&
Matrix.of(context)
.shareContent[
'msgtype'] ==
'm.text';
return Column( return Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
AnimatedContainer( AnimatedContainer(
duration: Duration( duration: Duration(
milliseconds: 500), milliseconds: 500),
height: height: displayPresences
displayPresences ? 78 : 0, ? 78
child: !displayPresences : displayShareStatus
? null ? 56
: ListView.builder( : 0,
child: displayPresences
? ListView.builder(
scrollDirection: scrollDirection:
Axis.horizontal, Axis.horizontal,
itemCount: directChats itemCount:
.length, Matrix.of(context)
.userStatuses
.length,
itemBuilder: (BuildContext itemBuilder: (BuildContext
context, context,
int i) => int i) =>
PresenceListItem( StatusListItem(Matrix
directChats[ .of(context)
i]), .userStatuses[i]),
), )
: displayShareStatus
? ListTile(
leading:
CircleAvatar(
radius: Avatar
.defaultSize /
2,
backgroundColor:
Theme.of(
context)
.secondaryHeaderColor,
child: Icon(
Icons.edit,
color: Theme.of(
context)
.primaryColor,
),
),
title: Text(L10n.of(
context)
.setStatus),
onTap: () =>
_setStatus(
context))
: null,
), ),
], ],
); );

View file

@ -2,32 +2,37 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/avatar.dart'; import 'package:fluffychat/components/avatar.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart'; import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/utils/url_launcher.dart';
import 'package:fluffychat/utils/user_status.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/utils/string_color.dart'; import 'package:fluffychat/utils/string_color.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fluffychat/utils/presence_extension.dart'; import 'package:matrix_link_text/link_text.dart';
import 'chat.dart'; import 'chat.dart';
class PresenceView extends StatelessWidget { class StatusView extends StatelessWidget {
final Uri avatarUrl; final Uri avatarUrl;
final String displayname; final String displayname;
final Presence presence; final UserStatus status;
final bool composeMode; final bool composeMode;
final TextEditingController _composeController = TextEditingController(); final String composeText;
final TextEditingController _composeController;
PresenceView({ StatusView({
this.composeMode = false, this.composeMode = false,
this.presence, this.status,
this.avatarUrl, this.avatarUrl,
this.displayname, this.displayname,
this.composeText,
Key key, Key key,
}) : super(key: key); }) : _composeController = TextEditingController(text: composeText),
super(key: key);
void _sendMessageAction(BuildContext context) async { void _sendMessageAction(BuildContext context) async {
final roomId = await User( final roomId = await User(
presence.senderId, status.userId,
room: Room(id: '', client: Matrix.of(context).client), room: Room(id: '', client: Matrix.of(context).client),
).startDirectChat(); ).startDirectChat();
await Navigator.of(context).pushAndRemoveUntil( await Navigator.of(context).pushAndRemoveUntil(
@ -48,9 +53,22 @@ class PresenceView extends StatelessWidget {
await Navigator.of(context).popUntil((Route r) => r.isFirst); await Navigator.of(context).popUntil((Route r) => r.isFirst);
} }
void _removeStatusAction(BuildContext context) async {
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog(
Matrix.of(context).client.sendPresence(
Matrix.of(context).client.userID,
PresenceType.online,
statusMsg:
' ', // Send this empty String make sure that all other devices will get an update
),
);
if (success == false) return;
await Navigator.of(context).popUntil((Route r) => r.isFirst);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (composeMode == false && presence == null) { if (composeMode == false && status == null) {
throw ('If composeMode is null then the presence must be not null!'); throw ('If composeMode is null then the presence must be not null!');
} }
final padding = const EdgeInsets.only( final padding = const EdgeInsets.only(
@ -81,10 +99,20 @@ class PresenceView extends StatelessWidget {
style: TextStyle(color: Colors.white), style: TextStyle(color: Colors.white),
), ),
subtitle: Text( subtitle: Text(
presence?.senderId ?? Matrix.of(context).client.userID, status?.userId ?? Matrix.of(context).client.userID,
style: TextStyle(color: Colors.white), style: TextStyle(color: Colors.white),
), ),
), ),
actions:
!composeMode && status.userId == Matrix.of(context).client.userID
? [
IconButton(
icon: Icon(Icons.archive),
onPressed: () => _removeStatusAction(context),
color: Colors.white,
),
]
: null,
), ),
body: Container( body: Container(
alignment: Alignment.center, alignment: Alignment.center,
@ -121,27 +149,36 @@ class PresenceView extends StatelessWidget {
shrinkWrap: true, shrinkWrap: true,
padding: padding, padding: padding,
children: [ children: [
Text( LinkText(
presence.getLocalizedStatusMessage(context), text: status.statusMsg,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( textStyle: TextStyle(
fontSize: 30, fontSize: 30,
color: Colors.white, color: Colors.white,
), ),
linkStyle: TextStyle(
fontSize: 30,
color: Colors.white70,
decoration: TextDecoration.underline,
),
onLinkTap: (url) => UrlLauncher(context, url).launchUrl(),
), ),
], ],
), ),
), ),
floatingActionButton: FloatingActionButton.extended( floatingActionButton:
backgroundColor: Theme.of(context).primaryColor, !composeMode && status.userId == Matrix.of(context).client.userID
icon: Icon(composeMode ? Icons.edit : Icons.message_outlined), ? null
label: Text(composeMode : FloatingActionButton.extended(
? L10n.of(context).setStatus backgroundColor: Theme.of(context).primaryColor,
: L10n.of(context).sendAMessage), icon: Icon(composeMode ? Icons.edit : Icons.message_outlined),
onPressed: () => composeMode label: Text(composeMode
? _setStatusAction(context) ? L10n.of(context).setStatus
: _sendMessageAction(context), : L10n.of(context).sendAMessage),
), onPressed: () => composeMode
? _setStatusAction(context)
: _sendMessageAction(context),
),
); );
} }
} }