Fix top list

This commit is contained in:
Christian Pauly 2020-06-19 15:10:26 +02:00
parent 0b22e9ea82
commit bcda0bbd5f
6 changed files with 65 additions and 72 deletions

View File

@ -34,15 +34,6 @@ class PresenceDialog extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Text(presence.getLocalizedStatusMessage(context)), Text(presence.getLocalizedStatusMessage(context)),
if (presence.presence != null)
Text(
presence.presence.toString().split('.').last,
style: TextStyle(
color: presence.presence.currentlyActive == true
? Colors.green
: Theme.of(context).primaryColor,
),
)
], ],
), ),
actions: <Widget>[ actions: <Widget>[

View File

@ -1,15 +1,15 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/dialogs/presence_dialog.dart';
import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat.dart'; import 'package:fluffychat/views/chat.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../utils/client_presence_extension.dart';
import '../avatar.dart'; import '../avatar.dart';
import '../matrix.dart'; import '../matrix.dart';
class PresenceListItem extends StatelessWidget { class PresenceListItem extends StatelessWidget {
final Presence presence; final Room room;
const PresenceListItem(this.presence); const PresenceListItem(this.room);
void _startChatAction(BuildContext context, String userId) async { void _startChatAction(BuildContext context, String userId) async {
final roomId = await User(userId, final roomId = await User(userId,
@ -25,37 +25,42 @@ class PresenceListItem extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FutureBuilder<Profile>( final user = room.getUserByMXIDSync(room.directChatMatrixID);
future: final presence =
Matrix.of(context).client.requestProfileCached(presence.senderId), Matrix.of(context).client.presences[room.directChatMatrixID];
builder: (context, snapshot) {
Uri avatarUrl;
var displayname = presence.senderId.localpart;
if (snapshot.hasData) {
avatarUrl = snapshot.data.avatarUrl;
displayname =
snapshot.data.displayname ?? presence.senderId.localpart;
}
return InkWell( return InkWell(
onTap: () => _startChatAction(context, presence.senderId), onTap: () => presence?.presence?.statusMsg == null
? _startChatAction(context, user.id)
: showDialog(
context: context,
builder: (_) => PresenceDialog(
presence,
avatarUrl: user.avatarUrl,
displayname: user.calcDisplayname(),
),
),
child: Container( child: Container(
width: 80, width: 80,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
SizedBox(height: 9), SizedBox(height: 9),
Avatar(avatarUrl, displayname), Avatar(user.avatarUrl, user.calcDisplayname()),
Padding( Padding(
padding: const EdgeInsets.all(6.0), padding: const EdgeInsets.all(6.0),
child: Text( child: Text(
displayname, user.calcDisplayname(),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
maxLines: 1, maxLines: 1,
style: TextStyle(
fontWeight: presence?.presence?.statusMsg == null
? null
: FontWeight.bold,
),
), ),
), ),
], ],
), ),
), ),
); );
});
} }
} }

View File

@ -1,16 +1,6 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
extension ClientPresenceExtension on Client { extension ClientPresenceExtension on Client {
List<Presence> get statusList {
final statusList = presences.values.toList().reversed.toList();
final directRooms = rooms.where((r) => r.isDirectChat).toList();
statusList.removeWhere((p) =>
directRooms.indexWhere((r) => r.directChatMatrixID == p.senderId) ==
-1);
statusList.reversed.toList();
return statusList;
}
static final Map<String, Profile> presencesCache = {}; static final Map<String, Profile> presencesCache = {};
Future<Profile> requestProfileCached(String senderId) async { Future<Profile> requestProfileCached(String senderId) async {

View File

@ -8,8 +8,11 @@ extension PresenceExtension on Presence {
if (presence.statusMsg?.isNotEmpty ?? false) { if (presence.statusMsg?.isNotEmpty ?? false) {
return presence.statusMsg; return presence.statusMsg;
} }
if (presence.lastActiveAgo != null) {
return L10n.of(context).lastActiveAgo( return L10n.of(context).lastActiveAgo(
DateTime.fromMillisecondsSinceEpoch(presence.lastActiveAgo) DateTime.fromMillisecondsSinceEpoch(presence.lastActiveAgo)
.localizedTimeShort(context)); .localizedTimeShort(context));
} }
return L10n.of(context).lastSeenLongTimeAgo;
}
} }

View File

@ -9,7 +9,10 @@ extension RoomStatusExtension on Room {
String getLocalizedStatus(BuildContext context) { String getLocalizedStatus(BuildContext context) {
if (isDirectChat) { if (isDirectChat) {
if (directChatPresence != null) { if (directChatPresence != null &&
directChatPresence.presence != null &&
(directChatPresence.presence.lastActiveAgo != null ||
directChatPresence.presence.currentlyActive != null)) {
if (directChatPresence.presence.currentlyActive == true) { if (directChatPresence.presence.currentlyActive == true) {
return L10n.of(context).currentlyActive; return L10n.of(context).currentlyActive;
} }

View File

@ -19,7 +19,6 @@ import '../components/matrix.dart';
import '../l10n/l10n.dart'; import '../l10n/l10n.dart';
import '../utils/app_route.dart'; import '../utils/app_route.dart';
import '../utils/url_launcher.dart'; import '../utils/url_launcher.dart';
import '../utils/client_presence_extension.dart';
import 'archive.dart'; import 'archive.dart';
import 'homeserver_picker.dart'; import 'homeserver_picker.dart';
import 'new_group.dart'; import 'new_group.dart';
@ -436,6 +435,16 @@ class _ChatListState extends State<ChatList> {
(publicRoomsResponse?.chunk?.length ?? 0); (publicRoomsResponse?.chunk?.length ?? 0);
final totalCount = final totalCount =
rooms.length + publicRoomsCount; rooms.length + publicRoomsCount;
final directChats =
rooms.where((r) => r.isDirectChat).toList();
directChats.sort((a, b) => Matrix.of(context)
.client
.presences[b.directChatMatrixID]
?.presence
?.statusMsg !=
null
? 1
: -1);
return ListView.separated( return ListView.separated(
controller: _scrollController, controller: _scrollController,
separatorBuilder: separatorBuilder:
@ -452,10 +461,7 @@ class _ChatListState extends State<ChatList> {
itemCount: totalCount + 1, itemCount: totalCount + 1,
itemBuilder: (BuildContext context, int i) { itemBuilder: (BuildContext context, int i) {
if (i == 0) { if (i == 0) {
return (Matrix.of(context) return (directChats.isEmpty ||
.client
.statusList
.isEmpty ||
selectMode == SelectMode.share) selectMode == SelectMode.share)
? Container() ? Container()
: PreferredSize( : PreferredSize(
@ -466,17 +472,12 @@ class _ChatListState extends State<ChatList> {
child: ListView.builder( child: ListView.builder(
scrollDirection: scrollDirection:
Axis.horizontal, Axis.horizontal,
itemCount: Matrix.of(context) itemCount: directChats.length,
.client itemBuilder:
.statusList (BuildContext context,
.length,
itemBuilder: (BuildContext
context,
int i) => int i) =>
PresenceListItem( PresenceListItem(
Matrix.of(context) directChats[i]),
.client
.statusList[i]),
), ),
), ),
); );