fix extra memberships
This commit is contained in:
parent
b3d1dc81b5
commit
211c088df9
3 changed files with 296 additions and 250 deletions
|
|
@ -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,285 +71,325 @@ 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,
|
||||||
),
|
),
|
||||||
MessageContent() || EncryptedContent() => Row(
|
MessageContent() || EncryptedContent() => Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
spacing: 8,
|
|
||||||
children: [
|
|
||||||
if (!textOnly)
|
|
||||||
if (isGrouped)
|
|
||||||
SizedBox(width: 40)
|
|
||||||
else
|
|
||||||
MessageAvatar(event, height: 40),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
spacing: 4,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
spacing: 8,
|
||||||
children: [
|
children: [
|
||||||
if (!isGrouped && !textOnly)
|
if (!textOnly)
|
||||||
Row(
|
if (isGrouped)
|
||||||
|
SizedBox(width: 40)
|
||||||
|
else
|
||||||
|
MessageAvatar(event, height: 40),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
spacing: 4,
|
spacing: 4,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Flexible(
|
if (!isGrouped && !textOnly)
|
||||||
child: MessageDisplayname(
|
Row(
|
||||||
event,
|
spacing: 4,
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
children: [
|
||||||
),
|
Flexible(
|
||||||
),
|
child: MessageDisplayname(
|
||||||
Flexible(child: timestamp),
|
event,
|
||||||
],
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
Card(
|
|
||||||
color:
|
|
||||||
ref.watch(
|
|
||||||
ClientStateController.provider.select(
|
|
||||||
(value) => value?.userId,
|
|
||||||
),
|
),
|
||||||
) ==
|
Flexible(child: timestamp),
|
||||||
event.sender
|
],
|
||||||
? (event.eventId.startsWith("~")
|
),
|
||||||
? colorScheme.onPrimary
|
Card(
|
||||||
: colorScheme.primaryContainer)
|
color:
|
||||||
: colorScheme.surfaceContainer,
|
ref.watch(
|
||||||
|
ClientStateController.provider.select(
|
||||||
|
(value) => value?.userId,
|
||||||
|
),
|
||||||
|
) ==
|
||||||
|
event.sender
|
||||||
|
? (event.eventId.startsWith("~")
|
||||||
|
? colorScheme.onPrimary
|
||||||
|
: colorScheme.primaryContainer)
|
||||||
|
: colorScheme.surfaceContainer,
|
||||||
|
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
padding: EdgeInsets.symmetric(
|
||||||
child: Column(
|
horizontal: 12,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
vertical: 8,
|
||||||
children: [
|
|
||||||
// Quoted( // TODO: Show replies
|
|
||||||
// EventText(replyEvent textOnly: true, maxLines: 1,)
|
|
||||||
// ),
|
|
||||||
switch (event.content) {
|
|
||||||
EncryptedContent() => Text(
|
|
||||||
"Unable to decrypt event",
|
|
||||||
style: errorStyle,
|
|
||||||
),
|
),
|
||||||
TextMessageContent(
|
child: Column(
|
||||||
:final body,
|
|
||||||
:final formattedBody,
|
|
||||||
:final format,
|
|
||||||
) ||
|
|
||||||
NoticeMessageContent(
|
|
||||||
:final body,
|
|
||||||
:final formattedBody,
|
|
||||||
:final format,
|
|
||||||
) ||
|
|
||||||
EmoteMessageContent(
|
|
||||||
:final body,
|
|
||||||
:final formattedBody,
|
|
||||||
:final format,
|
|
||||||
) ||
|
|
||||||
ImageMessageContent(
|
|
||||||
:final body,
|
|
||||||
:final formattedBody,
|
|
||||||
:final format,
|
|
||||||
) => Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
format == "org.matrix.custom.html" && !textOnly
|
// Quoted( // TODO: Show replies
|
||||||
? Html(
|
// EventText(replyEvent textOnly: true, maxLines: 1,)
|
||||||
textStyle: textStyle,
|
// ),
|
||||||
formattedBody!.replaceAllMapped(
|
switch (event.content) {
|
||||||
RegExp(
|
EncryptedContent() => Text(
|
||||||
"(<a\\b[^>]*>.*?<\\/a>)|(\\bhttps?:\\/\\/[^\\s<]+)",
|
"Unable to decrypt event",
|
||||||
caseSensitive: false,
|
style: errorStyle,
|
||||||
dotAll: true,
|
),
|
||||||
),
|
TextMessageContent(
|
||||||
(m) {
|
:final body,
|
||||||
// If it's already an <a> tag, leave it unchanged
|
:final formattedBody,
|
||||||
if (m.group(1) != null) {
|
:final format,
|
||||||
return m.group(1)!;
|
) ||
|
||||||
}
|
NoticeMessageContent(
|
||||||
|
:final body,
|
||||||
// Otherwise, wrap the bare URL
|
:final formattedBody,
|
||||||
final url = m.group(2)!;
|
:final format,
|
||||||
return "<a href=\"$url\">$url</a>";
|
) ||
|
||||||
},
|
EmoteMessageContent(
|
||||||
),
|
:final body,
|
||||||
)
|
:final formattedBody,
|
||||||
: Linkify(
|
:final format,
|
||||||
style: textStyle,
|
) ||
|
||||||
text: body,
|
ImageMessageContent(
|
||||||
maxLines: maxLines,
|
:final body,
|
||||||
overflow: TextOverflow.ellipsis,
|
:final formattedBody,
|
||||||
options: LinkifyOptions(humanize: false),
|
:final format,
|
||||||
onOpen: (link) => ref
|
) => Column(
|
||||||
.watch(LaunchHelper.provider)
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
.launchUrl(Uri.parse(link.url)),
|
children: [
|
||||||
linkStyle: TextStyle(
|
format == "org.matrix.custom.html" &&
|
||||||
color: Theme.of(
|
!textOnly
|
||||||
context,
|
? Html(
|
||||||
).colorScheme.primary,
|
textStyle: textStyle,
|
||||||
),
|
formattedBody!.replaceAllMapped(
|
||||||
),
|
RegExp(
|
||||||
|
"(<a\\b[^>]*>.*?<\\/a>)|(\\bhttps?:\\/\\/[^\\s<]+)",
|
||||||
if (!textOnly)
|
caseSensitive: false,
|
||||||
if (event.content case ImageMessageContent(
|
dotAll: true,
|
||||||
:final url,
|
|
||||||
:final info,
|
|
||||||
))
|
|
||||||
switch (url?.mxcToHttps(
|
|
||||||
ref.watch(
|
|
||||||
ClientStateController.provider.select(
|
|
||||||
(value) => value!.homeserverUrl!,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)) {
|
|
||||||
final url? => ConstrainedBox(
|
|
||||||
constraints: BoxConstraints.loose(
|
|
||||||
Size.fromWidth(500),
|
|
||||||
),
|
|
||||||
child: ExpandableImage(
|
|
||||||
url.toString(),
|
|
||||||
child: ClipRRect(
|
|
||||||
borderRadius: BorderRadius.all(
|
|
||||||
Radius.circular(8),
|
|
||||||
),
|
|
||||||
child: Image(
|
|
||||||
image: CachedNetworkImage(
|
|
||||||
url.toString(),
|
|
||||||
ref.watch(
|
|
||||||
CrossCacheController.provider,
|
|
||||||
),
|
),
|
||||||
headers: ref.headers,
|
(m) {
|
||||||
|
// If it's already an <a> tag, leave it unchanged
|
||||||
|
if (m.group(1) != null) {
|
||||||
|
return m.group(1)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, wrap the bare URL
|
||||||
|
final url = m.group(2)!;
|
||||||
|
return "<a href=\"$url\">$url</a>";
|
||||||
|
},
|
||||||
),
|
),
|
||||||
width: info?.width,
|
)
|
||||||
loadingBuilder:
|
: Linkify(
|
||||||
(_, child, loadingProgress) =>
|
style: textStyle,
|
||||||
loadingProgress == null
|
text: body,
|
||||||
? child
|
maxLines: maxLines,
|
||||||
: switch (info?.blurHash) {
|
overflow: TextOverflow.ellipsis,
|
||||||
final blurHash? =>
|
options: LinkifyOptions(
|
||||||
SizedBox(
|
humanize: false,
|
||||||
width:
|
),
|
||||||
info?.width ??
|
onOpen: (link) => ref
|
||||||
info?.height ??
|
.watch(LaunchHelper.provider)
|
||||||
200,
|
.launchUrl(Uri.parse(link.url)),
|
||||||
height:
|
linkStyle: TextStyle(
|
||||||
info?.height ??
|
color: Theme.of(
|
||||||
info?.width ??
|
context,
|
||||||
200,
|
).colorScheme.primary,
|
||||||
child: BlurHash(
|
),
|
||||||
hash: blurHash,
|
),
|
||||||
|
|
||||||
|
if (!textOnly)
|
||||||
|
if (event.content
|
||||||
|
case ImageMessageContent(
|
||||||
|
:final url,
|
||||||
|
:final info,
|
||||||
|
))
|
||||||
|
switch (url?.mxcToHttps(
|
||||||
|
ref.watch(
|
||||||
|
ClientStateController.provider
|
||||||
|
.select(
|
||||||
|
(value) =>
|
||||||
|
value!.homeserverUrl!,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)) {
|
||||||
|
final url? => ConstrainedBox(
|
||||||
|
constraints: BoxConstraints.loose(
|
||||||
|
Size.fromWidth(500),
|
||||||
|
),
|
||||||
|
child: ExpandableImage(
|
||||||
|
url.toString(),
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.all(
|
||||||
|
Radius.circular(8),
|
||||||
|
),
|
||||||
|
child: Image(
|
||||||
|
image: CachedNetworkImage(
|
||||||
|
url.toString(),
|
||||||
|
ref.watch(
|
||||||
|
CrossCacheController
|
||||||
|
.provider,
|
||||||
|
),
|
||||||
|
headers: ref.headers,
|
||||||
|
),
|
||||||
|
width: info?.width,
|
||||||
|
loadingBuilder:
|
||||||
|
(
|
||||||
|
_,
|
||||||
|
child,
|
||||||
|
loadingProgress,
|
||||||
|
) => loadingProgress == null
|
||||||
|
? child
|
||||||
|
: switch (info?.blurHash) {
|
||||||
|
final blurHash? =>
|
||||||
|
SizedBox(
|
||||||
|
width:
|
||||||
|
info?.width ??
|
||||||
|
info?.height ??
|
||||||
|
200,
|
||||||
|
height:
|
||||||
|
info?.height ??
|
||||||
|
info?.width ??
|
||||||
|
200,
|
||||||
|
child: BlurHash(
|
||||||
|
hash: blurHash,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
_ => Loading(),
|
||||||
|
},
|
||||||
|
errorBuilder:
|
||||||
|
(
|
||||||
|
context,
|
||||||
|
error,
|
||||||
|
stackTrace,
|
||||||
|
) => Center(
|
||||||
|
child: Text(
|
||||||
|
"Image Failed to Load",
|
||||||
|
style: TextStyle(
|
||||||
|
color: Theme.of(
|
||||||
|
context,
|
||||||
|
).colorScheme.error,
|
||||||
),
|
),
|
||||||
_ => Loading(),
|
|
||||||
},
|
|
||||||
errorBuilder:
|
|
||||||
(context, error, stackTrace) =>
|
|
||||||
Center(
|
|
||||||
child: Text(
|
|
||||||
"Image Failed to Load",
|
|
||||||
style: TextStyle(
|
|
||||||
color: Theme.of(
|
|
||||||
context,
|
|
||||||
).colorScheme.error,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
_ => Text(
|
||||||
|
"Nexus currently cannot handle encrypted media",
|
||||||
|
style: errorStyle,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
if (event.lastEditRowId != null &&
|
||||||
|
!textOnly)
|
||||||
|
Text(
|
||||||
|
"(edited)",
|
||||||
|
style: theme.textTheme.labelSmall,
|
||||||
),
|
),
|
||||||
),
|
if (linkify(body).firstWhereOrNull(
|
||||||
_ => Text(
|
(element) => element is UrlElement,
|
||||||
"Nexus currently cannot handle encrypted media",
|
)
|
||||||
|
case final UrlElement link?)
|
||||||
|
LinkPreview(link.url),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
MessageContent(:final body) => Row(
|
||||||
|
spacing: 8,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"Unknown message type:",
|
||||||
style: errorStyle,
|
style: errorStyle,
|
||||||
),
|
),
|
||||||
},
|
Text(body),
|
||||||
if (event.lastEditRowId != null && !textOnly)
|
],
|
||||||
Text(
|
|
||||||
"(edited)",
|
|
||||||
style: theme.textTheme.labelSmall,
|
|
||||||
),
|
),
|
||||||
if (linkify(body).firstWhereOrNull(
|
_ => throw Exception("This is impossible"),
|
||||||
(element) => element is UrlElement,
|
},
|
||||||
)
|
|
||||||
case final UrlElement link?)
|
|
||||||
LinkPreview(link.url),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
MessageContent(:final body) => Row(
|
),
|
||||||
spacing: 8,
|
),
|
||||||
mainAxisSize: MainAxisSize.min,
|
],
|
||||||
children: [
|
|
||||||
Text("Unknown message type:", style: errorStyle),
|
|
||||||
Text(body),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
_ => throw Exception("This is impossible"),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
MembershipContent content =>
|
||||||
],
|
event.previousContent is MembershipContent &&
|
||||||
),
|
(event.previousContent as MembershipContent).status ==
|
||||||
MembershipContent content => Row(
|
content.status
|
||||||
spacing: 4,
|
? null
|
||||||
children: [
|
: Row(
|
||||||
SizedBox(width: 4),
|
spacing: 4,
|
||||||
Icon(Icons.people),
|
children: [
|
||||||
InkWell(
|
Padding(
|
||||||
onTapUp: (details) => context.showUserPopover(
|
padding: EdgeInsets.symmetric(horizontal: 4),
|
||||||
content,
|
child: Icon(Icons.people),
|
||||||
event.sender,
|
),
|
||||||
globalPosition: details.globalPosition,
|
InkWell(
|
||||||
|
onTapUp: (details) => context.showUserPopover(
|
||||||
|
content,
|
||||||
|
event.sender,
|
||||||
|
globalPosition: details.globalPosition,
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
content.displayName ?? event.stateKey!.localpart,
|
||||||
|
style: TextStyle(
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
"${switch (content.status) {
|
||||||
|
MembershipStatus.invite => "was invited to",
|
||||||
|
MembershipStatus.join => "joined",
|
||||||
|
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 == 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: [
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 4),
|
||||||
|
child: Icon(Icons.numbers),
|
||||||
|
),
|
||||||
|
MessageDisplayname(
|
||||||
|
event,
|
||||||
|
style: TextStyle(
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text("changed the room avatar"),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
child: Text(
|
_ => null,
|
||||||
content.displayName ?? event.stateKey!.localpart,
|
};
|
||||||
style: TextStyle(
|
|
||||||
color: theme.colorScheme.primary,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
"${switch (content.status) {
|
|
||||||
MembershipStatus.invite => "was invited to",
|
|
||||||
MembershipStatus.join => "joined",
|
|
||||||
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 ?? ""}",
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
AvatarContent() => Row(
|
|
||||||
spacing: 4,
|
|
||||||
children: [
|
|
||||||
SizedBox(width: 4),
|
|
||||||
Icon(Icons.numbers),
|
|
||||||
MessageDisplayname(
|
|
||||||
event,
|
|
||||||
style: TextStyle(
|
|
||||||
color: theme.colorScheme.primary,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text("changed the room avatar"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
_ => null,
|
|
||||||
};
|
|
||||||
|
|
||||||
return GestureDetector(
|
return child == null
|
||||||
onSecondaryTapUp: contextMenuCallback,
|
? textOnly
|
||||||
onLongPressStart: contextMenuCallback,
|
? Text("Unknown event type", style: errorStyle)
|
||||||
child: child == null
|
: SizedBox.shrink()
|
||||||
? textOnly
|
: GestureDetector(
|
||||||
? Text("Unknown event type", style: errorStyle)
|
onSecondaryTapUp: contextMenuCallback,
|
||||||
: SizedBox.shrink()
|
onLongPressStart: contextMenuCallback,
|
||||||
: Padding(padding: EdgeInsets.symmetric(vertical: 8), child: child),
|
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