Compare commits
3 Commits
cf3b6ee4a9
...
eb77e51775
Author | SHA1 | Date |
---|---|---|
Pascal Abresch | eb77e51775 | |
Pascal Abresch | e4e7877f99 | |
Pascal Abresch | 0fc98068ca |
|
@ -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,
|
||||
));
|
||||
}
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -63,7 +63,6 @@ class _RoomPageState extends State<RoomPage> {
|
|||
TextField(
|
||||
onSubmitted: _sendMessage,
|
||||
controller: _inputController,
|
||||
autofocus: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Reference in New Issue