Commit a03d3eec authored by Wilko Manger's avatar Wilko Manger

Implement message sending

parent 34a6b44f
Pipeline #340 passed with stages
in 3 minutes and 38 seconds
......@@ -21,7 +21,7 @@ import 'package:rxdart/rxdart.dart';
class ChatBloc {
Room room;
JoinedRoom room;
int _eventCount = 20;
......@@ -72,4 +72,13 @@ class ChatBloc {
_eventSubj.add(List.of(chatEvents));
}
Future<void> sendMessage(String text) async {
// TODO: Check if text is just whitespace
if (text.isNotEmpty) {
await room.send(TextMessage(body: text));
await loadEvents();
}
}
}
\ No newline at end of file
......@@ -19,7 +19,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/ui/main/chat/chat_bloc.dart';
import 'package:pattle/src/ui/main/chat/widgets/text_message.dart';
import 'package:pattle/src/ui/main/chat/widgets/bubble.dart';
import 'package:pattle/src/ui/resources/theme.dart';
import 'package:pattle/src/ui/util/matrix_image.dart';
......@@ -29,12 +29,13 @@ class ChatPageState extends State<ChatPage> {
final me = di.getLocalUser();
final ChatBloc bloc = ChatBloc();
final Room room;
final JoinedRoom room;
ScrollController scrollController = ScrollController();
double get scrollLoadRange => scrollController.position.maxScrollExtent - 700;
TextEditingController textController = TextEditingController();
ChatPageState(this.room) {
bloc.room = room;
}
......@@ -96,13 +97,57 @@ class ChatPageState extends State<ChatPage> {
),
body: Stack(
children: <Widget>[
_buildEventsList(),
_buildBody(),
_buildLoadingIndicator()
],
)
);
}
Widget _buildBody() {
return Column(
children: <Widget>[
Expanded(
child: _buildEventsList()
),
_buildInput(),
],
);
}
Widget _buildInput() {
return Material(
elevation: 8,
color: LightColors.red[50],
child: Padding(
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: Material(
elevation: 8,
borderRadius: BorderRadius.circular(8),
child: TextField(
controller: textController,
textInputAction: TextInputAction.newline,
decoration: InputDecoration(
border: UnderlineInputBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(8))
),
filled: true,
fillColor: Colors.white,
hintText: 'Type a message',
suffixIcon: IconButton(
icon: Icon(Icons.send),
onPressed: () {
bloc.sendMessage(textController.value.text);
textController.clear();
}
)
),
),
)
)
);
}
Widget _buildLoadingIndicator() {
return StreamBuilder<bool>(
stream: bloc.isLoadingEvents,
......@@ -169,7 +214,7 @@ class ChatPageState extends State<ChatPage> {
Event event, Event previousEvent, Event nextEvent, bool isMine) {
if (event is TextMessageEvent) {
return TextMessage(
return Bubble(
message: event,
previousEvent: previousEvent,
nextEvent: nextEvent,
......
......@@ -22,7 +22,7 @@ import 'package:pattle/src/ui/util/date_format.dart';
import 'package:pattle/src/ui/util/display_name.dart';
class TextMessage extends StatelessWidget {
class Bubble extends StatelessWidget {
final TextMessageEvent message;
......@@ -41,7 +41,7 @@ class TextMessage extends StatelessWidget {
static const _betweenGroupMargin = 4.0;
static const _oppositeMargin = 64.0;
TextMessage({
Bubble({
@required this.message,
@required this.previousEvent,
@required this.nextEvent,
......@@ -83,7 +83,7 @@ class TextMessage extends StatelessWidget {
Widget _buildContent(BuildContext context) =>
Text(message.body ?? '',
Text(message.content.body ?? '',
style: _textStyle(context)
);
......@@ -260,7 +260,7 @@ class TextMessage extends StatelessWidget {
),
)
),
)
)
),
]
),
......
......@@ -170,7 +170,7 @@ class ChatOverviewPageState extends State<ChatOverviewPage> {
)
),
TextSpan(
text: event.body ?? 'null'
text: event.content.body ?? 'null'
)
]
)
......
......@@ -178,14 +178,14 @@ packages:
name: matrix_sdk
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.4"
version: "0.3.0"
matrix_sdk_sqflite:
dependency: "direct main"
description:
name: matrix_sdk_sqflite
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.10"
version: "0.1.11"
meta:
dependency: transitive
description:
......
......@@ -12,8 +12,8 @@ dependencies:
injector: ^1.0.6
matrix_sdk: ^0.2.4
matrix_sdk_sqflite: ^0.1.10
matrix_sdk: ^0.3.0
matrix_sdk_sqflite: ^0.1.11
rxdart: ^0.21.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment