Compare commits
4 Commits
eb77e51775
...
4050e6ac93
Author | SHA1 | Date |
---|---|---|
nep@lizzie | 4050e6ac93 | |
nep@lizzie | 20b5f87ee0 | |
nep@lizzie | 11fbb41f91 | |
nep@lizzie | 516df6eae3 |
|
@ -8,7 +8,6 @@ class Matrix {
|
|||
// 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();
|
||||
print(uri);
|
||||
if (method == 'GET') {
|
||||
requestMethod(Uri uri) => client.getUrl(uri);
|
||||
return await requestsend(uri: uri, function: requestMethod, accessToken: accessToken, jsonPayload: jsonPayload);
|
||||
|
@ -87,7 +86,7 @@ class Matrix {
|
|||
static Future<void> sync({@required Uri uri, @required final String accessToken}) async {
|
||||
request(uri: uri.replace(path:"/_matrix/client/r0/sync"), method: 'GET', accessToken: accessToken).then((cont) {
|
||||
var json = new JsonDecoder().convert(cont);
|
||||
print(json);
|
||||
print(json["rooms"]["join"]);
|
||||
});
|
||||
}
|
||||
static Future<List<dynamic>> roomsync({@required Uri uri, @required final String accessToken, @required final String roomid, final String paginationToken}) async {
|
||||
|
|
|
@ -46,9 +46,22 @@ class _LoginPageState extends State<LoginPage> {
|
|||
return req.close();
|
||||
}).then((resp) {
|
||||
return resp.transform(utf8.decoder).join().then((cont) {
|
||||
var json = new JsonDecoder().convert(cont);
|
||||
if (resp.statusCode != 200) {
|
||||
_failureMessage = "HTTP ${resp.statusCode}";
|
||||
}
|
||||
print("StatusCode: ${resp.statusCode}");
|
||||
var json;
|
||||
try {
|
||||
json = new JsonDecoder().convert(cont);
|
||||
}
|
||||
catch(e) {
|
||||
print(cont);
|
||||
_failureMessage = "Invalid JSON!";
|
||||
return;
|
||||
}
|
||||
// I hate switch statements
|
||||
if (resp.statusCode == 403) {
|
||||
print(cont);
|
||||
_failureMessage = json["error"];
|
||||
} else if (resp.statusCode == 200) {
|
||||
var s = widget.settings;
|
||||
|
@ -62,6 +75,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||
s.setBool("logged_in", true);
|
||||
_showMainView();
|
||||
} else {
|
||||
_failureMessage = "{$resp.statusCode}: ${json}";
|
||||
print(resp.statusCode);
|
||||
print(json);
|
||||
}
|
||||
|
@ -90,16 +104,11 @@ class _LoginPageState extends State<LoginPage> {
|
|||
onChanged: (s) { _homeServer = s; }
|
||||
),
|
||||
Text("Home server"),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
Text(_failureMessage),
|
||||
RaisedButton(
|
||||
RaisedButton(
|
||||
child: Text("Login"),
|
||||
onPressed: () { setState(() { _doLogin(); }); },
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(_failureMessage),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
@ -29,17 +29,24 @@ class _RoomPageState extends State<RoomPage> {
|
|||
var set = widget.settings;
|
||||
Matrix.sendMessage(uri: Uri.parse(set.getString("home_server")), accessToken: set.getString("access_token"), roomid: widget.roomid, message: str);
|
||||
_inputController.text = "";
|
||||
_updateMessages();
|
||||
}
|
||||
|
||||
void _updateMessages() {
|
||||
var set = widget.settings;
|
||||
var cont = Matrix.roomsync(uri: Uri.parse(set.getString("home_server")), roomid: widget.roomid, accessToken: set.getString("access_token")).then((cont) {
|
||||
_messages= [ ];
|
||||
List<Widget> messages = [ ];
|
||||
for (var neko in cont) {
|
||||
if (neko["type"] == "m.room.message") {
|
||||
_messages.add(Text(neko["sender"] + ": " + neko["content"]["body"], textAlign: TextAlign.left));
|
||||
messages.add(
|
||||
ListTile(
|
||||
leading: Text(neko["sender"]),
|
||||
title: Text(neko["content"]["body"], textAlign: TextAlign.left)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
_messages= messages;
|
||||
setState(() {
|
||||
|
||||
});
|
||||
|
@ -60,10 +67,23 @@ class _RoomPageState extends State<RoomPage> {
|
|||
children: _messages
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
onSubmitted: _sendMessage,
|
||||
controller: _inputController,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
onSubmitted: _sendMessage,
|
||||
controller: _inputController,
|
||||
minLines: 1,
|
||||
maxLines: 4
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.send),
|
||||
color: Colors.pink,
|
||||
onPressed: () { _sendMessage(_inputController.text); }
|
||||
),
|
||||
]
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
|
|
@ -50,6 +50,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
void initState() {
|
||||
_updateRooms();
|
||||
print(Matrix.supportedVersions(widget.settings.getString("home_server")));
|
||||
Matrix.sync(uri: Uri.parse(widget.settings.getString("home_server")), accessToken: widget.settings.getString("access_token"));
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: hermes
|
||||
description: A new Flutter project.
|
||||
description: A messenger for matrix.
|
||||
|
||||
# The following defines the version and build number for your application.
|
||||
# A version number is three numbers separated by dots, like 1.2.43
|
||||
|
@ -7,7 +7,8 @@ description: A new Flutter project.
|
|||
# Both the version and the builder number may be overridden in flutter
|
||||
# build by specifying --build-name and --build-number, respectively.
|
||||
# Read more about versioning at semver.org.
|
||||
version: 1.0.0+1
|
||||
version: 0.0.0
|
||||
#fuck you stupid version number counter
|
||||
|
||||
environment:
|
||||
sdk: ">=2.1.0 <3.0.0"
|
||||
|
|
Reference in New Issue