More features

This commit is contained in:
Christian Pauly 2020-01-05 11:27:03 +00:00 committed by Marcel
commit f1079e5c70
13 changed files with 503 additions and 156 deletions

52
lib/views/archive.dart Normal file
View file

@ -0,0 +1,52 @@
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/list_items/chat_list_item.dart';
import 'package:fluffychat/components/matrix.dart';
import 'package:flutter/material.dart';
class Archive extends StatefulWidget {
@override
_ArchiveState createState() => _ArchiveState();
}
class _ArchiveState extends State<Archive> {
List<Room> archive;
Future<List<Room>> getArchive(BuildContext context) async {
if (archive != null) return archive;
return await Matrix.of(context).client.archive;
}
@override
Widget build(BuildContext context) {
return AdaptivePageLayout(
firstScaffold: Scaffold(
appBar: AppBar(
title: Text("Archive"),
),
body: FutureBuilder<List<Room>>(
future: getArchive(context),
builder: (BuildContext context, snapshot) {
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
} else {
archive = snapshot.data;
return ListView.builder(
itemCount: archive.length,
itemBuilder: (BuildContext context, int i) => ChatListItem(
archive[i],
onForget: () => setState(() => archive = null)),
);
}
},
),
),
secondScaffold: Scaffold(
body: Center(
child: Image.asset("assets/logo.png", width: 100, height: 100),
),
),
primaryPage: FocusPage.FIRST,
);
}
}

View file

@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'package:famedlysdk/famedlysdk.dart';
@ -26,8 +27,14 @@ class _ChatState extends State<Chat> {
Timeline timeline;
String seenByText = "";
final ScrollController _scrollController = ScrollController();
Timer typingCoolDown;
Timer typingTimeout;
bool currentlyTyping = false;
@override
void initState() {
_scrollController.addListener(() async {
@ -43,10 +50,31 @@ class _ChatState extends State<Chat> {
super.initState();
}
Future<bool> getTimeline() async {
timeline ??= await room.getTimeline(onUpdate: () {
setState(() {});
void updateView() {
String seenByText = "";
if (timeline.events.isNotEmpty) {
List lastReceipts = List.from(timeline.events.first.receipts);
lastReceipts.removeWhere((r) =>
r.user.id == room.client.userID ||
r.user.id == timeline.events.first.senderId);
if (lastReceipts.length == 1) {
seenByText = "Seen by ${lastReceipts.first.user.calcDisplayname()}";
} else if (lastReceipts.length == 2) {
seenByText =
"Seen by ${lastReceipts.first.user.calcDisplayname()} and ${lastReceipts[1].user.calcDisplayname()}";
} else if (lastReceipts.length > 2) {
seenByText =
"Seen by ${lastReceipts.first.user.calcDisplayname()} and ${lastReceipts.length - 1} others";
}
}
setState(() {
this.seenByText = seenByText;
});
}
Future<bool> getTimeline() async {
timeline ??= await room.getTimeline(onUpdate: updateView);
updateView();
return true;
}
@ -115,8 +143,29 @@ class _ChatState extends State<Chat> {
Widget build(BuildContext context) {
Client client = Matrix.of(context).client;
room ??= client.getRoomById(widget.id);
if (room == null) {
return Center(
child: Text("You are no longer participating in this chat"),
);
}
if (room.membership == Membership.invite) room.join();
if (room.membership == Membership.invite) {
Matrix.of(context).tryRequestWithLoadingDialog(room.join());
}
String typingText = "";
List<User> typingUsers = room.typingUsers;
typingUsers.removeWhere((User u) => u.id == client.userID);
if (typingUsers.length == 1) {
typingText = "${typingUsers.first.calcDisplayname()} is typing...";
} else if (typingUsers.length == 2) {
typingText =
"${typingUsers.first.calcDisplayname()} and ${typingUsers[1].calcDisplayname()} are typing...";
} else if (typingUsers.length > 2) {
typingText =
"${typingUsers.first.calcDisplayname()} and ${typingUsers.length - 1} others are typing...";
}
return AdaptivePageLayout(
primaryPage: FocusPage.SECOND,
@ -125,7 +174,33 @@ class _ChatState extends State<Chat> {
),
secondScaffold: Scaffold(
appBar: AppBar(
title: Text(room.displayname),
title: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(room.displayname),
AnimatedContainer(
duration: Duration(milliseconds: 500),
height: typingText.isEmpty ? 0 : 20,
child: Row(
children: <Widget>[
typingText.isEmpty
? Container()
: Icon(Icons.edit,
color: Theme.of(context).primaryColor, size: 10),
SizedBox(width: 4),
Text(
typingText,
style: TextStyle(
color: Theme.of(context).primaryColor,
fontStyle: FontStyle.italic,
),
),
],
),
),
],
),
actions: <Widget>[ChatSettingsPopupMenu(room, !room.isDirectChat)],
),
body: SafeArea(
@ -140,6 +215,7 @@ class _ChatState extends State<Chat> {
child: CircularProgressIndicator(),
);
}
if (room.notificationCount != null &&
room.notificationCount > 0 &&
timeline != null &&
@ -148,92 +224,138 @@ class _ChatState extends State<Chat> {
}
return ListView.builder(
reverse: true,
itemCount: timeline.events.length,
itemCount: timeline.events.length + 1,
controller: _scrollController,
itemBuilder: (BuildContext context, int i) =>
Message(timeline.events[i]),
itemBuilder: (BuildContext context, int i) => i == 0
? AnimatedContainer(
height: seenByText.isEmpty ? 0 : 36,
duration: seenByText.isEmpty
? Duration(milliseconds: 0)
: Duration(milliseconds: 500),
alignment: timeline.events.first.senderId ==
client.userID
? Alignment.centerRight
: Alignment.centerLeft,
child: Text(
seenByText,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Theme.of(context).primaryColor,
),
),
padding: EdgeInsets.all(8),
)
: Message(timeline.events[i - 1]),
);
},
),
),
Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 2,
offset: Offset(0, -1), // changes position of shadow
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
kIsWeb
? Container()
: PopupMenuButton<String>(
icon: Icon(Icons.add),
onSelected: (String choice) async {
if (choice == "file") {
sendFileAction(context);
} else if (choice == "image") {
sendImageAction(context);
}
if (choice == "camera") openCameraAction(context);
},
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: "file",
child: ListTile(
leading: Icon(Icons.attach_file),
title: Text('Send file'),
contentPadding: EdgeInsets.all(0),
),
),
const PopupMenuItem<String>(
value: "image",
child: ListTile(
leading: Icon(Icons.image),
title: Text('Send image'),
contentPadding: EdgeInsets.all(0),
),
),
const PopupMenuItem<String>(
value: "camera",
child: ListTile(
leading: Icon(Icons.camera),
title: Text('Open camera'),
contentPadding: EdgeInsets.all(0),
),
),
],
room.canSendDefaultMessages && room.membership == Membership.join
? Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 2,
offset: Offset(0, -1), // changes position of shadow
),
SizedBox(width: 8),
Expanded(
child: TextField(
minLines: 1,
maxLines: kIsWeb ? 1 : null,
keyboardType:
kIsWeb ? TextInputType.text : TextInputType.multiline,
onSubmitted: (t) => send(),
controller: sendController,
decoration: InputDecoration(
labelText: "Write a message...",
hintText: "You're message",
border: InputBorder.none,
],
),
)),
SizedBox(width: 8),
IconButton(
icon: Icon(Icons.send),
onPressed: () => send(),
),
],
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
kIsWeb
? Container()
: PopupMenuButton<String>(
icon: Icon(Icons.add),
onSelected: (String choice) async {
if (choice == "file") {
sendFileAction(context);
} else if (choice == "image") {
sendImageAction(context);
}
if (choice == "camera") {
openCameraAction(context);
}
},
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: "file",
child: ListTile(
leading: Icon(Icons.attach_file),
title: Text('Send file'),
contentPadding: EdgeInsets.all(0),
),
),
const PopupMenuItem<String>(
value: "image",
child: ListTile(
leading: Icon(Icons.image),
title: Text('Send image'),
contentPadding: EdgeInsets.all(0),
),
),
const PopupMenuItem<String>(
value: "camera",
child: ListTile(
leading: Icon(Icons.camera),
title: Text('Open camera'),
contentPadding: EdgeInsets.all(0),
),
),
],
),
SizedBox(width: 8),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: TextField(
minLines: 1,
maxLines: kIsWeb ? 1 : null,
keyboardType: kIsWeb
? TextInputType.text
: TextInputType.multiline,
onSubmitted: (t) => send(),
controller: sendController,
decoration: InputDecoration(
hintText: "Write a message...",
border: InputBorder.none,
),
onChanged: (String text) {
this.typingCoolDown?.cancel();
this.typingCoolDown =
Timer(Duration(seconds: 2), () {
this.typingCoolDown = null;
this.currentlyTyping = false;
room.sendTypingInfo(false);
});
this.typingTimeout ??=
Timer(Duration(seconds: 30), () {
this.typingTimeout = null;
this.currentlyTyping = false;
});
if (!this.currentlyTyping) {
this.currentlyTyping = true;
room.sendTypingInfo(true,
timeout:
Duration(seconds: 30).inMilliseconds);
}
},
),
)),
SizedBox(width: 8),
IconButton(
icon: Icon(Icons.send),
onPressed: () => send(),
),
],
),
)
: Container(),
],
),
),

