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