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(
|
||||||
token,
|
"Push notifications disabled.",
|
||||||
"http",
|
context,
|
||||||
"chat.fluffy.fluffychat",
|
duration: Toast.LENGTH_LONG,
|
||||||
"FluffyChat",
|
|
||||||
client.deviceName,
|
|
||||||
"en",
|
|
||||||
"https://janian.de:7023/",
|
|
||||||
append: false,
|
|
||||||
format: "event_id_only",
|
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
await client.setPushers(
|
||||||
|
token,
|
||||||
|
"http",
|
||||||
|
"chat.fluffy.fluffychat",
|
||||||
|
widget.clientName,
|
||||||
|
client.deviceName,
|
||||||
|
"en",
|
||||||
|
"https://janian.de:7023/",
|
||||||
|
append: false,
|
||||||
|
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,102 +18,112 @@ 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:
|
||||||
if (textOnly) {
|
case EventTypes.Sticker:
|
||||||
return Text(
|
switch (event.messageType) {
|
||||||
"${event.sender.calcDisplayname()} has sent an image",
|
case MessageTypes.Image:
|
||||||
maxLines: maxLines,
|
case MessageTypes.Sticker:
|
||||||
style: TextStyle(
|
if (textOnly) {
|
||||||
color: textColor,
|
return Text(
|
||||||
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
"${event.sender.calcDisplayname()} has sent an image",
|
||||||
),
|
maxLines: maxLines,
|
||||||
);
|
style: TextStyle(
|
||||||
|
color: textColor,
|
||||||
|
decoration:
|
||||||
|
event.redacted ? TextDecoration.lineThrough : null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final int size = 400;
|
||||||
|
final String src = MxContent(event.content["url"]).getThumbnail(
|
||||||
|
Matrix.of(context).client,
|
||||||
|
width: size * MediaQuery.of(context).devicePixelRatio,
|
||||||
|
height: size * MediaQuery.of(context).devicePixelRatio,
|
||||||
|
method: ThumbnailMethod.scale,
|
||||||
|
);
|
||||||
|
return Bubble(
|
||||||
|
padding: BubbleEdges.all(0),
|
||||||
|
radius: Radius.circular(10),
|
||||||
|
elevation: 0,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () => launch(
|
||||||
|
MxContent(event.content["url"])
|
||||||
|
.getDownloadLink(Matrix.of(context).client),
|
||||||
|
),
|
||||||
|
child: kIsWeb
|
||||||
|
? Image.network(
|
||||||
|
src,
|
||||||
|
width: size.toDouble(),
|
||||||
|
)
|
||||||
|
: CachedNetworkImage(
|
||||||
|
imageUrl: src,
|
||||||
|
width: size.toDouble(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
case MessageTypes.Audio:
|
||||||
|
case MessageTypes.File:
|
||||||
|
case MessageTypes.Video:
|
||||||
|
return Container(
|
||||||
|
width: 200,
|
||||||
|
child: RaisedButton(
|
||||||
|
color: Colors.blueGrey,
|
||||||
|
child: Text(
|
||||||
|
"Download ${event.getBody()}",
|
||||||
|
overflow: TextOverflow.fade,
|
||||||
|
softWrap: false,
|
||||||
|
maxLines: 1,
|
||||||
|
),
|
||||||
|
onPressed: () => launch(
|
||||||
|
MxContent(event.content["url"])
|
||||||
|
.getDownloadLink(Matrix.of(context).client),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
case MessageTypes.Text:
|
||||||
|
case MessageTypes.Reply:
|
||||||
|
case MessageTypes.Location:
|
||||||
|
case MessageTypes.None:
|
||||||
|
case MessageTypes.Notice:
|
||||||
|
final String senderPrefix =
|
||||||
|
textOnly && event.senderId != event.room.directChatMatrixID
|
||||||
|
? event.senderId == Matrix.of(context).client.userID
|
||||||
|
? "You: "
|
||||||
|
: "${event.sender.calcDisplayname()}: "
|
||||||
|
: "";
|
||||||
|
return Text(
|
||||||
|
senderPrefix + event.getBody(),
|
||||||
|
maxLines: maxLines,
|
||||||
|
overflow: textOnly ? TextOverflow.ellipsis : null,
|
||||||
|
style: TextStyle(
|
||||||
|
color: textColor,
|
||||||
|
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
case MessageTypes.Emote:
|
||||||
|
return Text(
|
||||||
|
"* " + event.getBody(),
|
||||||
|
maxLines: maxLines,
|
||||||
|
overflow: textOnly ? TextOverflow.ellipsis : null,
|
||||||
|
style: TextStyle(
|
||||||
|
color: textColor,
|
||||||
|
fontStyle: FontStyle.italic,
|
||||||
|
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
final int size = 400;
|
return unknown;
|
||||||
final String src = MxContent(event.content["url"]).getThumbnail(
|
|
||||||
Matrix.of(context).client,
|
|
||||||
width: size * MediaQuery.of(context).devicePixelRatio,
|
|
||||||
height: size * MediaQuery.of(context).devicePixelRatio,
|
|
||||||
method: ThumbnailMethod.scale,
|
|
||||||
);
|
|
||||||
return Bubble(
|
|
||||||
padding: BubbleEdges.all(0),
|
|
||||||
radius: Radius.circular(10),
|
|
||||||
elevation: 0,
|
|
||||||
child: InkWell(
|
|
||||||
onTap: () => launch(
|
|
||||||
MxContent(event.content["url"])
|
|
||||||
.getDownloadLink(Matrix.of(context).client),
|
|
||||||
),
|
|
||||||
child: kIsWeb
|
|
||||||
? Image.network(
|
|
||||||
src,
|
|
||||||
width: size.toDouble(),
|
|
||||||
)
|
|
||||||
: CachedNetworkImage(
|
|
||||||
imageUrl: src,
|
|
||||||
width: size.toDouble(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
case EventTypes.Audio:
|
|
||||||
case EventTypes.File:
|
|
||||||
case EventTypes.Video:
|
|
||||||
return Container(
|
|
||||||
width: 200,
|
|
||||||
child: RaisedButton(
|
|
||||||
color: Colors.blueGrey,
|
|
||||||
child: Text(
|
|
||||||
"Download ${event.getBody()}",
|
|
||||||
overflow: TextOverflow.fade,
|
|
||||||
softWrap: false,
|
|
||||||
maxLines: 1,
|
|
||||||
),
|
|
||||||
onPressed: () => launch(
|
|
||||||
MxContent(event.content["url"])
|
|
||||||
.getDownloadLink(Matrix.of(context).client),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
case EventTypes.Text:
|
|
||||||
case EventTypes.Reply:
|
|
||||||
case EventTypes.Notice:
|
|
||||||
final String senderPrefix =
|
|
||||||
textOnly && event.senderId != event.room.directChatMatrixID
|
|
||||||
? event.senderId == Matrix.of(context).client.userID
|
|
||||||
? "You: "
|
|
||||||
: "${event.sender.calcDisplayname()}: "
|
|
||||||
: "";
|
|
||||||
if (textOnly) {
|
|
||||||
return Text(
|
|
||||||
senderPrefix + event.getBody(),
|
|
||||||
maxLines: maxLines,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: TextStyle(
|
|
||||||
color: textColor,
|
|
||||||
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return LinkText(
|
|
||||||
text: senderPrefix + event.getBody(),
|
|
||||||
textStyle: TextStyle(
|
|
||||||
color: textColor,
|
|
||||||
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
case EventTypes.Emote:
|
|
||||||
return Text(
|
|
||||||
"* " + event.getBody(),
|
|
||||||
maxLines: maxLines,
|
|
||||||
overflow: textOnly ? TextOverflow.ellipsis : null,
|
|
||||||
style: TextStyle(
|
|
||||||
color: textColor,
|
|
||||||
fontStyle: FontStyle.italic,
|
|
||||||
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
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