Redesign
This commit is contained in:
parent
f2b0cce282
commit
cc61d8e91a
|
@ -1,3 +1,10 @@
|
||||||
|
# Version 0.5.1 - 2020-MM-DD
|
||||||
|
### New features
|
||||||
|
- Refactoring under the hood
|
||||||
|
### Fixes
|
||||||
|
- Fixed the bug that when revoking permissions for a user makes the user an admin
|
||||||
|
- Fixed the Kick user when user has already left the group
|
||||||
|
|
||||||
# Version 0.5.0 - 2020-01-20
|
# Version 0.5.0 - 2020-01-20
|
||||||
### New features
|
### New features
|
||||||
- Localizations
|
- Localizations
|
||||||
|
|
|
@ -37,7 +37,7 @@ class _NewGroupDialogState extends State<NewGroupDialog> {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) {
|
MaterialPageRoute(builder: (context) {
|
||||||
return Chat(roomID);
|
return ChatView(roomID);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -42,7 +42,7 @@ class _NewPrivateChatDialogState extends State<NewPrivateChatDialog> {
|
||||||
if (roomID != null) {
|
if (roomID != null) {
|
||||||
await Navigator.push(
|
await Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => Chat(roomID)),
|
MaterialPageRoute(builder: (context) => ChatView(roomID)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ class ChatListItem extends StatelessWidget {
|
||||||
}
|
}
|
||||||
await Navigator.pushAndRemoveUntil(
|
await Navigator.pushAndRemoveUntil(
|
||||||
context,
|
context,
|
||||||
AppRoute.defaultRoute(context, Chat(room.id)),
|
AppRoute.defaultRoute(context, ChatView(room.id)),
|
||||||
(r) => r.isFirst,
|
(r) => r.isFirst,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ class ParticipantListItem extends StatelessWidget {
|
||||||
await Navigator.of(context).pushAndRemoveUntil(
|
await Navigator.of(context).pushAndRemoveUntil(
|
||||||
AppRoute.defaultRoute(
|
AppRoute.defaultRoute(
|
||||||
context,
|
context,
|
||||||
Chat(roomId),
|
ChatView(roomId),
|
||||||
),
|
),
|
||||||
(Route r) => r.isFirst);
|
(Route r) => r.isFirst);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -153,7 +153,7 @@ class MatrixState extends State<Matrix> {
|
||||||
await Navigator.of(context).pushAndRemoveUntil(
|
await Navigator.of(context).pushAndRemoveUntil(
|
||||||
AppRoute.defaultRoute(
|
AppRoute.defaultRoute(
|
||||||
context,
|
context,
|
||||||
Chat(roomId),
|
ChatView(roomId),
|
||||||
),
|
),
|
||||||
(r) => r.isFirst);
|
(r) => r.isFirst);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ class UrlLauncher {
|
||||||
if (response == false) return;
|
if (response == false) return;
|
||||||
await Navigator.pushAndRemoveUntil(
|
await Navigator.pushAndRemoveUntil(
|
||||||
context,
|
context,
|
||||||
AppRoute.defaultRoute(context, Chat(response["room_id"])),
|
AppRoute.defaultRoute(context, ChatView(response["room_id"])),
|
||||||
(r) => r.isFirst,
|
(r) => r.isFirst,
|
||||||
);
|
);
|
||||||
} else if (identifier.substring(0, 1) == "@") {
|
} else if (identifier.substring(0, 1) == "@") {
|
||||||
|
@ -44,7 +44,7 @@ class UrlLauncher {
|
||||||
if (roomID != null) {
|
if (roomID != null) {
|
||||||
await Navigator.push(
|
await Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => Chat(roomID)),
|
MaterialPageRoute(builder: (context) => ChatView(roomID)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,16 +17,34 @@ import 'package:pedantic/pedantic.dart';
|
||||||
|
|
||||||
import 'chat_list.dart';
|
import 'chat_list.dart';
|
||||||
|
|
||||||
class Chat extends StatefulWidget {
|
class ChatView extends StatelessWidget {
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
const Chat(this.id, {Key key}) : super(key: key);
|
const ChatView(this.id, {Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
// TODO: implement build
|
||||||
|
return AdaptivePageLayout(
|
||||||
|
primaryPage: FocusPage.SECOND,
|
||||||
|
firstScaffold: ChatList(
|
||||||
|
activeChat: id,
|
||||||
|
),
|
||||||
|
secondScaffold: _Chat(id),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _Chat extends StatefulWidget {
|
||||||
|
final String id;
|
||||||
|
|
||||||
|
const _Chat(this.id, {Key key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_ChatState createState() => _ChatState();
|
_ChatState createState() => _ChatState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ChatState extends State<Chat> {
|
class _ChatState extends State<_Chat> {
|
||||||
Room room;
|
Room room;
|
||||||
|
|
||||||
Timeline timeline;
|
Timeline timeline;
|
||||||
|
@ -202,224 +220,217 @@ class _ChatState extends State<Chat> {
|
||||||
(typingUsers.length - 1).toString());
|
(typingUsers.length - 1).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return AdaptivePageLayout(
|
return Scaffold(
|
||||||
primaryPage: FocusPage.SECOND,
|
appBar: AppBar(
|
||||||
firstScaffold: ChatList(
|
title: Column(
|
||||||
activeChat: widget.id,
|
mainAxisSize: MainAxisSize.min,
|
||||||
),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
secondScaffold: Scaffold(
|
children: <Widget>[
|
||||||
appBar: AppBar(
|
Text(room.getLocalizedDisplayname(context)),
|
||||||
title: Column(
|
AnimatedContainer(
|
||||||
mainAxisSize: MainAxisSize.min,
|
duration: Duration(milliseconds: 500),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
height: typingText.isEmpty ? 0 : 20,
|
||||||
children: <Widget>[
|
child: Row(
|
||||||
Text(room.getLocalizedDisplayname(context)),
|
children: <Widget>[
|
||||||
AnimatedContainer(
|
typingText.isEmpty
|
||||||
duration: Duration(milliseconds: 500),
|
? Container()
|
||||||
height: typingText.isEmpty ? 0 : 20,
|
: Icon(Icons.edit,
|
||||||
child: Row(
|
color: Theme.of(context).primaryColor, size: 10),
|
||||||
children: <Widget>[
|
SizedBox(width: 4),
|
||||||
typingText.isEmpty
|
Text(
|
||||||
? Container()
|
typingText,
|
||||||
: Icon(Icons.edit,
|
style: TextStyle(
|
||||||
color: Theme.of(context).primaryColor, size: 10),
|
color: Theme.of(context).primaryColor,
|
||||||
SizedBox(width: 4),
|
fontStyle: FontStyle.italic,
|
||||||
Text(
|
|
||||||
typingText,
|
|
||||||
style: TextStyle(
|
|
||||||
color: Theme.of(context).primaryColor,
|
|
||||||
fontStyle: FontStyle.italic,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
actions: <Widget>[ChatSettingsPopupMenu(room, !room.isDirectChat)],
|
|
||||||
),
|
),
|
||||||
body: SafeArea(
|
actions: <Widget>[ChatSettingsPopupMenu(room, !room.isDirectChat)],
|
||||||
child: Column(
|
),
|
||||||
children: <Widget>[
|
body: SafeArea(
|
||||||
Expanded(
|
child: Column(
|
||||||
child: FutureBuilder<bool>(
|
children: <Widget>[
|
||||||
future: getTimeline(),
|
Expanded(
|
||||||
builder: (BuildContext context, snapshot) {
|
child: FutureBuilder<bool>(
|
||||||
if (!snapshot.hasData) {
|
future: getTimeline(),
|
||||||
return Center(
|
builder: (BuildContext context, snapshot) {
|
||||||
child: CircularProgressIndicator(),
|
if (!snapshot.hasData) {
|
||||||
);
|
return Center(
|
||||||
}
|
child: CircularProgressIndicator(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (room.notificationCount != null &&
|
if (room.notificationCount != null &&
|
||||||
room.notificationCount > 0 &&
|
room.notificationCount > 0 &&
|
||||||
timeline != null &&
|
timeline != null &&
|
||||||
timeline.events.isNotEmpty) {
|
timeline.events.isNotEmpty) {
|
||||||
room.sendReadReceipt(timeline.events.first.eventId);
|
room.sendReadReceipt(timeline.events.first.eventId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeline.events.isEmpty) return Container();
|
if (timeline.events.isEmpty) return Container();
|
||||||
|
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
reverse: true,
|
reverse: true,
|
||||||
itemCount: timeline.events.length + 1,
|
itemCount: timeline.events.length + 1,
|
||||||
controller: _scrollController,
|
controller: _scrollController,
|
||||||
itemBuilder: (BuildContext context, int i) {
|
itemBuilder: (BuildContext context, int i) {
|
||||||
return i == 0
|
return i == 0
|
||||||
? AnimatedContainer(
|
? AnimatedContainer(
|
||||||
height: seenByText.isEmpty ? 0 : 24,
|
height: seenByText.isEmpty ? 0 : 24,
|
||||||
duration: seenByText.isEmpty
|
duration: seenByText.isEmpty
|
||||||
? Duration(milliseconds: 0)
|
? Duration(milliseconds: 0)
|
||||||
: Duration(milliseconds: 500),
|
: Duration(milliseconds: 500),
|
||||||
alignment: timeline.events.first.senderId ==
|
alignment: timeline.events.first.senderId ==
|
||||||
client.userID
|
client.userID
|
||||||
? Alignment.topRight
|
? Alignment.topRight
|
||||||
: Alignment.topLeft,
|
: Alignment.topLeft,
|
||||||
child: Text(
|
child: Text(
|
||||||
seenByText,
|
seenByText,
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Theme.of(context).primaryColor,
|
color: Theme.of(context).primaryColor,
|
||||||
),
|
|
||||||
),
|
),
|
||||||
padding: EdgeInsets.only(
|
|
||||||
left: 8,
|
|
||||||
right: 8,
|
|
||||||
bottom: 8,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: Message(timeline.events[i - 1],
|
|
||||||
nextEvent:
|
|
||||||
i >= 2 ? timeline.events[i - 2] : null);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
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
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
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>>[
|
|
||||||
PopupMenuItem<String>(
|
|
||||||
value: "file",
|
|
||||||
child: ListTile(
|
|
||||||
leading: CircleAvatar(
|
|
||||||
backgroundColor: Colors.green,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
child: Icon(Icons.attachment),
|
|
||||||
),
|
|
||||||
title: Text(I18n.of(context).sendFile),
|
|
||||||
contentPadding: EdgeInsets.all(0),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
PopupMenuItem<String>(
|
|
||||||
value: "image",
|
|
||||||
child: ListTile(
|
|
||||||
leading: CircleAvatar(
|
|
||||||
backgroundColor: Colors.blue,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
child: Icon(Icons.image),
|
|
||||||
),
|
|
||||||
title: Text(I18n.of(context).sendImage),
|
|
||||||
contentPadding: EdgeInsets.all(0),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
PopupMenuItem<String>(
|
|
||||||
value: "camera",
|
|
||||||
child: ListTile(
|
|
||||||
leading: CircleAvatar(
|
|
||||||
backgroundColor: Colors.purple,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
child: Icon(Icons.camera),
|
|
||||||
),
|
|
||||||
title:
|
|
||||||
Text(I18n.of(context).openCamera),
|
|
||||||
contentPadding: EdgeInsets.all(0),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
SizedBox(width: 8),
|
padding: EdgeInsets.only(
|
||||||
Expanded(
|
left: 8,
|
||||||
child: Padding(
|
right: 8,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
bottom: 8,
|
||||||
child: TextField(
|
),
|
||||||
minLines: 1,
|
)
|
||||||
maxLines: kIsWeb ? 1 : 8,
|
: Message(timeline.events[i - 1],
|
||||||
keyboardType: kIsWeb
|
nextEvent:
|
||||||
? TextInputType.text
|
i >= 2 ? timeline.events[i - 2] : null);
|
||||||
: TextInputType.multiline,
|
});
|
||||||
onSubmitted: (String text) {
|
},
|
||||||
send();
|
),
|
||||||
FocusScope.of(context).requestFocus(inputFocus);
|
),
|
||||||
},
|
room.canSendDefaultMessages && room.membership == Membership.join
|
||||||
focusNode: inputFocus,
|
? Container(
|
||||||
controller: sendController,
|
decoration: BoxDecoration(
|
||||||
decoration: InputDecoration(
|
color: Colors.white,
|
||||||
hintText: I18n.of(context).writeAMessage,
|
boxShadow: [
|
||||||
border: InputBorder.none,
|
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>>[
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: "file",
|
||||||
|
child: ListTile(
|
||||||
|
leading: CircleAvatar(
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
child: Icon(Icons.attachment),
|
||||||
|
),
|
||||||
|
title: Text(I18n.of(context).sendFile),
|
||||||
|
contentPadding: EdgeInsets.all(0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: "image",
|
||||||
|
child: ListTile(
|
||||||
|
leading: CircleAvatar(
|
||||||
|
backgroundColor: Colors.blue,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
child: Icon(Icons.image),
|
||||||
|
),
|
||||||
|
title: Text(I18n.of(context).sendImage),
|
||||||
|
contentPadding: EdgeInsets.all(0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: "camera",
|
||||||
|
child: ListTile(
|
||||||
|
leading: CircleAvatar(
|
||||||
|
backgroundColor: Colors.purple,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
child: Icon(Icons.camera),
|
||||||
|
),
|
||||||
|
title: Text(I18n.of(context).openCamera),
|
||||||
|
contentPadding: EdgeInsets.all(0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
onChanged: (String text) {
|
SizedBox(width: 8),
|
||||||
this.typingCoolDown?.cancel();
|
Expanded(
|
||||||
this.typingCoolDown =
|
child: Padding(
|
||||||
Timer(Duration(seconds: 2), () {
|
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
||||||
this.typingCoolDown = null;
|
child: TextField(
|
||||||
this.currentlyTyping = false;
|
minLines: 1,
|
||||||
room.sendTypingInfo(false);
|
maxLines: kIsWeb ? 1 : 8,
|
||||||
});
|
keyboardType: kIsWeb
|
||||||
this.typingTimeout ??=
|
? TextInputType.text
|
||||||
Timer(Duration(seconds: 30), () {
|
: TextInputType.multiline,
|
||||||
this.typingTimeout = null;
|
onSubmitted: (String text) {
|
||||||
this.currentlyTyping = false;
|
send();
|
||||||
});
|
FocusScope.of(context).requestFocus(inputFocus);
|
||||||
if (!this.currentlyTyping) {
|
},
|
||||||
this.currentlyTyping = true;
|
focusNode: inputFocus,
|
||||||
room.sendTypingInfo(true,
|
controller: sendController,
|
||||||
timeout:
|
decoration: InputDecoration(
|
||||||
Duration(seconds: 30).inMilliseconds);
|
hintText: I18n.of(context).writeAMessage,
|
||||||
}
|
border: InputBorder.none,
|
||||||
},
|
|
||||||
),
|
),
|
||||||
)),
|
onChanged: (String text) {
|
||||||
SizedBox(width: 8),
|
this.typingCoolDown?.cancel();
|
||||||
IconButton(
|
this.typingCoolDown =
|
||||||
icon: Icon(Icons.send),
|
Timer(Duration(seconds: 2), () {
|
||||||
onPressed: () => send(),
|
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(
|
||||||
: Container(),
|
icon: Icon(Icons.send),
|
||||||
],
|
onPressed: () => send(),
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Container(),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,14 +2,14 @@ import 'dart:async';
|
||||||
|
|
||||||
import 'package:famedlysdk/famedlysdk.dart';
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
||||||
import 'package:fluffychat/components/dialogs/new_group_dialog.dart';
|
|
||||||
import 'package:fluffychat/components/dialogs/new_private_chat_dialog.dart';
|
|
||||||
import 'package:fluffychat/components/list_items/chat_list_item.dart';
|
import 'package:fluffychat/components/list_items/chat_list_item.dart';
|
||||||
import 'package:fluffychat/components/matrix.dart';
|
import 'package:fluffychat/components/matrix.dart';
|
||||||
import 'package:fluffychat/i18n/i18n.dart';
|
import 'package:fluffychat/i18n/i18n.dart';
|
||||||
import 'package:fluffychat/utils/app_route.dart';
|
import 'package:fluffychat/utils/app_route.dart';
|
||||||
import 'package:fluffychat/utils/url_launcher.dart';
|
import 'package:fluffychat/utils/url_launcher.dart';
|
||||||
import 'package:fluffychat/views/archive.dart';
|
import 'package:fluffychat/views/archive.dart';
|
||||||
|
import 'package:fluffychat/views/new_group.dart';
|
||||||
|
import 'package:fluffychat/views/new_private_chat.dart';
|
||||||
import 'package:fluffychat/views/settings.dart';
|
import 'package:fluffychat/views/settings.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
@ -193,19 +193,18 @@ class _ChatListState extends State<ChatList> {
|
||||||
backgroundColor: Colors.blue,
|
backgroundColor: Colors.blue,
|
||||||
label: I18n.of(context).createNewGroup,
|
label: I18n.of(context).createNewGroup,
|
||||||
labelStyle: TextStyle(fontSize: 18.0),
|
labelStyle: TextStyle(fontSize: 18.0),
|
||||||
onTap: () => showDialog(
|
onTap: () => Navigator.of(context).pushAndRemoveUntil(
|
||||||
context: context,
|
AppRoute.defaultRoute(context, NewGroupView()),
|
||||||
builder: (BuildContext innerContext) => NewGroupDialog(),
|
(r) => r.isFirst),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
SpeedDialChild(
|
SpeedDialChild(
|
||||||
child: Icon(Icons.person_add),
|
child: Icon(Icons.person_add),
|
||||||
backgroundColor: Colors.green,
|
backgroundColor: Colors.green,
|
||||||
label: I18n.of(context).newPrivateChat,
|
label: I18n.of(context).newPrivateChat,
|
||||||
labelStyle: TextStyle(fontSize: 18.0),
|
labelStyle: TextStyle(fontSize: 18.0),
|
||||||
onTap: () => showDialog(
|
onTap: () => Navigator.of(context).pushAndRemoveUntil(
|
||||||
context: context,
|
AppRoute.defaultRoute(context, NewPrivateChatView()),
|
||||||
builder: (BuildContext innerContext) => NewPrivateChatDialog()),
|
(r) => r.isFirst),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
107
lib/views/new_group.dart
Normal file
107
lib/views/new_group.dart
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
||||||
|
import 'package:fluffychat/components/matrix.dart';
|
||||||
|
import 'package:fluffychat/i18n/i18n.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pedantic/pedantic.dart';
|
||||||
|
|
||||||
|
import 'chat.dart';
|
||||||
|
import 'chat_list.dart';
|
||||||
|
import 'invitation_selection.dart';
|
||||||
|
|
||||||
|
class NewGroupView extends StatelessWidget {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AdaptivePageLayout(
|
||||||
|
primaryPage: FocusPage.SECOND,
|
||||||
|
firstScaffold: ChatList(),
|
||||||
|
secondScaffold: _NewGroup(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _NewGroup extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
_NewGroupState createState() => _NewGroupState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _NewGroupState extends State<_NewGroup> {
|
||||||
|
TextEditingController controller = TextEditingController();
|
||||||
|
bool publicGroup = false;
|
||||||
|
|
||||||
|
void submitAction(BuildContext context) async {
|
||||||
|
final MatrixState matrix = Matrix.of(context);
|
||||||
|
Map<String, dynamic> params = {};
|
||||||
|
if (publicGroup) {
|
||||||
|
params["preset"] = "public_chat";
|
||||||
|
params["visibility"] = "public";
|
||||||
|
if (controller.text.isNotEmpty) {
|
||||||
|
params["room_alias_name"] = controller.text;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
params["preset"] = "private_chat";
|
||||||
|
}
|
||||||
|
if (controller.text.isNotEmpty) params["name"] = controller.text;
|
||||||
|
final String roomID = await matrix.tryRequestWithLoadingDialog(
|
||||||
|
matrix.client.createRoom(params: params),
|
||||||
|
);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
if (roomID != null) {
|
||||||
|
unawaited(
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) {
|
||||||
|
return ChatView(roomID);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => InvitationSelection(
|
||||||
|
matrix.client.getRoomById(roomID),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(I18n.of(context).createNewGroup),
|
||||||
|
elevation: 0,
|
||||||
|
),
|
||||||
|
body: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: <Widget>[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: TextField(
|
||||||
|
controller: controller,
|
||||||
|
autofocus: true,
|
||||||
|
autocorrect: false,
|
||||||
|
textInputAction: TextInputAction.go,
|
||||||
|
onSubmitted: (s) => submitAction(context),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
labelText: I18n.of(context).optionalGroupName,
|
||||||
|
prefixIcon: Icon(Icons.people),
|
||||||
|
hintText: I18n.of(context).enterAGroupName),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SwitchListTile(
|
||||||
|
title: Text(I18n.of(context).groupIsPublic),
|
||||||
|
value: publicGroup,
|
||||||
|
onChanged: (bool b) => setState(() => publicGroup = b),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
backgroundColor: Theme.of(context).primaryColor,
|
||||||
|
onPressed: () => submitAction(context),
|
||||||
|
child: Icon(Icons.arrow_forward),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
240
lib/views/new_private_chat.dart
Normal file
240
lib/views/new_private_chat.dart
Normal file
|
@ -0,0 +1,240 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
|
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
||||||
|
import 'package:fluffychat/components/avatar.dart';
|
||||||
|
import 'package:fluffychat/components/matrix.dart';
|
||||||
|
import 'package:fluffychat/i18n/i18n.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:share/share.dart';
|
||||||
|
|
||||||
|
import 'chat.dart';
|
||||||
|
import 'chat_list.dart';
|
||||||
|
|
||||||
|
class NewPrivateChatView extends StatelessWidget {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AdaptivePageLayout(
|
||||||
|
primaryPage: FocusPage.SECOND,
|
||||||
|
firstScaffold: ChatList(),
|
||||||
|
secondScaffold: _NewPrivateChat(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _NewPrivateChat extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
_NewPrivateChatState createState() => _NewPrivateChatState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _NewPrivateChatState extends State<_NewPrivateChat> {
|
||||||
|
TextEditingController controller = TextEditingController();
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
bool loading = false;
|
||||||
|
String currentSearchTerm;
|
||||||
|
List<Map<String, dynamic>> foundProfiles = [];
|
||||||
|
Timer coolDown;
|
||||||
|
Map<String, dynamic> get foundProfile => foundProfiles.firstWhere(
|
||||||
|
(user) => user["user_id"] == "@$currentSearchTerm",
|
||||||
|
orElse: () => null);
|
||||||
|
bool get correctMxId =>
|
||||||
|
foundProfiles
|
||||||
|
.indexWhere((user) => user["user_id"] == "@$currentSearchTerm") !=
|
||||||
|
-1;
|
||||||
|
|
||||||
|
void submitAction(BuildContext context) async {
|
||||||
|
if (controller.text.isEmpty) return;
|
||||||
|
if (!_formKey.currentState.validate()) return;
|
||||||
|
final MatrixState matrix = Matrix.of(context);
|
||||||
|
|
||||||
|
if ("@" + controller.text.trim() == matrix.client.userID) return;
|
||||||
|
|
||||||
|
final User user = User(
|
||||||
|
"@" + controller.text.trim(),
|
||||||
|
room: Room(id: "", client: matrix.client),
|
||||||
|
);
|
||||||
|
final String roomID =
|
||||||
|
await matrix.tryRequestWithLoadingDialog(user.startDirectChat());
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
|
||||||
|
if (roomID != null) {
|
||||||
|
await Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => ChatView(roomID)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void searchUserWithCoolDown(BuildContext context, String text) async {
|
||||||
|
coolDown?.cancel();
|
||||||
|
coolDown = Timer(
|
||||||
|
Duration(seconds: 1),
|
||||||
|
() => searchUser(context, text),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void searchUser(BuildContext context, String text) async {
|
||||||
|
if (text.isEmpty) {
|
||||||
|
setState(() {
|
||||||
|
foundProfiles = [];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
currentSearchTerm = text;
|
||||||
|
if (currentSearchTerm.isEmpty) return;
|
||||||
|
if (loading) return;
|
||||||
|
setState(() => loading = true);
|
||||||
|
final MatrixState matrix = Matrix.of(context);
|
||||||
|
final response = await matrix.tryRequestWithErrorToast(
|
||||||
|
matrix.client.jsonRequest(
|
||||||
|
type: HTTPType.POST,
|
||||||
|
action: "/client/r0/user_directory/search",
|
||||||
|
data: {
|
||||||
|
"search_term": text,
|
||||||
|
"limit": 10,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
setState(() => loading = false);
|
||||||
|
if (response == false ||
|
||||||
|
!(response is Map) ||
|
||||||
|
(response["results"]?.isEmpty ?? true)) return;
|
||||||
|
setState(() {
|
||||||
|
foundProfiles = List<Map<String, dynamic>>.from(response["results"]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final String defaultDomain = Matrix.of(context).client.userID.split(":")[1];
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(I18n.of(context).newPrivateChat),
|
||||||
|
elevation: 0,
|
||||||
|
),
|
||||||
|
body: Column(
|
||||||
|
children: <Widget>[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: TextFormField(
|
||||||
|
controller: controller,
|
||||||
|
autofocus: true,
|
||||||
|
autocorrect: false,
|
||||||
|
onChanged: (String text) =>
|
||||||
|
searchUserWithCoolDown(context, text),
|
||||||
|
textInputAction: TextInputAction.go,
|
||||||
|
onFieldSubmitted: (s) => submitAction(context),
|
||||||
|
validator: (value) {
|
||||||
|
if (value.isEmpty) {
|
||||||
|
return I18n.of(context).pleaseEnterAMatrixIdentifier;
|
||||||
|
}
|
||||||
|
final MatrixState matrix = Matrix.of(context);
|
||||||
|
String mxid = "@" + controller.text.trim();
|
||||||
|
if (mxid == matrix.client.userID) {
|
||||||
|
return I18n.of(context).youCannotInviteYourself;
|
||||||
|
}
|
||||||
|
if (!mxid.contains("@")) {
|
||||||
|
return I18n.of(context).makeSureTheIdentifierIsValid;
|
||||||
|
}
|
||||||
|
if (!mxid.contains(":")) {
|
||||||
|
return I18n.of(context).makeSureTheIdentifierIsValid;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
labelText: I18n.of(context).enterAUsername,
|
||||||
|
prefixIcon: loading
|
||||||
|
? Container(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
width: 12,
|
||||||
|
height: 12,
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
)
|
||||||
|
: correctMxId
|
||||||
|
? Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Avatar(
|
||||||
|
MxContent(foundProfile["avatar_url"] ?? ""),
|
||||||
|
foundProfile["display_name"] ??
|
||||||
|
foundProfile["user_id"],
|
||||||
|
size: 12,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Icon(Icons.account_circle),
|
||||||
|
prefixText: "@",
|
||||||
|
hintText:
|
||||||
|
"${I18n.of(context).username.toLowerCase()}:$defaultDomain",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Divider(height: 1),
|
||||||
|
if (foundProfiles.isNotEmpty && !correctMxId)
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: foundProfiles.length,
|
||||||
|
itemBuilder: (BuildContext context, int i) {
|
||||||
|
Map<String, dynamic> foundProfile = foundProfiles[i];
|
||||||
|
return ListTile(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
controller.text = currentSearchTerm =
|
||||||
|
foundProfile["user_id"].substring(1);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
leading: Avatar(
|
||||||
|
MxContent(foundProfile["avatar_url"] ?? ""),
|
||||||
|
foundProfile["display_name"] ?? foundProfile["user_id"],
|
||||||
|
//size: 24,
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
foundProfile["display_name"] ??
|
||||||
|
foundProfile["user_id"].split(":").first.substring(1),
|
||||||
|
style: TextStyle(),
|
||||||
|
maxLines: 1,
|
||||||
|
),
|
||||||
|
subtitle: Text(
|
||||||
|
foundProfile["user_id"],
|
||||||
|
maxLines: 1,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (foundProfiles.isEmpty || correctMxId)
|
||||||
|
ListTile(
|
||||||
|
trailing: Icon(
|
||||||
|
Icons.share,
|
||||||
|
size: 16,
|
||||||
|
),
|
||||||
|
onTap: () => Share.share(
|
||||||
|
"https://matrix.to/#/${Matrix.of(context).client.userID}"),
|
||||||
|
title: Text(
|
||||||
|
"${I18n.of(context).yourOwnUsername}:",
|
||||||
|
style: TextStyle(
|
||||||
|
fontStyle: FontStyle.italic,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
subtitle: Text(
|
||||||
|
Matrix.of(context).client.userID,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
color: Theme.of(context).primaryColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Divider(height: 1),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: () => submitAction(context),
|
||||||
|
child: Icon(Icons.arrow_forward),
|
||||||
|
backgroundColor: Theme.of(context).primaryColor,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -110,8 +110,8 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: "1ff04785c0fb7db986c8a7b33396bf06301f1a14"
|
ref: "53250618764f068aae92ecff52eaa4d968be3290"
|
||||||
resolved-ref: "1ff04785c0fb7db986c8a7b33396bf06301f1a14"
|
resolved-ref: "53250618764f068aae92ecff52eaa4d968be3290"
|
||||||
url: "https://gitlab.com/famedly/famedlysdk.git"
|
url: "https://gitlab.com/famedly/famedlysdk.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.0.1"
|
version: "0.0.1"
|
||||||
|
|
|
@ -27,7 +27,7 @@ dependencies:
|
||||||
famedlysdk:
|
famedlysdk:
|
||||||
git:
|
git:
|
||||||
url: https://gitlab.com/famedly/famedlysdk.git
|
url: https://gitlab.com/famedly/famedlysdk.git
|
||||||
ref: 1ff04785c0fb7db986c8a7b33396bf06301f1a14
|
ref: 53250618764f068aae92ecff52eaa4d968be3290
|
||||||
|
|
||||||
localstorage: ^3.0.1+4
|
localstorage: ^3.0.1+4
|
||||||
bubble: ^1.1.9+1
|
bubble: ^1.1.9+1
|
||||||
|
|
Loading…
Reference in a new issue