Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite Timeline View to improve performance #258

Merged
merged 28 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a1c83fb
initial fix of over building
Airyzz Jun 4, 2024
d4bf7f2
slight refactor of new timeline view
Airyzz Jun 4, 2024
a002c2f
more work on reimplementation
Airyzz Jun 4, 2024
db04412
Update timeline_event_menu.dart
Airyzz Jun 4, 2024
994de47
Update timeline_event_view_url_previews.dart
Airyzz Jun 4, 2024
5d310e3
Fix getting wrong event in menu
Airyzz Jun 4, 2024
2afd82c
Reimplement message menu
Airyzz Jun 5, 2024
e340869
Reimplement generic timeline events
Airyzz Jun 5, 2024
fa8c44a
show timestamps
Airyzz Jun 5, 2024
1eb8f23
Handle encrypted events
Airyzz Jun 5, 2024
00f2a9f
Add date time marker
Airyzz Jun 5, 2024
dc1a023
Reimplement url previews
Airyzz Jun 5, 2024
3bcde77
Refresh url preview when message changes
Airyzz Jun 5, 2024
deab62c
Add edited marker
Airyzz Jun 5, 2024
73f4376
Update timeline_event_view_url_previews.dart
Airyzz Jun 5, 2024
9358dd5
Merge branch 'rewrite/timeline-events' of https://github.com/commetch…
Airyzz Jun 4, 2024
8fe9342
Add jump to latest button
Airyzz Jun 5, 2024
f7233dc
dont show time seperator on single event
Airyzz Jun 5, 2024
d9d8209
Handle read receipts
Airyzz Jun 5, 2024
45bfd58
only show preview if we should actually get one
Airyzz Jun 5, 2024
aa56fa9
Update timeline_event_view_url_previews.dart
Airyzz Jun 6, 2024
0277e9c
handle server not supporting url preview
Airyzz Jun 6, 2024
375403b
Update room_timeline_widget_view.dart
Airyzz Jun 6, 2024
0ae192d
Update room_timeline_widget.dart
Airyzz Jun 6, 2024
2f79e18
Only show image in url for supported image types
Airyzz Jun 7, 2024
8ae4062
clean up some logs
Airyzz Jun 7, 2024
824363f
Update matrix_client.dart
Airyzz Jun 7, 2024
e5ebf6e
fix warnings
Airyzz Jun 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Future<void> onForegroundMessage(dynamic message) async {
var room = client.getRoom(roomId);
var event = await room!.getEvent(eventId);

var user = room.getMemberOrFallback(event!.senderId)!;
var user = room.getMemberOrFallback(event!.senderId);

Log.i("Dispatching notification");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class UnifiedPushNotifier implements Notifier {
var room = client.getRoom(roomId);
var event = await room!.getEvent(eventId);

var user = room.getMemberOrFallback(event!.senderId)!;
var user = room.getMemberOrFallback(event!.senderId);

NotificationManager.notify(MessageNotificationContent(
senderName: user.displayName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import 'package:commet/client/room.dart';
import 'package:commet/client/timeline.dart';
import 'package:commet/debug/log.dart';
import 'package:commet/main.dart';
import 'package:commet/utils/mime.dart';
import 'package:flutter/widgets.dart';
import 'package:matrix/matrix.dart' as matrix;
import 'package:encrypted_url_preview/encrypted_url_preview.dart';
import 'package:matrix/matrix_api_lite.dart';

class MatrixUrlPreviewComponent implements UrlPreviewComponent<MatrixClient> {
@override
Expand All @@ -20,6 +22,8 @@ class MatrixUrlPreviewComponent implements UrlPreviewComponent<MatrixClient> {

EncryptedUrlPreview? privatePreviewGetter;

bool? serverSupportsUrlPreview;

void createPrivatePreviewGetter() {
privatePreviewGetter = EncryptedUrlPreview(
proxyServerUrl: Uri.https("telescope.commet.chat"),
Expand Down Expand Up @@ -62,7 +66,10 @@ pQIDAQAB
return null;
}

cache[uri.toString()] = data!;
if (data != null) {
cache[uri.toString()] = data;
}

return data;
}

Expand All @@ -82,6 +89,10 @@ pQIDAQAB
return false;
}

if (serverSupportsUrlPreview == false) {
return false;
}

return event.links?.isNotEmpty == true;
}

Expand Down Expand Up @@ -137,20 +148,46 @@ pQIDAQAB

Future<UrlPreviewData?> fetchPreviewData(
matrix.Client client, Uri url) async {
var response = await client.request(
matrix.RequestType.GET, "/media/v3/preview_url",
query: {"url": url.toString()});
late Map<String, Object?> response;
try {
response = await client.request(
matrix.RequestType.GET, "/media/v3/preview_url",
query: {"url": url.toString()});
} catch (e, s) {
if (e is MatrixException) {
if (e.error == MatrixError.M_UNRECOGNIZED) {
serverSupportsUrlPreview = false;
}
}

Log.onError(e, s);

return null;
}

serverSupportsUrlPreview = true;
var title = response['og:title'] as String?;
var siteName = response['og:site_name'] as String?;
var imageUrl = response['og:image'] as String?;
var description = response['og:description'] as String?;

var type = response["og:image:type"] as String?;
if (type != null) {
if (Mime.displayableTypes.contains(type) == false) {
imageUrl = null;
}
}

ImageProvider? image;
if (imageUrl != null) {
var imageUri = Uri.parse(imageUrl);
if (imageUri.scheme == "mxc") {
image = MatrixMxcImage(imageUri, client, doThumbnail: false);
try {
image = MatrixMxcImage(imageUri, client, doThumbnail: false);
} catch (exception, stack) {
Log.onError(exception, stack);
Log.w("Failed to get mxc image");
}
}
}

Expand Down
7 changes: 0 additions & 7 deletions commet/lib/client/matrix/matrix_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ class MatrixClient extends Client {
: matrix.NativeImplementationsIsolate(compute);

MatrixClient({required String identifier}) {
if (preferences.developerMode) {
matrix.Logs().level = matrix.Level.verbose;
}

_id = identifier;
_matrixClient = _createMatrixClient(identifier);
_matrixClient.onSync.stream.listen(onMatrixClientSync);
Expand Down Expand Up @@ -231,7 +227,6 @@ class MatrixClient extends Client {
}

void onMatrixClientSync(matrix.SyncUpdate update) {
Log.d("On Matrix Sync!");
_onSync.add(null);
_updateRoomslist();
_updateSpacesList();
Expand All @@ -257,8 +252,6 @@ class MatrixClient extends Client {
legacyDatabaseBuilder: (client) =>
getLegacyMatrixDatabase(client.clientName),
databaseBuilder: (client) => getMatrixDatabase(client.clientName),
logLevel:
BuildConfig.RELEASE ? matrix.Level.warning : matrix.Level.verbose,
);

client.onSyncStatus.stream.listen(onSyncStatusChanged);
Expand Down
26 changes: 13 additions & 13 deletions commet/lib/client/matrix/matrix_room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,13 @@ class MatrixRoom extends Room {
}
}

_onUpdateSubscription =
_matrixRoom.onUpdate.stream.listen(onMatrixRoomUpdate);
_onUpdateSubscription = _matrixRoom.client.onRoomState.stream
.where((event) => event.roomId == _matrixRoom.id)
.listen(onRoomStateUpdated);

_matrixRoom.client.onEvent.stream.listen(onEvent);
_matrixRoom.client.onEvent.stream
.where((event) => event.roomID == _matrixRoom.id)
.listen(onEvent);

_permissions = MatrixRoomPermissions(_matrixRoom);
}
Expand Down Expand Up @@ -238,10 +241,6 @@ class MatrixRoom extends Room {

var sender = getMemberOrFallback(event.senderId);

if (sender == null) {
return;
}

var notification = MessageNotificationContent(
senderName: sender.displayName,
senderId: sender.identifier,
Expand Down Expand Up @@ -371,9 +370,11 @@ class MatrixRoom extends Room {
await _matrixRoom.enableEncryption();
}

void onMatrixRoomUpdate(String event) async {
void onRoomStateUpdated(matrix.Event event) async {
_displayName = _matrixRoom.getLocalizedDisplayname();
_onUpdate.add(null);
if (event.type == "m.room.name") {
_onUpdate.add(null);
}
}

@override
Expand Down Expand Up @@ -509,7 +510,7 @@ class MatrixRoom extends Room {
bool get isMembersListComplete => _matrixRoom.participantListComplete;

@override
Member? getMemberOrFallback(String id) {
Member getMemberOrFallback(String id) {
return MatrixMember(
_matrixRoom.client, _matrixRoom.unsafeGetUserFromMemoryOrFallback(id));
}
Expand All @@ -522,9 +523,8 @@ class MatrixRoom extends Room {
var roles = (state.content["users"] as Map<String, dynamic>);
var ids = roles.keys;

var result = ids
.map((e) => (getMemberOrFallback(e)!, MatrixRole(roles[e])))
.toList();
var result =
ids.map((e) => (getMemberOrFallback(e), MatrixRole(roles[e]))).toList();

result.removeWhere((element) => element.$2.rank == 0);

Expand Down
6 changes: 5 additions & 1 deletion commet/lib/client/matrix/matrix_timeline_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ class MatrixTimelineEvent implements TimelineEvent {
}

@override
Widget buildFormattedContent() {
Widget? buildFormattedContent() {
if (formattedBody == null) {
return null;
}

return MatrixHtmlParser.parse(formattedBody!, event.room.client);
}

Expand Down
2 changes: 1 addition & 1 deletion commet/lib/client/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ abstract class Room {

Future<TimelineEvent?> getEvent(String eventId);

Member? getMemberOrFallback(String id);
Member getMemberOrFallback(String id);

@override
bool operator ==(Object other) {
Expand Down
2 changes: 1 addition & 1 deletion commet/lib/client/timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ abstract class TimelineEvent {
/// If you want to display the same message twice, use `buildFormattedContent()` to create a new widget
Widget? get formattedContent;

Widget buildFormattedContent();
Widget? buildFormattedContent();

String? get relatedEventId;
String? get stateKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class BackgroundNotificationsManager {
Log.i("Found room: ${room?.displayName}");

var event = await room!.getEvent(eventId);
var user = room.getMemberOrFallback(event!.senderId)!;
var user = room.getMemberOrFallback(event!.senderId);

Log.i("Got user: $user ($user)");
Log.i("Got event: ${event.body}");
Expand Down
2 changes: 1 addition & 1 deletion commet/lib/ui/atoms/emoji_reaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EmojiReaction extends StatelessWidget {
final int numReactions;
final bool highlighted;

BorderRadius get borderRadius => BorderRadius.circular(12);
BorderRadius get borderRadius => BorderRadius.circular(8);

@override
Widget build(BuildContext context) {
Expand Down
54 changes: 0 additions & 54 deletions commet/lib/ui/atoms/generic_room_event.dart

This file was deleted.

4 changes: 3 additions & 1 deletion commet/lib/ui/molecules/emoji_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class EmojiPicker extends StatelessWidget {
this.onlyEmoji = false,
this.onlyStickers = false,
this.staggered = false,
this.preferredTooltipDirection = AxisDirection.right,
this.packListAxis = Axis.vertical});
final void Function(Emoticon emoticon)? onEmoticonPressed;
final List<EmoticonPack> packs;
Expand All @@ -25,6 +26,7 @@ class EmojiPicker extends StatelessWidget {
final bool staggered;
final bool onlyStickers;
final bool onlyEmoji;
final AxisDirection preferredTooltipDirection;

final ItemScrollController itemScrollController = ItemScrollController();

Expand Down Expand Up @@ -112,7 +114,7 @@ class EmojiPicker extends StatelessWidget {
return SizedBox(
child: tiamat.Tooltip(
text: packs[index].displayName,
preferredDirection: AxisDirection.right,
preferredDirection: preferredTooltipDirection,
child: ImageButton(
size: packButtonSize,
iconSize: packButtonSize - 8,
Expand Down
Loading
Loading