Compare commits

...

2 Commits

2 changed files with 97 additions and 64 deletions

View File

@ -49,23 +49,19 @@ class _LoginPageState extends State<LoginPage> {
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;
print(json);
s.setString("access_token", json["access_token"]);
s.setString("matrix_id", json["user_id"]);
//this means the hs uri was correct, but not neccesarily what the server gives us
@ -76,8 +72,6 @@ class _LoginPageState extends State<LoginPage> {
_showMainView();
} else {
_failureMessage = "{$resp.statusCode}: ${json}";
print(resp.statusCode);
print(json);
}
});
});
@ -94,7 +88,7 @@ class _LoginPageState extends State<LoginPage> {
padding: EdgeInsets.all(8.0),
child: ListView(
children: <Widget>[
TextField(autocorrect: false, onChanged: (s) { _matrixId = s; }),
TextField(autocorrect: false, onChanged: (s) { _matrixId = s; }, autofocus: true),
Text("Matrix ID"),
TextField(autocorrect: false, obscureText: true, onChanged: (s) { _password = s; }),
Text("Password"),

View File

@ -38,17 +38,48 @@ class _RoomPageState extends State<RoomPage> {
List<Widget> messages = [ ];
for (var neko in cont) {
if (neko["type"] == "m.room.message") {
if (neko["content"]["msgtype"] == "m.text") {
messages.add(
ListTile(
leading: Text(neko["sender"]),
title: Text(neko["content"]["body"], textAlign: TextAlign.left)
)
title: Column(
children: <Widget>[
Row( children: <Widget>[ Text(neko["sender"], style: TextStyle(fontWeight: FontWeight.bold), textAlign: TextAlign.start), Spacer()]),
Row( children: <Widget>[ Expanded(child: Text(neko["content"]["body"], textAlign: TextAlign.start))]),
]
),
),
);
} else if (neko["content"]["msgtype"] == "m.notice") {
messages.add(
ListTile(
title: Column(
children: <Widget>[
Text(neko["sender"], textAlign: TextAlign.center),
Text(neko["content"]["body"], textAlign: TextAlign.center),
]
),
),
);
} else if (neko["content"]["msgtype"] == "m.emote") {
messages.add(
ListTile(
title: Column(
children: <Widget>[
Row( children: <Widget> [
Text(neko["sender"], style: TextStyle(fontStyle: FontStyle.italic, fontWeight: FontWeight.bold), textAlign: TextAlign.left)
]),
Row( children: <Widget> [
Text(neko["content"]["body"], style: TextStyle(fontStyle: FontStyle.italic), textAlign: TextAlign.left),
]),
]
),
),
);
}
}
_messages= messages;
}
setState(() {
_messages= messages;
});
});
}
@ -58,6 +89,14 @@ class _RoomPageState extends State<RoomPage> {
return Scaffold(
appBar: AppBar(
title: Text(widget.roomname),
actions: <Widget>[
IconButton(
icon: Icon(Icons.autorenew, color: Colors.purple),
onPressed: () {
_updateMessages();
}
)
]
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,