Krille/remove status feature
This commit is contained in:
@ -1,66 +1,15 @@
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||
import 'package:fluffychat/utils/app_route.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';
|
||||
import '../user_bottom_sheet.dart';
|
||||
|
||||
class ParticipantListItem extends StatelessWidget {
|
||||
final User user;
|
||||
|
||||
const ParticipantListItem(this.user);
|
||||
|
||||
void participantAction(BuildContext context, String action) async {
|
||||
switch (action) {
|
||||
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) {
|
||||
var membershipBatch = <Membership, String>{
|
||||
@ -74,87 +23,43 @@ class ParticipantListItem extends StatelessWidget {
|
||||
: user.powerLevel >= 50
|
||||
? L10n.of(context).moderator
|
||||
: '';
|
||||
var items = <PopupMenuEntry<String>>[];
|
||||
|
||||
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 PopupMenuButton(
|
||||
onSelected: (action) => participantAction(context, action),
|
||||
itemBuilder: (c) => items,
|
||||
child: ListTile(
|
||||
title: Row(
|
||||
children: <Widget>[
|
||||
Text(user.calcDisplayname()),
|
||||
permissionBatch.isEmpty
|
||||
? Container()
|
||||
: Container(
|
||||
padding: EdgeInsets.all(4),
|
||||
margin: EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).secondaryHeaderColor,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Center(child: Text(permissionBatch)),
|
||||
),
|
||||
membershipBatch[user.membership].isEmpty
|
||||
? Container()
|
||||
: Container(
|
||||
padding: EdgeInsets.all(4),
|
||||
margin: EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).secondaryHeaderColor,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child:
|
||||
Center(child: Text(membershipBatch[user.membership])),
|
||||
),
|
||||
],
|
||||
return ListTile(
|
||||
onTap: () => showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => UserBottomSheet(
|
||||
user: user,
|
||||
),
|
||||
subtitle: Text(user.id),
|
||||
leading: Avatar(user.avatarUrl, user.calcDisplayname()),
|
||||
),
|
||||
title: Row(
|
||||
children: <Widget>[
|
||||
Text(user.calcDisplayname()),
|
||||
permissionBatch.isEmpty
|
||||
? Container()
|
||||
: Container(
|
||||
padding: EdgeInsets.all(4),
|
||||
margin: EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).secondaryHeaderColor,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Center(child: Text(permissionBatch)),
|
||||
),
|
||||
membershipBatch[user.membership].isEmpty
|
||||
? Container()
|
||||
: Container(
|
||||
padding: EdgeInsets.all(4),
|
||||
margin: EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).secondaryHeaderColor,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Center(child: Text(membershipBatch[user.membership])),
|
||||
),
|
||||
],
|
||||
),
|
||||
subtitle: Text(user.id),
|
||||
leading: Avatar(user.avatarUrl, user.calcDisplayname()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -7,7 +7,6 @@ import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||
import 'package:fluffychat/utils/firebase_controller.dart';
|
||||
import 'package:fluffychat/utils/matrix_locals.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/utils/user_status.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
@ -22,7 +21,6 @@ import '../main.dart';
|
||||
import '../utils/app_route.dart';
|
||||
import '../utils/beautify_string_extension.dart';
|
||||
import '../utils/famedlysdk_store.dart';
|
||||
import '../utils/presence_extension.dart';
|
||||
import '../views/key_verification.dart';
|
||||
import '../utils/platform_infos.dart';
|
||||
import 'avatar.dart';
|
||||
@ -91,7 +89,6 @@ class MatrixState extends State<Matrix> {
|
||||
await client.connect();
|
||||
final firstLoginState = await initLoginState;
|
||||
if (firstLoginState == LoginState.logged) {
|
||||
_cleanUpUserStatus(userStatuses);
|
||||
if (PlatformInfos.isMobile) {
|
||||
await FirebaseController.setupFirebase(
|
||||
this,
|
||||
@ -123,7 +120,6 @@ class MatrixState extends State<Matrix> {
|
||||
StreamSubscription onNotification;
|
||||
StreamSubscription<html.Event> onFocusSub;
|
||||
StreamSubscription<html.Event> onBlurSub;
|
||||
StreamSubscription onPresenceSub;
|
||||
|
||||
void onJitsiCall(EventUpdate eventUpdate) {
|
||||
final event = Event.fromJson(
|
||||
@ -246,9 +242,6 @@ class MatrixState extends State<Matrix> {
|
||||
importantStateEvents: <String>{
|
||||
'im.ponies.room_emotes', // we want emotes to work properly
|
||||
});
|
||||
onPresenceSub ??= client.onPresence.stream
|
||||
.where((p) => p.isUserStatus)
|
||||
.listen(_storeUserStatus);
|
||||
onJitsiCallSub ??= client.onEvent.stream
|
||||
.where((e) =>
|
||||
e.type == 'timeline' &&
|
||||
@ -330,64 +323,11 @@ class MatrixState extends State<Matrix> {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
List<UserStatus> get userStatuses {
|
||||
try {
|
||||
return (client.accountData[userStatusesType].content['user_statuses']
|
||||
as List)
|
||||
.map((json) => UserStatus.fromJson(json))
|
||||
.toList();
|
||||
} catch (_) {}
|
||||
return [];
|
||||
}
|
||||
|
||||
void _storeUserStatus(Presence presence) {
|
||||
final tmpUserStatuses = List<UserStatus>.from(userStatuses);
|
||||
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) {
|
||||
tmpUserStatuses.add(newUserStatus);
|
||||
} else if (tmpUserStatuses[currentStatusIndex].statusMsg !=
|
||||
presence.presence.statusMsg) {
|
||||
if (presence.presence.statusMsg.trim().isEmpty) {
|
||||
tmpUserStatuses.removeAt(currentStatusIndex);
|
||||
} else {
|
||||
tmpUserStatuses[currentStatusIndex] = newUserStatus;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
_cleanUpUserStatus(tmpUserStatuses);
|
||||
}
|
||||
|
||||
void _cleanUpUserStatus(List<UserStatus> tmpUserStatuses) {
|
||||
final now = DateTime.now().millisecondsSinceEpoch;
|
||||
tmpUserStatuses
|
||||
.removeWhere((u) => (now - u.receivedAt) > (1000 * 60 * 60 * 24));
|
||||
tmpUserStatuses.sort((a, b) => b.receivedAt.compareTo(a.receivedAt));
|
||||
if (tmpUserStatuses.length > 40) {
|
||||
tmpUserStatuses.removeRange(40, tmpUserStatuses.length);
|
||||
}
|
||||
if (tmpUserStatuses != userStatuses) {
|
||||
client.setAccountData(
|
||||
client.userID,
|
||||
userStatusesType,
|
||||
{
|
||||
'user_statuses': tmpUserStatuses.map((i) => i.toJson()).toList(),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
onRoomKeyRequestSub?.cancel();
|
||||
onKeyVerificationRequestSub?.cancel();
|
||||
onJitsiCallSub?.cancel();
|
||||
onPresenceSub?.cancel();
|
||||
onNotification?.cancel();
|
||||
onFocusSub?.cancel();
|
||||
onBlurSub?.cancel();
|
||||
|
||||
186
lib/components/user_bottom_sheet.dart
Normal file
186
lib/components/user_bottom_sheet.dart
Normal file
@ -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),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user