feat: Implement new status feature
This commit is contained in:
parent
0f056a4b86
commit
c5d84c22ca
10 changed files with 329 additions and 245 deletions
|
|
@ -3,12 +3,13 @@ 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/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/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/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
|
@ -197,17 +198,25 @@ class _ChatListState extends State<ChatList> {
|
|||
);
|
||||
}
|
||||
|
||||
void _setStatus(BuildContext context) async {
|
||||
Navigator.of(context).pop();
|
||||
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: (_) => PresenceView(
|
||||
builder: (_) => StatusView(
|
||||
composeMode: true,
|
||||
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(
|
||||
leading: Icon(Icons.edit),
|
||||
title: Text(L10n.of(context).setStatus),
|
||||
onTap: () => _setStatus(context),
|
||||
onTap: () =>
|
||||
_setStatus(context, fromDrawer: true),
|
||||
),
|
||||
Divider(height: 1),
|
||||
ListTile(
|
||||
|
|
@ -414,14 +424,32 @@ class _ChatListState extends State<ChatList> {
|
|||
(AdaptivePageLayout.columnMode(context) ||
|
||||
selectMode != SelectMode.normal)
|
||||
? null
|
||||
: FloatingActionButton(
|
||||
child: Icon(Icons.add),
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
onPressed: () => Navigator.of(context)
|
||||
.pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(
|
||||
context, NewPrivateChatView()),
|
||||
(r) => r.isFirst),
|
||||
: 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),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
|
|
@ -432,7 +460,8 @@ class _ChatListState extends State<ChatList> {
|
|||
.client
|
||||
.onSync
|
||||
.stream
|
||||
.where((s) => s.hasRoomUpdate),
|
||||
.where((s) =>
|
||||
s.hasRoomUpdate || s.hasPresenceUpdate),
|
||||
builder: (context, snapshot) {
|
||||
return FutureBuilder<void>(
|
||||
future: waitForFirstSync(context),
|
||||
|
|
@ -475,19 +504,6 @@ class _ChatListState extends State<ChatList> {
|
|||
0);
|
||||
final totalCount =
|
||||
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(
|
||||
controller: _scrollController,
|
||||
separatorBuilder: (BuildContext context,
|
||||
|
|
@ -511,31 +527,70 @@ class _ChatListState extends State<ChatList> {
|
|||
itemBuilder:
|
||||
(BuildContext context, int i) {
|
||||
if (i == 0) {
|
||||
final displayPresences = directChats
|
||||
.isNotEmpty &&
|
||||
selectMode == SelectMode.normal;
|
||||
final displayPresences =
|
||||
Matrix.of(context)
|
||||
.userStatuses
|
||||
.isNotEmpty &&
|
||||
selectMode ==
|
||||
SelectMode.normal;
|
||||
final displayShareStatus =
|
||||
selectMode ==
|
||||
SelectMode.share &&
|
||||
Matrix.of(context)
|
||||
.shareContent[
|
||||
'msgtype'] ==
|
||||
'm.text';
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AnimatedContainer(
|
||||
duration: Duration(
|
||||
milliseconds: 500),
|
||||
height:
|
||||
displayPresences ? 78 : 0,
|
||||
child: !displayPresences
|
||||
? null
|
||||
: ListView.builder(
|
||||
height: displayPresences
|
||||
? 78
|
||||
: displayShareStatus
|
||||
? 56
|
||||
: 0,
|
||||
child: displayPresences
|
||||
? ListView.builder(
|
||||
scrollDirection:
|
||||
Axis.horizontal,
|
||||
itemCount: directChats
|
||||
.length,
|
||||
itemCount:
|
||||
Matrix.of(context)
|
||||
.userStatuses
|
||||
.length,
|
||||
itemBuilder: (BuildContext
|
||||
context,
|
||||
int i) =>
|
||||
PresenceListItem(
|
||||
directChats[
|
||||
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,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
|
|||
|
|
@ -2,32 +2,37 @@ 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:fluffychat/utils/presence_extension.dart';
|
||||
import 'package:matrix_link_text/link_text.dart';
|
||||
|
||||
import 'chat.dart';
|
||||
|
||||
class PresenceView extends StatelessWidget {
|
||||
class StatusView extends StatelessWidget {
|
||||
final Uri avatarUrl;
|
||||
final String displayname;
|
||||
final Presence presence;
|
||||
final UserStatus status;
|
||||
final bool composeMode;
|
||||
final TextEditingController _composeController = TextEditingController();
|
||||
final String composeText;
|
||||
final TextEditingController _composeController;
|
||||
|
||||
PresenceView({
|
||||
StatusView({
|
||||
this.composeMode = false,
|
||||
this.presence,
|
||||
this.status,
|
||||
this.avatarUrl,
|
||||
this.displayname,
|
||||
this.composeText,
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
}) : _composeController = TextEditingController(text: composeText),
|
||||
super(key: key);
|
||||
|
||||
void _sendMessageAction(BuildContext context) async {
|
||||
final roomId = await User(
|
||||
presence.senderId,
|
||||
status.userId,
|
||||
room: Room(id: '', client: Matrix.of(context).client),
|
||||
).startDirectChat();
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
|
|
@ -48,9 +53,22 @@ class PresenceView extends StatelessWidget {
|
|||
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 && presence == null) {
|
||||
if (composeMode == false && status == null) {
|
||||
throw ('If composeMode is null then the presence must be not null!');
|
||||
}
|
||||
final padding = const EdgeInsets.only(
|
||||
|
|
@ -81,10 +99,20 @@ class PresenceView extends StatelessWidget {
|
|||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
subtitle: Text(
|
||||
presence?.senderId ?? Matrix.of(context).client.userID,
|
||||
status?.userId ?? Matrix.of(context).client.userID,
|
||||
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,
|
||||
|
|
@ -121,27 +149,36 @@ class PresenceView extends StatelessWidget {
|
|||
shrinkWrap: true,
|
||||
padding: padding,
|
||||
children: [
|
||||
Text(
|
||||
presence.getLocalizedStatusMessage(context),
|
||||
LinkText(
|
||||
text: status.statusMsg,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
textStyle: TextStyle(
|
||||
fontSize: 30,
|
||||
color: Colors.white,
|
||||
),
|
||||
linkStyle: TextStyle(
|
||||
fontSize: 30,
|
||||
color: Colors.white70,
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
onLinkTap: (url) => UrlLauncher(context, url).launchUrl(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: 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),
|
||||
),
|
||||
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