Krille/remove status feature
This commit is contained in:
parent
61ceb7d723
commit
e3f1fc757c
13 changed files with 372 additions and 651 deletions
|
|
@ -15,6 +15,7 @@ import 'package:fluffychat/components/encryption_button.dart';
|
|||
import 'package:fluffychat/components/list_items/message.dart';
|
||||
import 'package:fluffychat/components/matrix.dart';
|
||||
import 'package:fluffychat/components/reply_content.dart';
|
||||
import 'package:fluffychat/components/user_bottom_sheet.dart';
|
||||
import 'package:fluffychat/config/app_emojis.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/utils/matrix_locals.dart';
|
||||
|
|
@ -476,16 +477,22 @@ class _ChatState extends State<_Chat> {
|
|||
return ListTile(
|
||||
leading: Avatar(room.avatar, room.displayname),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
onTap: room.isDirectChat && room.directChatPresence == null
|
||||
? null
|
||||
: room.isDirectChat
|
||||
? null
|
||||
: () => Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatDetails(room),
|
||||
),
|
||||
),
|
||||
onTap: room.isDirectChat
|
||||
? () => showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => UserBottomSheet(
|
||||
user: room
|
||||
.getUserByMXIDSync(room.directChatMatrixID),
|
||||
onMention: () => sendController.text +=
|
||||
' ${room.directChatMatrixID}',
|
||||
),
|
||||
)
|
||||
: () => Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatDetails(room),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
room.getLocalizedDisplayname(
|
||||
MatrixLocals(L10n.of(context))),
|
||||
|
|
@ -684,10 +691,17 @@ class _ChatState extends State<_Chat> {
|
|||
onSwipe: (direction) => replyAction(
|
||||
replyTo: filteredEvents[i - 1]),
|
||||
child: Message(filteredEvents[i - 1],
|
||||
onAvatarTab: (Event event) {
|
||||
sendController.text +=
|
||||
' ${event.senderId}';
|
||||
},
|
||||
onAvatarTab: (Event event) =>
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
UserBottomSheet(
|
||||
user: event.sender,
|
||||
onMention: () =>
|
||||
sendController.text +=
|
||||
' ${event.senderId}',
|
||||
),
|
||||
),
|
||||
onSelect: (Event event) {
|
||||
if (!event.redacted) {
|
||||
if (selectedEvents
|
||||
|
|
|
|||
|
|
@ -3,18 +3,15 @@ import 'dart:io';
|
|||
|
||||
import 'package:famedlysdk/famedlysdk.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/dialogs/simple_dialogs.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/utils/fluffy_share.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/views/status_view.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
|
||||
import 'package:share/share.dart';
|
||||
|
||||
import '../components/adaptive_page_layout.dart';
|
||||
import '../components/list_items/chat_list_item.dart';
|
||||
|
|
@ -198,29 +195,23 @@ class _ChatListState extends State<ChatList> {
|
|||
);
|
||||
}
|
||||
|
||||
void _setStatus(BuildContext context, {bool fromDrawer = false}) async {
|
||||
if (fromDrawer) Navigator.of(context).pop();
|
||||
final ownProfile = await SimpleDialogs(context)
|
||||
.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) {
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => StatusView(
|
||||
composeMode: true,
|
||||
avatarUrl: ownProfile.avatarUrl,
|
||||
displayname: ownProfile.displayname ??
|
||||
Matrix.of(context).client.userID.localpart,
|
||||
composeText: composeText,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
void _setStatus(BuildContext context) async {
|
||||
Navigator.of(context).pop();
|
||||
final statusMsg = await SimpleDialogs(context).enterText(
|
||||
titleText: L10n.of(context).setStatus,
|
||||
labelText: L10n.of(context).setStatus,
|
||||
hintText: L10n.of(context).statusExampleMessage,
|
||||
multiLine: true,
|
||||
);
|
||||
if (statusMsg?.isEmpty ?? true) return;
|
||||
final client = Matrix.of(context).client;
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
client.sendPresence(
|
||||
client.userID,
|
||||
PresenceType.online,
|
||||
statusMsg: statusMsg,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -302,8 +293,7 @@ class _ChatListState extends State<ChatList> {
|
|||
ListTile(
|
||||
leading: Icon(Icons.edit),
|
||||
title: Text(L10n.of(context).setStatus),
|
||||
onTap: () =>
|
||||
_setStatus(context, fromDrawer: true),
|
||||
onTap: () => _setStatus(context),
|
||||
),
|
||||
Divider(height: 1),
|
||||
ListTile(
|
||||
|
|
@ -338,9 +328,11 @@ class _ChatListState extends State<ChatList> {
|
|||
title: Text(L10n.of(context).inviteContact),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
Share.share(L10n.of(context).inviteText(
|
||||
Matrix.of(context).client.userID,
|
||||
'https://matrix.to/#/${Matrix.of(context).client.userID}'));
|
||||
FluffyShare.share(
|
||||
L10n.of(context).inviteText(
|
||||
Matrix.of(context).client.userID,
|
||||
'https://matrix.to/#/${Matrix.of(context).client.userID}'),
|
||||
context);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
|
@ -422,31 +414,14 @@ class _ChatListState extends State<ChatList> {
|
|||
),
|
||||
floatingActionButton: AdaptivePageLayout.columnMode(context)
|
||||
? null
|
||||
: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
FloatingActionButton(
|
||||
heroTag: null,
|
||||
child: Icon(
|
||||
Icons.edit,
|
||||
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),
|
||||
),
|
||||
],
|
||||
: FloatingActionButton(
|
||||
child: Icon(Icons.add),
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
onPressed: () => Navigator.of(context)
|
||||
.pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(
|
||||
context, NewPrivateChatView()),
|
||||
(r) => r.isFirst),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
|
|
@ -506,94 +481,28 @@ class _ChatListState extends State<ChatList> {
|
|||
final totalCount =
|
||||
rooms.length + publicRoomsCount;
|
||||
return ListView.separated(
|
||||
controller: _scrollController,
|
||||
separatorBuilder: (BuildContext context,
|
||||
int i) =>
|
||||
i == totalCount - publicRoomsCount
|
||||
? ListTile(
|
||||
title: Text(
|
||||
L10n.of(context)
|
||||
.publicRooms +
|
||||
':',
|
||||
style: TextStyle(
|
||||
fontWeight:
|
||||
FontWeight.bold,
|
||||
color: Theme.of(context)
|
||||
.primaryColor,
|
||||
),
|
||||
controller: _scrollController,
|
||||
separatorBuilder: (BuildContext context,
|
||||
int i) =>
|
||||
i == totalCount - publicRoomsCount
|
||||
? ListTile(
|
||||
title: Text(
|
||||
L10n.of(context)
|
||||
.publicRooms +
|
||||
':',
|
||||
style: TextStyle(
|
||||
fontWeight:
|
||||
FontWeight.bold,
|
||||
color: Theme.of(context)
|
||||
.primaryColor,
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
itemCount: totalCount + 1,
|
||||
itemBuilder:
|
||||
(BuildContext context, int i) {
|
||||
if (i == 0) {
|
||||
final displayPresences =
|
||||
selectMode != SelectMode.share;
|
||||
final displayShareStatus =
|
||||
selectMode ==
|
||||
SelectMode.share &&
|
||||
Matrix.of(context)
|
||||
.shareContent[
|
||||
'msgtype'] ==
|
||||
'm.text';
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AnimatedContainer(
|
||||
duration: Duration(
|
||||
milliseconds: 300),
|
||||
height: displayPresences
|
||||
? 78
|
||||
: displayShareStatus
|
||||
? 56
|
||||
: 0,
|
||||
child: displayPresences
|
||||
? ListView.builder(
|
||||
scrollDirection:
|
||||
Axis.horizontal,
|
||||
itemCount:
|
||||
Matrix.of(context)
|
||||
.userStatuses
|
||||
.length,
|
||||
itemBuilder: (BuildContext
|
||||
context,
|
||||
int i) =>
|
||||
StatusListItem(Matrix
|
||||
.of(context)
|
||||
.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,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
i--;
|
||||
return i < rooms.length
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
itemCount: totalCount,
|
||||
itemBuilder: (BuildContext context,
|
||||
int i) =>
|
||||
i < rooms.length
|
||||
? ChatListItem(
|
||||
rooms[i],
|
||||
selected: _selectedRoomIds
|
||||
|
|
@ -614,8 +523,9 @@ class _ChatListState extends State<ChatList> {
|
|||
)
|
||||
: PublicRoomListItem(
|
||||
publicRoomsResponse
|
||||
.chunk[i - rooms.length]);
|
||||
});
|
||||
.chunk[i - rooms.length],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ import 'package:fluffychat/components/avatar.dart';
|
|||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||
import 'package:fluffychat/components/matrix.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/utils/fluffy_share.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:share/share.dart';
|
||||
|
||||
import 'chat.dart';
|
||||
import 'chat_list.dart';
|
||||
|
|
@ -204,9 +204,10 @@ class _NewPrivateChatState extends State<_NewPrivateChat> {
|
|||
Icons.share,
|
||||
size: 16,
|
||||
),
|
||||
onTap: () => Share.share(L10n.of(context).inviteText(
|
||||
Matrix.of(context).client.userID,
|
||||
'https://matrix.to/#/${Matrix.of(context).client.userID}')),
|
||||
onTap: () => FluffyShare.share(
|
||||
L10n.of(context).inviteText(Matrix.of(context).client.userID,
|
||||
'https://matrix.to/#/${Matrix.of(context).client.userID}'),
|
||||
context),
|
||||
title: Text(
|
||||
'${L10n.of(context).yourOwnUsername}:',
|
||||
style: TextStyle(
|
||||
|
|
|
|||
|
|
@ -1,186 +0,0 @@
|
|||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/avatar.dart';
|
||||
import 'package:fluffychat/components/dialogs/simple_dialogs.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:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/utils/string_color.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix_link_text/link_text.dart';
|
||||
|
||||
import 'chat.dart';
|
||||
|
||||
class StatusView extends StatelessWidget {
|
||||
final Uri avatarUrl;
|
||||
final String displayname;
|
||||
final UserStatus status;
|
||||
final bool composeMode;
|
||||
final String composeText;
|
||||
final TextEditingController _composeController;
|
||||
|
||||
StatusView({
|
||||
this.composeMode = false,
|
||||
this.status,
|
||||
this.avatarUrl,
|
||||
this.displayname,
|
||||
this.composeText,
|
||||
Key key,
|
||||
}) : _composeController = TextEditingController(text: composeText),
|
||||
super(key: key);
|
||||
|
||||
void _sendMessageAction(BuildContext context) async {
|
||||
final roomId = await User(
|
||||
status.userId,
|
||||
room: Room(id: '', client: Matrix.of(context).client),
|
||||
).startDirectChat();
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatView(roomId),
|
||||
),
|
||||
(Route r) => r.isFirst);
|
||||
}
|
||||
|
||||
void _setStatusAction(BuildContext context) async {
|
||||
if (_composeController.text.isEmpty) return;
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
Matrix.of(context).client.sendPresence(
|
||||
Matrix.of(context).client.userID, PresenceType.online,
|
||||
statusMsg: _composeController.text),
|
||||
);
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
if (composeMode == false && status == null) {
|
||||
throw ('If composeMode is null then the presence must be not null!');
|
||||
}
|
||||
final padding = const EdgeInsets.only(
|
||||
top: 16.0,
|
||||
right: 16.0,
|
||||
left: 16.0,
|
||||
bottom: 64.0,
|
||||
);
|
||||
return Scaffold(
|
||||
backgroundColor: displayname.color,
|
||||
extendBody: true,
|
||||
appBar: AppBar(
|
||||
titleSpacing: 0.0,
|
||||
brightness: Brightness.dark,
|
||||
leading: IconButton(
|
||||
icon: Icon(
|
||||
Icons.close,
|
||||
color: Colors.white,
|
||||
),
|
||||
onPressed: Navigator.of(context).pop,
|
||||
),
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 1,
|
||||
title: ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Avatar(avatarUrl, displayname),
|
||||
title: Text(
|
||||
displayname,
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
subtitle: Text(
|
||||
status?.userId ?? Matrix.of(context).client.userID,
|
||||
maxLines: 1,
|
||||
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(
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
displayname.color,
|
||||
Theme.of(context).primaryColor,
|
||||
displayname.color,
|
||||
],
|
||||
),
|
||||
),
|
||||
child: composeMode
|
||||
? Padding(
|
||||
padding: padding,
|
||||
child: TextField(
|
||||
controller: _composeController,
|
||||
autofocus: true,
|
||||
minLines: 1,
|
||||
maxLines: 20,
|
||||
style: TextStyle(
|
||||
fontSize: 30,
|
||||
color: Colors.white,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
)
|
||||
: ListView(
|
||||
shrinkWrap: true,
|
||||
padding: padding,
|
||||
children: [
|
||||
LinkText(
|
||||
text: status.statusMsg,
|
||||
textAlign: TextAlign.center,
|
||||
textStyle: TextStyle(
|
||||
fontSize: 30,
|
||||
color: Colors.white,
|
||||
),
|
||||
linkStyle: TextStyle(
|
||||
fontSize: 30,
|
||||
color: Colors.white70,
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
onLinkTap: (url) => UrlLauncher(context, url).launchUrl(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton:
|
||||
!composeMode && status.userId == Matrix.of(context).client.userID
|
||||
? null
|
||||
: FloatingActionButton.extended(
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
icon: Icon(composeMode ? Icons.edit : Icons.message_outlined),
|
||||
label: Text(composeMode
|
||||
? L10n.of(context).setStatus
|
||||
: L10n.of(context).sendAMessage),
|
||||
onPressed: () => composeMode
|
||||
? _setStatusAction(context)
|
||||
: _sendMessageAction(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue