Remove flutter chat #26
3 changed files with 296 additions and 250 deletions
fix extra memberships
commit
211c088df9
|
|
@ -37,7 +37,8 @@ abstract class Event with _$Event {
|
||||||
@JsonKey(name: "last_edit_rowid") int? lastEditRowId,
|
@JsonKey(name: "last_edit_rowid") int? lastEditRowId,
|
||||||
@UnreadTypeConverter() UnreadType? unreadType,
|
@UnreadTypeConverter() UnreadType? unreadType,
|
||||||
@JsonKey(fromJson: Event.pmpFromJson) Profile? pmp,
|
@JsonKey(fromJson: Event.pmpFromJson) Profile? pmp,
|
||||||
@JsonKey(fromJson: Content.fromJson) required Content content,
|
required Content content,
|
||||||
|
required Content? previousContent,
|
||||||
}) = _Event;
|
}) = _Event;
|
||||||
|
|
||||||
factory Event.fromJson(Map<String, dynamic> json) =>
|
factory Event.fromJson(Map<String, dynamic> json) =>
|
||||||
|
|
@ -46,6 +47,12 @@ abstract class Event with _$Event {
|
||||||
json["decrypted"] ?? json["content"],
|
json["decrypted"] ?? json["content"],
|
||||||
json["decrypted_type"] ?? json["type"],
|
json["decrypted_type"] ?? json["type"],
|
||||||
),
|
),
|
||||||
|
previousContent: json["unsigned"]?["prev_content"] == null
|
||||||
|
? null
|
||||||
|
: Content.fromEventJson(
|
||||||
|
json["unsigned"]?["prev_content"],
|
||||||
|
json["decrypted_type"] ?? json["type"],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,9 +71,9 @@ class RenderEvent extends ConsumerWidget {
|
||||||
fontStyle: event.content is EmoteMessageContent ? FontStyle.italic : null,
|
fontStyle: event.content is EmoteMessageContent ? FontStyle.italic : null,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (event.redactedBy != null) return SizedBox.shrink();
|
final child = event.redactedBy != null
|
||||||
|
? null
|
||||||
final child = switch (event.content) {
|
: switch (event.content) {
|
||||||
Content(:final parseError?) => SelectableText(
|
Content(:final parseError?) => SelectableText(
|
||||||
"An error occurred while parsing this event:\n$parseError\n${parseError.stackTrace}",
|
"An error occurred while parsing this event:\n$parseError\n${parseError.stackTrace}",
|
||||||
style: errorStyle,
|
style: errorStyle,
|
||||||
|
|
@ -119,7 +119,10 @@ class RenderEvent extends ConsumerWidget {
|
||||||
: colorScheme.surfaceContainer,
|
: colorScheme.surfaceContainer,
|
||||||
|
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
padding: EdgeInsets.symmetric(
|
||||||
|
horizontal: 12,
|
||||||
|
vertical: 8,
|
||||||
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
|
@ -153,7 +156,8 @@ class RenderEvent extends ConsumerWidget {
|
||||||
) => Column(
|
) => Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
format == "org.matrix.custom.html" && !textOnly
|
format == "org.matrix.custom.html" &&
|
||||||
|
!textOnly
|
||||||
? Html(
|
? Html(
|
||||||
textStyle: textStyle,
|
textStyle: textStyle,
|
||||||
formattedBody!.replaceAllMapped(
|
formattedBody!.replaceAllMapped(
|
||||||
|
|
@ -179,7 +183,9 @@ class RenderEvent extends ConsumerWidget {
|
||||||
text: body,
|
text: body,
|
||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
options: LinkifyOptions(humanize: false),
|
options: LinkifyOptions(
|
||||||
|
humanize: false,
|
||||||
|
),
|
||||||
onOpen: (link) => ref
|
onOpen: (link) => ref
|
||||||
.watch(LaunchHelper.provider)
|
.watch(LaunchHelper.provider)
|
||||||
.launchUrl(Uri.parse(link.url)),
|
.launchUrl(Uri.parse(link.url)),
|
||||||
|
|
@ -191,14 +197,17 @@ class RenderEvent extends ConsumerWidget {
|
||||||
),
|
),
|
||||||
|
|
||||||
if (!textOnly)
|
if (!textOnly)
|
||||||
if (event.content case ImageMessageContent(
|
if (event.content
|
||||||
|
case ImageMessageContent(
|
||||||
:final url,
|
:final url,
|
||||||
:final info,
|
:final info,
|
||||||
))
|
))
|
||||||
switch (url?.mxcToHttps(
|
switch (url?.mxcToHttps(
|
||||||
ref.watch(
|
ref.watch(
|
||||||
ClientStateController.provider.select(
|
ClientStateController.provider
|
||||||
(value) => value!.homeserverUrl!,
|
.select(
|
||||||
|
(value) =>
|
||||||
|
value!.homeserverUrl!,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)) {
|
)) {
|
||||||
|
|
@ -216,14 +225,18 @@ class RenderEvent extends ConsumerWidget {
|
||||||
image: CachedNetworkImage(
|
image: CachedNetworkImage(
|
||||||
url.toString(),
|
url.toString(),
|
||||||
ref.watch(
|
ref.watch(
|
||||||
CrossCacheController.provider,
|
CrossCacheController
|
||||||
|
.provider,
|
||||||
),
|
),
|
||||||
headers: ref.headers,
|
headers: ref.headers,
|
||||||
),
|
),
|
||||||
width: info?.width,
|
width: info?.width,
|
||||||
loadingBuilder:
|
loadingBuilder:
|
||||||
(_, child, loadingProgress) =>
|
(
|
||||||
loadingProgress == null
|
_,
|
||||||
|
child,
|
||||||
|
loadingProgress,
|
||||||
|
) => loadingProgress == null
|
||||||
? child
|
? child
|
||||||
: switch (info?.blurHash) {
|
: switch (info?.blurHash) {
|
||||||
final blurHash? =>
|
final blurHash? =>
|
||||||
|
|
@ -243,8 +256,11 @@ class RenderEvent extends ConsumerWidget {
|
||||||
_ => Loading(),
|
_ => Loading(),
|
||||||
},
|
},
|
||||||
errorBuilder:
|
errorBuilder:
|
||||||
(context, error, stackTrace) =>
|
(
|
||||||
Center(
|
context,
|
||||||
|
error,
|
||||||
|
stackTrace,
|
||||||
|
) => Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
"Image Failed to Load",
|
"Image Failed to Load",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
|
|
@ -263,7 +279,8 @@ class RenderEvent extends ConsumerWidget {
|
||||||
style: errorStyle,
|
style: errorStyle,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
if (event.lastEditRowId != null && !textOnly)
|
if (event.lastEditRowId != null &&
|
||||||
|
!textOnly)
|
||||||
Text(
|
Text(
|
||||||
"(edited)",
|
"(edited)",
|
||||||
style: theme.textTheme.labelSmall,
|
style: theme.textTheme.labelSmall,
|
||||||
|
|
@ -279,7 +296,10 @@ class RenderEvent extends ConsumerWidget {
|
||||||
spacing: 8,
|
spacing: 8,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text("Unknown message type:", style: errorStyle),
|
Text(
|
||||||
|
"Unknown message type:",
|
||||||
|
style: errorStyle,
|
||||||
|
),
|
||||||
Text(body),
|
Text(body),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
@ -294,11 +314,18 @@ class RenderEvent extends ConsumerWidget {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
MembershipContent content => Row(
|
MembershipContent content =>
|
||||||
|
event.previousContent is MembershipContent &&
|
||||||
|
(event.previousContent as MembershipContent).status ==
|
||||||
|
content.status
|
||||||
|
? null
|
||||||
|
: Row(
|
||||||
spacing: 4,
|
spacing: 4,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(width: 4),
|
Padding(
|
||||||
Icon(Icons.people),
|
padding: EdgeInsets.symmetric(horizontal: 4),
|
||||||
|
child: Icon(Icons.people),
|
||||||
|
),
|
||||||
InkWell(
|
InkWell(
|
||||||
onTapUp: (details) => context.showUserPopover(
|
onTapUp: (details) => context.showUserPopover(
|
||||||
content,
|
content,
|
||||||
|
|
@ -320,15 +347,25 @@ class RenderEvent extends ConsumerWidget {
|
||||||
MembershipStatus.leave => event.sender == event.stateKey ? "left" : (event.unsigned["prev_content"]?["membership"] == "ban" ? "was unbanned from" : "was kicked from"),
|
MembershipStatus.leave => event.sender == event.stateKey ? "left" : (event.unsigned["prev_content"]?["membership"] == "ban" ? "was unbanned from" : "was kicked from"),
|
||||||
MembershipStatus.ban => "was banned from",
|
MembershipStatus.ban => "was banned from",
|
||||||
MembershipStatus.knock => "asked to join",
|
MembershipStatus.knock => "asked to join",
|
||||||
}} the room. ${content.reason ?? ""}",
|
}} the room${content.reason == null ? "" : "because ${content.reason}"}${event.sender == event.stateKey ? "" : " by "}",
|
||||||
|
),
|
||||||
|
if (event.sender != event.stateKey)
|
||||||
|
MessageDisplayname(
|
||||||
|
event,
|
||||||
|
style: TextStyle(
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
AvatarContent() => Row(
|
AvatarContent() => Row(
|
||||||
spacing: 4,
|
spacing: 4,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(width: 4),
|
Padding(
|
||||||
Icon(Icons.numbers),
|
padding: EdgeInsets.symmetric(horizontal: 4),
|
||||||
|
child: Icon(Icons.numbers),
|
||||||
|
),
|
||||||
MessageDisplayname(
|
MessageDisplayname(
|
||||||
event,
|
event,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
|
|
@ -342,14 +379,17 @@ class RenderEvent extends ConsumerWidget {
|
||||||
_ => null,
|
_ => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
return GestureDetector(
|
return child == null
|
||||||
onSecondaryTapUp: contextMenuCallback,
|
|
||||||
onLongPressStart: contextMenuCallback,
|
|
||||||
child: child == null
|
|
||||||
? textOnly
|
? textOnly
|
||||||
? Text("Unknown event type", style: errorStyle)
|
? Text("Unknown event type", style: errorStyle)
|
||||||
: SizedBox.shrink()
|
: SizedBox.shrink()
|
||||||
: Padding(padding: EdgeInsets.symmetric(vertical: 8), child: child),
|
: GestureDetector(
|
||||||
|
onSecondaryTapUp: contextMenuCallback,
|
||||||
|
onLongPressStart: contextMenuCallback,
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.symmetric(vertical: 8),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ class EventWrapper extends StatelessWidget {
|
||||||
duration: Duration(milliseconds: 250),
|
duration: Duration(milliseconds: 250),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
spacing: 4,
|
|
||||||
children: [
|
children: [
|
||||||
child,
|
child,
|
||||||
if (event.sendError != null && event.sendError != "not sent")
|
if (event.sendError != null && event.sendError != "not sent")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue