Compare commits

...

3 Commits

Author SHA1 Message Date
Pascal Abresch eb77e51775 removed autofocus 2019-08-01 14:46:56 +02:00
Pascal Abresch e4e7877f99 moved main code back to main.dart 2019-08-01 14:45:16 +02:00
Pascal Abresch 0fc98068ca added transaction ids 2019-08-01 14:43:43 +02:00
4 changed files with 30 additions and 29 deletions

26
lib/main.dart Normal file
View File

@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'page/login';
import 'page/roomlist';
void main() async {
var settings = await SharedPreferences.getInstance();
var _home;
if (settings.getBool("logged_in") ?? false) {
_home = MyHomePage(settings: settings);
} else {
_home = LoginPage(settings: settings);
}
runApp(MaterialApp(
title: 'Hermes',
theme: ThemeData(
brightness: Brightness.dark,
primaryColor: Colors.pink,
backgroundColor: Colors.black,
primarySwatch: Colors.pink,
),
home: _home,
));
}

View File

@ -4,6 +4,7 @@ import 'dart:math';
import 'package:meta/meta.dart';
class Matrix {
static int txid = 0;
// TODO Error handeling
static Future<String> request({@required Uri uri, @required final String method, final String accessToken, final String jsonPayload}) async {
final client = new HttpClient();
@ -41,13 +42,11 @@ class Matrix {
}
static Future<void> sendMessage({@required Uri uri, @required final String accessToken, @required final String roomid, @required final String message}) async {
var rand = Random();
//String txid = (String)rand.nextInt(2^32);
String txid = '3';
String t_txid = txid.toString();
txid = txid + 1;
var json = new JsonCodec();
String payload = '{"msgtype":"m.text","body":' + json.encode(message) + '}';
print(payload);
request(uri: uri.replace(path: '/_matrix/client/r0/rooms/' + Uri.encodeComponent(roomid) + '/send/m.room.message/' + txid), method: 'PUT', accessToken: accessToken, jsonPayload: payload).then((cont) {
request(uri: uri.replace(path: '/_matrix/client/r0/rooms/' + Uri.encodeComponent(roomid) + '/send/m.room.message/' + t_txid), method: 'PUT', accessToken: accessToken, jsonPayload: payload).then((cont) {
print(cont);
});
}
@ -95,7 +94,6 @@ class Matrix {
return await request(uri: uri.replace(path:"/_matrix/client/r0/rooms/" + Uri.encodeComponent(roomid) + "/initialSync"), method: 'GET', accessToken: accessToken).then((cont) {
var json = new JsonDecoder().convert(cont);
var john = json["messages"]["chunk"];
print("done");
return john;
});
}

View File

@ -63,7 +63,6 @@ class _RoomPageState extends State<RoomPage> {
TextField(
onSubmitted: _sendMessage,
controller: _inputController,
autofocus: true,
),
],
),

View File

@ -4,28 +4,6 @@ import 'login';
import '../matrix/cs-r0.5.0';
import 'room';
void main() async {
var settings = await SharedPreferences.getInstance();
var _home;
if (settings.getBool("logged_in") ?? false) {
_home = MyHomePage(settings: settings);
} else {
_home = LoginPage(settings: settings);
}
runApp(MaterialApp(
title: 'Hermes',
theme: ThemeData(
brightness: Brightness.dark,
primaryColor: Colors.pink,
backgroundColor: Colors.black,
primarySwatch: Colors.pink,
),
home: _home,
));
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, @required this.settings}) : super(key: key);