Merge branch 'krille/remove-status-feature' into 'main'
Krille/remove status feature See merge request ChristianPauly/fluffychat-flutter!245onboarding
commit
286742767a
@ -1,83 +0,0 @@
|
||||
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(status.userId.localpart, null);
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,186 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/utils/fluffy_share.dart';
|
||||
import 'package:fluffychat/views/chat.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'content_banner.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import '../utils/presence_extension.dart';
|
||||
import 'dialogs/simple_dialogs.dart';
|
||||
import 'matrix.dart';
|
||||
|
||||
class UserBottomSheet extends StatelessWidget {
|
||||
final User user;
|
||||
final Function onMention;
|
||||
|
||||
const UserBottomSheet({Key key, @required this.user, this.onMention})
|
||||
: super(key: key);
|
||||
|
||||
void participantAction(BuildContext context, String action) async {
|
||||
switch (action) {
|
||||
case 'mention':
|
||||
Navigator.of(context).pop();
|
||||
onMention();
|
||||
break;
|
||||
case 'ban':
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(user.ban());
|
||||
}
|
||||
break;
|
||||
case 'unban':
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.unban());
|
||||
}
|
||||
break;
|
||||
case 'kick':
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(user.kick());
|
||||
}
|
||||
break;
|
||||
case 'admin':
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.setPower(100));
|
||||
}
|
||||
break;
|
||||
case 'moderator':
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.setPower(50));
|
||||
}
|
||||
break;
|
||||
case 'user':
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.setPower(0));
|
||||
}
|
||||
break;
|
||||
case 'message':
|
||||
final roomId = await user.startDirectChat();
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatView(roomId),
|
||||
),
|
||||
(Route r) => r.isFirst);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final presence = Matrix.of(context).client.presences[user.id];
|
||||
var items = <PopupMenuEntry<String>>[];
|
||||
|
||||
if (onMention != null) {
|
||||
items.add(
|
||||
PopupMenuItem(child: Text(L10n.of(context).mention), value: 'mention'),
|
||||
);
|
||||
}
|
||||
if (user.id != Matrix.of(context).client.userID) {
|
||||
items.add(
|
||||
PopupMenuItem(
|
||||
child: Text(L10n.of(context).sendAMessage), value: 'message'),
|
||||
);
|
||||
}
|
||||
if (user.canChangePowerLevel &&
|
||||
user.room.ownPowerLevel == 100 &&
|
||||
user.powerLevel != 100) {
|
||||
items.add(
|
||||
PopupMenuItem(
|
||||
child: Text(L10n.of(context).makeAnAdmin), value: 'admin'),
|
||||
);
|
||||
}
|
||||
if (user.canChangePowerLevel &&
|
||||
user.room.ownPowerLevel >= 50 &&
|
||||
user.powerLevel != 50) {
|
||||
items.add(
|
||||
PopupMenuItem(
|
||||
child: Text(L10n.of(context).makeAModerator), value: 'moderator'),
|
||||
);
|
||||
}
|
||||
if (user.canChangePowerLevel && user.powerLevel != 0) {
|
||||
items.add(
|
||||
PopupMenuItem(
|
||||
child: Text(L10n.of(context).revokeAllPermissions), value: 'user'),
|
||||
);
|
||||
}
|
||||
if (user.canKick) {
|
||||
items.add(
|
||||
PopupMenuItem(
|
||||
child: Text(L10n.of(context).kickFromChat), value: 'kick'),
|
||||
);
|
||||
}
|
||||
if (user.canBan && user.membership != Membership.ban) {
|
||||
items.add(
|
||||
PopupMenuItem(child: Text(L10n.of(context).banFromChat), value: 'ban'),
|
||||
);
|
||||
} else if (user.canBan && user.membership == Membership.ban) {
|
||||
items.add(
|
||||
PopupMenuItem(
|
||||
child: Text(L10n.of(context).removeExile), value: 'unban'),
|
||||
);
|
||||
}
|
||||
return Center(
|
||||
child: Container(
|
||||
width: min(MediaQuery.of(context).size.width,
|
||||
AdaptivePageLayout.defaultMinWidth * 1.5),
|
||||
child: SafeArea(
|
||||
child: Material(
|
||||
elevation: 4,
|
||||
child: Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: AppBar(
|
||||
elevation: 0,
|
||||
backgroundColor:
|
||||
Theme.of(context).scaffoldBackgroundColor.withOpacity(0.5),
|
||||
leading: IconButton(
|
||||
icon: Icon(Icons.arrow_downward_outlined),
|
||||
onPressed: Navigator.of(context).pop,
|
||||
),
|
||||
title: Text(user.calcDisplayname()),
|
||||
actions: [
|
||||
if (user.id != Matrix.of(context).client.userID)
|
||||
PopupMenuButton(
|
||||
itemBuilder: (_) => items,
|
||||
onSelected: (action) =>
|
||||
participantAction(context, action),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
ContentBanner(
|
||||
user.avatarUrl,
|
||||
defaultIcon: Icons.person_outline,
|
||||
),
|
||||
ListTile(
|
||||
title: Text(L10n.of(context).username),
|
||||
subtitle: Text(user.id),
|
||||
trailing: Icon(Icons.share),
|
||||
onTap: () => FluffyShare.share(user.id, context),
|
||||
),
|
||||
if (presence != null)
|
||||
ListTile(
|
||||
title: Text(presence.getLocalizedStatusMessage(context)),
|
||||
subtitle:
|
||||
Text(presence.getLocalizedLastActiveAgo(context)),
|
||||
trailing: Icon(Icons.circle,
|
||||
color: presence.presence.currentlyActive
|
||||
? Colors.green
|
||||
: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:share/share.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
abstract class FluffyShare {
|
||||
static Future<void> share(String text, BuildContext context) async {
|
||||
if (PlatformInfos.isMobile) {
|
||||
return Share.share(text);
|
||||
}
|
||||
await Clipboard.setData(
|
||||
ClipboardData(text: text),
|
||||
);
|
||||
BotToast.showText(text: L10n.of(context).copiedToClipboard);
|
||||
return;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -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…
Reference in New Issue