View file

@ -81,6 +81,11 @@ class _ChatDetailsState extends State<ChatDetails> {
@override
Widget build(BuildContext context) {
if (widget.room == null) {
return Center(
child: Text("You are no longer participating in this chat"),
);
}
members ??= widget.room.getParticipants();
final int actualMembersCount =
widget.room.mInvitedMemberCount + widget.room.mJoinedMemberCount;
@ -127,28 +132,17 @@ class _ChatDetailsState extends State<ChatDetails> {
),
)
: Container(),
Row(
children: <Widget>[
Expanded(
child: Container(
height: 8,
color: Theme.of(context).secondaryHeaderColor),
ListTile(
title: Text(
"$actualMembersCount participant" +
(actualMembersCount > 1 ? "s:" : ":"),
style: TextStyle(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.bold,
),
SizedBox(width: 8),
Text(
"$actualMembersCount participant(s)",
style: TextStyle(
fontSize: 15,
),
),
SizedBox(width: 8),
Expanded(
child: Container(
height: 8,
color: Theme.of(context).secondaryHeaderColor),
),
],
),
),
Divider(height: 1),
widget.room.canInvite
? ListTile(
title: Text("Invite contact"),

View file

@ -7,6 +7,7 @@ import 'package:fluffychat/components/dialogs/new_private_chat_dialog.dart';
import 'package:fluffychat/components/list_items/chat_list_item.dart';
import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/archive.dart';
import 'package:fluffychat/views/settings.dart';
import 'package:flutter/material.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
@ -100,16 +101,31 @@ class _ChatListState extends State<ChatList> {
onSelected: (String choice) {
switch (choice) {
case "settings":
Navigator.of(context).push(
Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(
context,
SettingsView(),
),
(r) => r.isFirst,
);
break;
case "archive":
Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(
context,
Archive(),
),
(r) => r.isFirst,
);
break;
}
},
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: "archive",
child: Text('Archive'),
),
const PopupMenuItem<String>(
value: "settings",
child: Text('Settings'),