feat: Implement new status feature
parent
0f056a4b86
commit
c5d84c22ca
@ -1,63 +0,0 @@
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/utils/presence_extension.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';
|
||||
|
||||
class PresenceDialog extends StatelessWidget {
|
||||
final Uri avatarUrl;
|
||||
final String displayname;
|
||||
final Presence presence;
|
||||
|
||||
const PresenceDialog(
|
||||
this.presence, {
|
||||
this.avatarUrl,
|
||||
this.displayname,
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Avatar(avatarUrl, displayname),
|
||||
title: Text(displayname),
|
||||
subtitle: Text(presence.senderId),
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(presence.getLocalizedStatusMessage(context)),
|
||||
],
|
||||
),
|
||||
actions: <Widget>[
|
||||
if (presence.senderId != Matrix.of(context).client.userID)
|
||||
FlatButton(
|
||||
child: Text(L10n.of(context).sendAMessage),
|
||||
onPressed: () async {
|
||||
final roomId = await User(
|
||||
presence.senderId,
|
||||
room: Room(id: '', client: Matrix.of(context).client),
|
||||
).startDirectChat();
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatView(roomId),
|
||||
),
|
||||
(Route r) => r.isFirst);
|
||||
},
|
||||
),
|
||||
FlatButton(
|
||||
child: Text(L10n.of(context).close),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/views/chat.dart';
|
||||
import 'package:fluffychat/views/presence_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../avatar.dart';
|
||||
import '../matrix.dart';
|
||||
|
||||
class PresenceListItem extends StatelessWidget {
|
||||
final Room room;
|
||||
|
||||
const PresenceListItem(this.room);
|
||||
|
||||
void _startChatAction(BuildContext context, String userId) async {
|
||||
final roomId = await User(userId,
|
||||
room: Room(client: Matrix.of(context).client, id: ''))
|
||||
.startDirectChat();
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatView(roomId),
|
||||
),
|
||||
(Route r) => r.isFirst);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final user = room.getUserByMXIDSync(room.directChatMatrixID);
|
||||
final presence =
|
||||
Matrix.of(context).client.presences[room.directChatMatrixID];
|
||||
final hasStatus = presence?.presence?.statusMsg != null;
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: () => presence?.presence?.statusMsg == null
|
||||
? _startChatAction(context, user.id)
|
||||
: /*showDialog(
|
||||
context: context,
|
||||
builder: (_) => PresenceDialog(
|
||||
presence,
|
||||
avatarUrl: user.avatarUrl,
|
||||
displayname: user.calcDisplayname(),
|
||||
),
|
||||
),*/
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => PresenceView(
|
||||
presence: presence,
|
||||
avatarUrl: user.avatarUrl,
|
||||
displayname: user.calcDisplayname(),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Container(
|
||||
width: 76,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
SizedBox(height: 10),
|
||||
Container(
|
||||
child: Stack(
|
||||
children: [
|
||||
Avatar(user.avatarUrl, user.calcDisplayname()),
|
||||
if (presence?.presence?.currentlyActive == true)
|
||||
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: !hasStatus
|
||||
? Theme.of(context).secondaryHeaderColor
|
||||
: 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(
|
||||
user.calcDisplayname().trim().split(' ').first,
|
||||
overflow: TextOverflow.clip,
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyText2
|
||||
.color
|
||||
.withOpacity(hasStatus ? 1 : 0.66),
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
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(client.userID, Uri.parse(''));
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
@ -1,10 +1,7 @@
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
|
||||
extension ClientPresenceExtension on Client {
|
||||
static final Map<String, Profile> presencesCache = {};
|
||||
|
||||
Future<Profile> requestProfileCached(String senderId) async {
|
||||
presencesCache[senderId] ??= await getProfileFromUserId(senderId);
|
||||
return presencesCache[senderId];
|
||||
}
|
||||
List<Presence> get statuses => presences.values
|
||||
.where((p) => p.presence.statusMsg?.isNotEmpty ?? false)
|
||||
.toList();
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue