fix extra memberships

This commit is contained in:
Henry Hiles 2026-05-19 13:37:02 -04:00
commit 211c088df9
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
3 changed files with 296 additions and 250 deletions

View file

@ -37,7 +37,8 @@ abstract class Event with _$Event {
@JsonKey(name: "last_edit_rowid") int? lastEditRowId,
@UnreadTypeConverter() UnreadType? unreadType,
@JsonKey(fromJson: Event.pmpFromJson) Profile? pmp,
@JsonKey(fromJson: Content.fromJson) required Content content,
required Content content,
required Content? previousContent,
}) = _Event;
factory Event.fromJson(Map<String, dynamic> json) =>
@ -46,6 +47,12 @@ abstract class Event with _$Event {
json["decrypted"] ?? json["content"],
json["decrypted_type"] ?? json["type"],
),
previousContent: json["unsigned"]?["prev_content"] == null
? null
: Content.fromEventJson(
json["unsigned"]?["prev_content"],
json["decrypted_type"] ?? json["type"],
),
);
}

View file

@ -71,9 +71,9 @@ class RenderEvent extends ConsumerWidget {
fontStyle: event.content is EmoteMessageContent ? FontStyle.italic : null,
);
if (event.redactedBy != null) return SizedBox.shrink();
final child = switch (event.content) {
final child = event.redactedBy != null
? null
: switch (event.content) {
Content(:final parseError?) => SelectableText(
"An error occurred while parsing this event:\n$parseError\n${parseError.stackTrace}",
style: errorStyle,
@ -119,7 +119,10 @@ class RenderEvent extends ConsumerWidget {
: colorScheme.surfaceContainer,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
padding: EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@ -153,7 +156,8 @@ class RenderEvent extends ConsumerWidget {
) => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
format == "org.matrix.custom.html" && !textOnly
format == "org.matrix.custom.html" &&
!textOnly
? Html(
textStyle: textStyle,
formattedBody!.replaceAllMapped(
@ -179,7 +183,9 @@ class RenderEvent extends ConsumerWidget {
text: body,
maxLines: maxLines,
overflow: TextOverflow.ellipsis,
options: LinkifyOptions(humanize: false),
options: LinkifyOptions(
humanize: false,
),
onOpen: (link) => ref
.watch(LaunchHelper.provider)
.launchUrl(Uri.parse(link.url)),
@ -191,14 +197,17 @@ class RenderEvent extends ConsumerWidget {
),
if (!textOnly)
if (event.content case ImageMessageContent(
if (event.content
case ImageMessageContent(
:final url,
:final info,
))
switch (url?.mxcToHttps(
ref.watch(
ClientStateController.provider.select(
(value) => value!.homeserverUrl!,
ClientStateController.provider
.select(
(value) =>
value!.homeserverUrl!,
),
),
)) {
@ -216,14 +225,18 @@ class RenderEvent extends ConsumerWidget {
image: CachedNetworkImage(
url.toString(),
ref.watch(
CrossCacheController.provider,
CrossCacheController
.provider,
),
headers: ref.headers,
),
width: info?.width,
loadingBuilder:
(_, child, loadingProgress) =>
loadingProgress == null
(
_,
child,
loadingProgress,
) => loadingProgress == null
? child
: switch (info?.blurHash) {
final blurHash? =>
@ -243,8 +256,11 @@ class RenderEvent extends ConsumerWidget {
_ => Loading(),
},
errorBuilder:
(context, error, stackTrace) =>
Center(
(
context,
error,
stackTrace,
) => Center(
child: Text(
"Image Failed to Load",
style: TextStyle(
@ -263,7 +279,8 @@ class RenderEvent extends ConsumerWidget {
style: errorStyle,
),
},
if (event.lastEditRowId != null && !textOnly)
if (event.lastEditRowId != null &&
!textOnly)
Text(
"(edited)",
style: theme.textTheme.labelSmall,
@ -279,7 +296,10 @@ class RenderEvent extends ConsumerWidget {
spacing: 8,
mainAxisSize: MainAxisSize.min,
children: [
Text("Unknown message type:", style: errorStyle),
Text(
"Unknown message type:",
style: errorStyle,
),
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,
children: [
SizedBox(width: 4),
Icon(Icons.people),
Padding(
padding: EdgeInsets.symmetric(horizontal: 4),
child: Icon(Icons.people),
),
InkWell(
onTapUp: (details) => context.showUserPopover(
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.ban => "was banned from",
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(
spacing: 4,
children: [
SizedBox(width: 4),
Icon(Icons.numbers),
Padding(
padding: EdgeInsets.symmetric(horizontal: 4),
child: Icon(Icons.numbers),
),
MessageDisplayname(
event,
style: TextStyle(
@ -342,14 +379,17 @@ class RenderEvent extends ConsumerWidget {
_ => null,
};
return GestureDetector(
onSecondaryTapUp: contextMenuCallback,
onLongPressStart: contextMenuCallback,
child: child == null
return child == null
? textOnly
? Text("Unknown event type", style: errorStyle)
: SizedBox.shrink()
: Padding(padding: EdgeInsets.symmetric(vertical: 8), child: child),
: GestureDetector(
onSecondaryTapUp: contextMenuCallback,
onLongPressStart: contextMenuCallback,
child: Padding(
padding: EdgeInsets.symmetric(vertical: 8),
child: child,
),
);
}
}

View file

@ -27,7 +27,6 @@ class EventWrapper extends StatelessWidget {
duration: Duration(milliseconds: 250),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 4,
children: [
child,
if (event.sendError != null && event.sendError != "not sent")