feat: Improved mouse support for selecting events

This commit is contained in:
krille-chan 2023-08-17 19:16:12 +02:00
parent 56c7c72f92
commit 6e9d3627cc
No known key found for this signature in database
3 changed files with 109 additions and 96 deletions

View file

@ -816,6 +816,17 @@ class ChatController extends State<ChatPageWithRoom> {
return true; return true;
} }
bool get canPinSelectedEvents {
if (isArchived ||
!room.canChangeStateEvent(EventTypes.RoomPinnedEvents) ||
selectedEvents.length != 1 ||
!selectedEvents.single.status.isSent) {
return false;
}
return currentRoomBundle
.any((cl) => selectedEvents.first.senderId == cl!.userID);
}
bool get canEditSelectedEvents { bool get canEditSelectedEvents {
if (isArchived || if (isArchived ||
selectedEvents.length != 1 || selectedEvents.length != 1 ||

View file

@ -54,17 +54,18 @@ class ChatView extends StatelessWidget {
onPressed: () => controller.saveSelectedEvent(context), onPressed: () => controller.saveSelectedEvent(context),
), ),
), ),
if (controller.canPinSelectedEvents)
IconButton(
icon: const Icon(Icons.push_pin_outlined),
onPressed: controller.pinEvent,
tooltip: L10n.of(context)!.pinMessage,
),
if (controller.canRedactSelectedEvents) if (controller.canRedactSelectedEvents)
IconButton( IconButton(
icon: const Icon(Icons.delete_outlined), icon: const Icon(Icons.delete_outlined),
tooltip: L10n.of(context)!.redactMessage, tooltip: L10n.of(context)!.redactMessage,
onPressed: controller.redactEventsAction, onPressed: controller.redactEventsAction,
), ),
IconButton(
icon: const Icon(Icons.push_pin_outlined),
onPressed: controller.pinEvent,
tooltip: L10n.of(context)!.pinMessage,
),
if (controller.selectedEvents.length == 1) if (controller.selectedEvents.length == 1)
PopupMenuButton<_EventContextAction>( PopupMenuButton<_EventContextAction>(
onSelected: (action) { onSelected: (action) {

View file

@ -117,83 +117,80 @@ class Message extends StatelessWidget {
: Theme.of(context).colorScheme.primaryContainer; : Theme.of(context).colorScheme.primaryContainer;
} }
final rowChildren = <Widget>[ final row = Row(
sameSender || ownMessage crossAxisAlignment: CrossAxisAlignment.start,
? SizedBox( mainAxisAlignment: rowMainAxisAlignment,
width: Avatar.defaultSize, children: [
child: Padding( sameSender || ownMessage
padding: const EdgeInsets.only(top: 8.0), ? SizedBox(
child: Center( width: Avatar.defaultSize,
child: SizedBox( child: Padding(
width: 16, padding: const EdgeInsets.only(top: 8.0),
height: 16, child: Center(
child: event.status == EventStatus.sending child: SizedBox(
? const CircularProgressIndicator.adaptive( width: 16,
strokeWidth: 2, height: 16,
) child: event.status == EventStatus.sending
: event.status == EventStatus.error ? const CircularProgressIndicator.adaptive(
? const Icon(Icons.error, color: Colors.red) strokeWidth: 2,
: null, )
: event.status == EventStatus.error
? const Icon(Icons.error, color: Colors.red)
: null,
),
), ),
), ),
)
: FutureBuilder<User?>(
future: event.fetchSenderUser(),
builder: (context, snapshot) {
final user =
snapshot.data ?? event.senderFromMemoryOrFallback;
return Avatar(
mxContent: user.avatarUrl,
name: user.calcDisplayname(),
onTap: () => onAvatarTab!(event),
);
},
), ),
) Expanded(
: FutureBuilder<User?>( child: Column(
future: event.fetchSenderUser(), crossAxisAlignment: CrossAxisAlignment.start,
builder: (context, snapshot) { mainAxisSize: MainAxisSize.min,
final user = snapshot.data ?? event.senderFromMemoryOrFallback; children: [
return Avatar( if (!sameSender)
mxContent: user.avatarUrl, Padding(
name: user.calcDisplayname(), padding: const EdgeInsets.only(left: 8.0, bottom: 4),
onTap: () => onAvatarTab!(event), child: ownMessage || event.room.isDirectChat
); ? const SizedBox(height: 12)
}, : FutureBuilder<User?>(
), future: event.fetchSenderUser(),
Expanded( builder: (context, snapshot) {
child: Column( final displayname =
crossAxisAlignment: CrossAxisAlignment.start, snapshot.data?.calcDisplayname() ??
mainAxisSize: MainAxisSize.min, event.senderFromMemoryOrFallback
children: [ .calcDisplayname();
if (!sameSender) return Text(
Padding( displayname,
padding: const EdgeInsets.only(left: 8.0, bottom: 4), style: TextStyle(
child: ownMessage || event.room.isDirectChat fontSize: 12,
? const SizedBox(height: 12) fontWeight: FontWeight.bold,
: FutureBuilder<User?>( color: (Theme.of(context).brightness ==
future: event.fetchSenderUser(), Brightness.light
builder: (context, snapshot) { ? displayname.color
final displayname = : displayname.lightColorText),
snapshot.data?.calcDisplayname() ?? ),
event.senderFromMemoryOrFallback );
.calcDisplayname(); },
return Text( ),
displayname, ),
style: TextStyle( Container(
fontSize: 12, alignment: alignment,
fontWeight: FontWeight.bold, padding: const EdgeInsets.only(left: 8),
color: (Theme.of(context).brightness == child: Material(
Brightness.light color: noBubble ? Colors.transparent : color,
? displayname.color
: displayname.lightColorText),
),
);
},
),
),
Container(
alignment: alignment,
padding: const EdgeInsets.only(left: 8),
child: Material(
color: noBubble ? Colors.transparent : color,
borderRadius: borderRadius,
clipBehavior: Clip.antiAlias,
child: InkWell(
onHover: (b) => useMouse = true,
onTap: !useMouse && longPressSelect
? () {}
: () => onSelect!(event),
onLongPress: !longPressSelect ? null : () => onSelect!(event),
borderRadius: borderRadius, borderRadius: borderRadius,
clipBehavior: Clip.antiAlias,
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: borderRadius:
@ -292,15 +289,10 @@ class Message extends StatelessWidget {
), ),
), ),
), ),
), ],
], ),
), ),
), ],
];
final row = Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: rowMainAxisAlignment,
children: rowChildren,
); );
Widget container; Widget container;
if (event.hasAggregatedEvents(timeline, RelationshipTypes.reaction) || if (event.hasAggregatedEvents(timeline, RelationshipTypes.reaction) ||
@ -400,17 +392,26 @@ class Message extends StatelessWidget {
direction: SwipeDirection.endToStart, direction: SwipeDirection.endToStart,
onSwipe: onSwipe, onSwipe: onSwipe,
child: Center( child: Center(
child: Container( child: MouseRegion(
color: selected onEnter: (_) => useMouse = true,
? Theme.of(context).primaryColor.withAlpha(100) onExit: (_) => useMouse = false,
: Theme.of(context).primaryColor.withAlpha(0), child: InkWell(
constraints: onTap: longPressSelect || useMouse ? () => onSelect!(event) : null,
const BoxConstraints(maxWidth: FluffyThemes.columnWidth * 2.5), onLongPress: () => onSelect!(event),
padding: const EdgeInsets.symmetric( child: Container(
horizontal: 8.0, color: selected
vertical: 4.0, ? Theme.of(context).primaryColor.withAlpha(100)
: Theme.of(context).primaryColor.withAlpha(0),
constraints: const BoxConstraints(
maxWidth: FluffyThemes.columnWidth * 2.5,
),
padding: const EdgeInsets.symmetric(
horizontal: 8.0,
vertical: 4.0,
),
child: container,
),
), ),
child: container,
), ),
), ),
); );