Fix message types and update to newest sdk
This commit is contained in:
parent
e97a5319d9
commit
fda9b752df
|
@ -16,7 +16,9 @@ class Message extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (event.typeKey != "m.room.message") return StateMessage(event);
|
if (![EventTypes.Message, EventTypes.Sticker].contains(event.type)) {
|
||||||
|
return StateMessage(event);
|
||||||
|
}
|
||||||
|
|
||||||
Client client = Matrix.of(context).client;
|
Client client = Matrix.of(context).client;
|
||||||
final bool ownMessage = event.senderId == client.userID;
|
final bool ownMessage = event.senderId == client.userID;
|
||||||
|
|
|
@ -131,24 +131,29 @@ class MatrixState extends State<Matrix> {
|
||||||
|
|
||||||
StreamSubscription onSetupFirebase;
|
StreamSubscription onSetupFirebase;
|
||||||
|
|
||||||
void setupFirebase(LoginState login) {
|
void setupFirebase(LoginState login) async {
|
||||||
if (login != LoginState.logged) return;
|
if (login != LoginState.logged) return;
|
||||||
if (Platform.isIOS) iOS_Permission();
|
if (Platform.isIOS) iOS_Permission();
|
||||||
|
|
||||||
_firebaseMessaging.getToken().then((token) {
|
final String token = await _firebaseMessaging.getToken();
|
||||||
print("Der token ist: $token");
|
if (token?.isEmpty ?? true) {
|
||||||
client.setPushers(
|
return Toast.show(
|
||||||
|
"Push notifications disabled.",
|
||||||
|
context,
|
||||||
|
duration: Toast.LENGTH_LONG,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await client.setPushers(
|
||||||
token,
|
token,
|
||||||
"http",
|
"http",
|
||||||
"chat.fluffy.fluffychat",
|
"chat.fluffy.fluffychat",
|
||||||
"FluffyChat",
|
widget.clientName,
|
||||||
client.deviceName,
|
client.deviceName,
|
||||||
"en",
|
"en",
|
||||||
"https://janian.de:7023/",
|
"https://janian.de:7023/",
|
||||||
append: false,
|
append: false,
|
||||||
format: "event_id_only",
|
format: "event_id_only",
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
_firebaseMessaging.configure(
|
_firebaseMessaging.configure(
|
||||||
onResume: (Map<String, dynamic> message) async {
|
onResume: (Map<String, dynamic> message) async {
|
||||||
|
@ -172,7 +177,7 @@ class MatrixState extends State<Matrix> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
if (widget.client == null) {
|
if (widget.client == null) {
|
||||||
client = Client(widget.clientName, debug: true);
|
client = Client(widget.clientName, debug: false);
|
||||||
if (!kIsWeb) {
|
if (!kIsWeb) {
|
||||||
client.store = Store(client);
|
client.store = Store(client);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,7 +3,6 @@ import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:famedlysdk/famedlysdk.dart';
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:link_text/link_text.dart';
|
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
import 'matrix.dart';
|
import 'matrix.dart';
|
||||||
|
@ -19,15 +18,30 @@ class MessageContent extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final int maxLines = textOnly ? 1 : null;
|
final int maxLines = textOnly ? 1 : null;
|
||||||
|
|
||||||
|
final Widget unknown = Text(
|
||||||
|
"${event.sender.calcDisplayname()} sent a ${event.typeKey} event",
|
||||||
|
maxLines: maxLines,
|
||||||
|
overflow: textOnly ? TextOverflow.ellipsis : null,
|
||||||
|
style: TextStyle(
|
||||||
|
color: textColor,
|
||||||
|
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case EventTypes.Image:
|
case EventTypes.Message:
|
||||||
|
case EventTypes.Sticker:
|
||||||
|
switch (event.messageType) {
|
||||||
|
case MessageTypes.Image:
|
||||||
|
case MessageTypes.Sticker:
|
||||||
if (textOnly) {
|
if (textOnly) {
|
||||||
return Text(
|
return Text(
|
||||||
"${event.sender.calcDisplayname()} has sent an image",
|
"${event.sender.calcDisplayname()} has sent an image",
|
||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: textColor,
|
color: textColor,
|
||||||
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
decoration:
|
||||||
|
event.redacted ? TextDecoration.lineThrough : null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -58,9 +72,9 @@ class MessageContent extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
case EventTypes.Audio:
|
case MessageTypes.Audio:
|
||||||
case EventTypes.File:
|
case MessageTypes.File:
|
||||||
case EventTypes.Video:
|
case MessageTypes.Video:
|
||||||
return Container(
|
return Container(
|
||||||
width: 200,
|
width: 200,
|
||||||
child: RaisedButton(
|
child: RaisedButton(
|
||||||
|
@ -77,34 +91,27 @@ class MessageContent extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
case EventTypes.Text:
|
case MessageTypes.Text:
|
||||||
case EventTypes.Reply:
|
case MessageTypes.Reply:
|
||||||
case EventTypes.Notice:
|
case MessageTypes.Location:
|
||||||
|
case MessageTypes.None:
|
||||||
|
case MessageTypes.Notice:
|
||||||
final String senderPrefix =
|
final String senderPrefix =
|
||||||
textOnly && event.senderId != event.room.directChatMatrixID
|
textOnly && event.senderId != event.room.directChatMatrixID
|
||||||
? event.senderId == Matrix.of(context).client.userID
|
? event.senderId == Matrix.of(context).client.userID
|
||||||
? "You: "
|
? "You: "
|
||||||
: "${event.sender.calcDisplayname()}: "
|
: "${event.sender.calcDisplayname()}: "
|
||||||
: "";
|
: "";
|
||||||
if (textOnly) {
|
|
||||||
return Text(
|
return Text(
|
||||||
senderPrefix + event.getBody(),
|
senderPrefix + event.getBody(),
|
||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: textOnly ? TextOverflow.ellipsis : null,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: textColor,
|
color: textColor,
|
||||||
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
case MessageTypes.Emote:
|
||||||
return LinkText(
|
|
||||||
text: senderPrefix + event.getBody(),
|
|
||||||
textStyle: TextStyle(
|
|
||||||
color: textColor,
|
|
||||||
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
case EventTypes.Emote:
|
|
||||||
return Text(
|
return Text(
|
||||||
"* " + event.getBody(),
|
"* " + event.getBody(),
|
||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
|
@ -115,6 +122,8 @@ class MessageContent extends StatelessWidget {
|
||||||
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
return unknown;
|
||||||
case EventTypes.RoomCreate:
|
case EventTypes.RoomCreate:
|
||||||
return Text(
|
return Text(
|
||||||
"${event.sender.calcDisplayname()} has created the chat",
|
"${event.sender.calcDisplayname()} has created the chat",
|
||||||
|
@ -272,15 +281,7 @@ class MessageContent extends StatelessWidget {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return Text(
|
return unknown;
|
||||||
"${event.sender.calcDisplayname()} sent a ${event.typeKey} event",
|
|
||||||
maxLines: maxLines,
|
|
||||||
overflow: textOnly ? TextOverflow.ellipsis : null,
|
|
||||||
style: TextStyle(
|
|
||||||
color: textColor,
|
|
||||||
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,9 @@ class App extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Matrix(
|
return Matrix(
|
||||||
clientName: "FluffyWeb",
|
clientName: "FluffyChat",
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
title: 'FluffyWeb',
|
title: 'FluffyChat',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
brightness: Brightness.light,
|
brightness: Brightness.light,
|
||||||
primaryColor: Color(0xFF5625BA),
|
primaryColor: Color(0xFF5625BA),
|
||||||
|
|
|
@ -411,6 +411,7 @@ class Store extends StoreAPI {
|
||||||
res[i],
|
res[i],
|
||||||
client,
|
client,
|
||||||
states: getStatesFromRoomId(res[i]["room_id"]),
|
states: getStatesFromRoomId(res[i]["room_id"]),
|
||||||
|
roomAccountData: getAccountDataFromRoomId(res[i]["room_id"]),
|
||||||
);
|
);
|
||||||
roomList.add(room);
|
roomList.add(room);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:famedlysdk/famedlysdk.dart';
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
|
@ -27,11 +28,10 @@ class _ChatDetailsState extends State<ChatDetails> {
|
||||||
List<User> members;
|
List<User> members;
|
||||||
void setDisplaynameAction(BuildContext context, String displayname) async {
|
void setDisplaynameAction(BuildContext context, String displayname) async {
|
||||||
final MatrixState matrix = Matrix.of(context);
|
final MatrixState matrix = Matrix.of(context);
|
||||||
final Map<String, dynamic> success =
|
final success = await matrix.tryRequestWithLoadingDialog(
|
||||||
await matrix.tryRequestWithLoadingDialog(
|
|
||||||
widget.room.setName(displayname),
|
widget.room.setName(displayname),
|
||||||
);
|
);
|
||||||
if (success != null && success.isEmpty) {
|
if (success != false) {
|
||||||
Toast.show(
|
Toast.show(
|
||||||
"Displayname has been changed",
|
"Displayname has been changed",
|
||||||
context,
|
context,
|
||||||
|
@ -48,8 +48,7 @@ class _ChatDetailsState extends State<ChatDetails> {
|
||||||
maxHeight: 1600);
|
maxHeight: 1600);
|
||||||
if (tempFile == null) return;
|
if (tempFile == null) return;
|
||||||
final MatrixState matrix = Matrix.of(context);
|
final MatrixState matrix = Matrix.of(context);
|
||||||
final Map<String, dynamic> success =
|
final success = await matrix.tryRequestWithLoadingDialog(
|
||||||
await matrix.tryRequestWithLoadingDialog(
|
|
||||||
widget.room.setAvatar(
|
widget.room.setAvatar(
|
||||||
MatrixFile(
|
MatrixFile(
|
||||||
bytes: await tempFile.readAsBytes(),
|
bytes: await tempFile.readAsBytes(),
|
||||||
|
@ -57,7 +56,7 @@ class _ChatDetailsState extends State<ChatDetails> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (success != null && success.isEmpty) {
|
if (success != false) {
|
||||||
Toast.show(
|
Toast.show(
|
||||||
"Avatar has been changed",
|
"Avatar has been changed",
|
||||||
context,
|
context,
|
||||||
|
@ -72,13 +71,22 @@ class _ChatDetailsState extends State<ChatDetails> {
|
||||||
if (participants != null) setState(() => members = participants);
|
if (participants != null) setState(() => members = participants);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StreamSubscription onUpdate;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
onUpdate?.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
members ??= widget.room.getParticipants();
|
members ??= widget.room.getParticipants();
|
||||||
final int actualMembersCount =
|
final int actualMembersCount =
|
||||||
widget.room.mInvitedMemberCount + widget.room.mJoinedMemberCount;
|
widget.room.mInvitedMemberCount + widget.room.mJoinedMemberCount;
|
||||||
final bool canRequestMoreMembers = members.length < actualMembersCount;
|
final bool canRequestMoreMembers = members.length < actualMembersCount;
|
||||||
widget.room.onUpdate = () => setState(() => members = null);
|
this.onUpdate ??= widget.room.onUpdate.stream
|
||||||
|
.listen((id) => setState(() => members = null));
|
||||||
return AdaptivePageLayout(
|
return AdaptivePageLayout(
|
||||||
primaryPage: FocusPage.SECOND,
|
primaryPage: FocusPage.SECOND,
|
||||||
firstScaffold: ChatList(
|
firstScaffold: ChatList(
|
||||||
|
|
|
@ -82,8 +82,8 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: c78330ea58c36eec197803eb461681d84fa50f42
|
ref: "90a06ebce547ed853e501532a03491356a93e483"
|
||||||
resolved-ref: c78330ea58c36eec197803eb461681d84fa50f42
|
resolved-ref: "90a06ebce547ed853e501532a03491356a93e483"
|
||||||
url: "https://gitlab.com/famedly/famedlysdk.git"
|
url: "https://gitlab.com/famedly/famedlysdk.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.0.1"
|
version: "0.0.1"
|
||||||
|
|
|
@ -27,7 +27,7 @@ dependencies:
|
||||||
famedlysdk:
|
famedlysdk:
|
||||||
git:
|
git:
|
||||||
url: https://gitlab.com/famedly/famedlysdk.git
|
url: https://gitlab.com/famedly/famedlysdk.git
|
||||||
ref: c78330ea58c36eec197803eb461681d84fa50f42
|
ref: ae1c757e4ec3e7a41a2471e471d7ae47d974e821
|
||||||
|
|
||||||
localstorage: ^3.0.1+4
|
localstorage: ^3.0.1+4
|
||||||
bubble: ^1.1.9+1
|
bubble: ^1.1.9+1
|
||||||
|
|
Loading…
Reference in a new issue