Commit 1e047d57 authored by Wilko Manger's avatar Wilko Manger

Don't show invite and join events in direct chats

If the invite and join events are of this user
and the direct user.

Also always show a date header at the top.
parent 985b96ae
......@@ -18,7 +18,9 @@
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/ui/main/models/chat_item.dart';
import 'package:pattle/src/ui/main/sync_bloc.dart';
import 'package:pattle/src/ui/util/room.dart';
import 'package:rxdart/rxdart.dart';
import 'package:pattle/src/di.dart' as di;
class ChatBloc {
......@@ -26,14 +28,13 @@ class ChatBloc {
int _eventCount = 20;
static const ignoredEvents = [
RedactionEvent,
AvatarUrlChangeEvent
];
List<Type> get ignoredEvents => ignoredEventsOf(room, isOverview: false);
PublishSubject<bool> _isLoadingEventsSubj = PublishSubject<bool>();
Stream<bool> get isLoadingEvents => _isLoadingEventsSubj.stream.distinct();
final me = di.getLocalUser();
bool _isLoading = false;
bool get isLoading => _isLoading;
set isLoading(bool value) {
......@@ -73,15 +74,38 @@ class ChatBloc {
// Remember: 'previous' is actually next in time
RoomEvent previousEvent;
await for(RoomEvent event in room.timeline.upTo(_eventCount)) {
RoomEvent event;
await for(event in room.timeline.upTo(_eventCount)) {
var shouldIgnore = false;
// In direct chats, don't show the invite event between this user
// and the direct user.
//
// Also in direct chats, don't show the join events between this user
// and the direct user.
if (room.isDirect) {
if (event is InviteEvent) {
final iInvitedYou = event.sender.isIdenticalTo(me)
&& event.content.subject.isIdenticalTo(room.directUser);
final youInvitedMe = event.sender.isIdenticalTo(room.directUser)
&& event.content.subject.isIdenticalTo(me);
shouldIgnore = iInvitedYou || youInvitedMe;
} else if (event is JoinEvent) {
final subject = event.content.subject;
shouldIgnore = subject.isIdenticalTo(me)
|| subject.isIdenticalTo(room.directUser);
}
}
if (ignoredEvents.contains(event.runtimeType)) {
if (ignoredEvents.contains(event.runtimeType) || shouldIgnore) {
continue;
}
// Insert DateHeader if there's a day difference
if (previousEvent != null && event != null
&& previousEvent.time.day != event.time.day) {
&& previousEvent.time.day != event.time.day) {
chatItems.add(DateItem(previousEvent.time));
}
......@@ -90,6 +114,9 @@ class ChatBloc {
previousEvent = event;
}
// Add DateHeader above all events
chatItems.add(DateItem(event.time));
_itemSubj.add(List.of(chatItems));
}
......
......@@ -35,7 +35,7 @@ class DateHeader extends Item {
return Center(
child: Padding(
padding: EdgeInsets.only(
top: betweenMargin,
top: marginTop(),
bottom: betweenMargin
),
child: Text(formatAsDate(context, item.date).toUpperCase(),
......@@ -46,4 +46,8 @@ class DateHeader extends Item {
)
);
}
@override
double marginTop()
=> previousItem == null ? betweenMargin * 2 : betweenMargin;
}
\ No newline at end of file
......@@ -17,6 +17,7 @@
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/ui/main/overview/models/chat_overview.dart';
import 'package:pattle/src/ui/util/room.dart';
import 'package:rxdart/rxdart.dart';
import 'package:pattle/src/di.dart' as di;
import 'package:pattle/src/ui/main/sync_bloc.dart';
......@@ -30,17 +31,12 @@ class ChatOverviewBloc {
final LocalUser _user = di.getLocalUser();
static const ignoredEvents = [
RedactionEvent,
DisplayNameChangeEvent,
AvatarUrlChangeEvent
];
Future<void> loadChats() async {
var chats = List<ChatOverview>();
// Get all rooms and push them as a single list
await for(Room room in _user.rooms.all()) {
final ignoredEvents = ignoredEventsOf(room, isOverview: true);
// TODO: Add optional filter argument to up to call
final latestEvent = await room.timeline.all()
.firstWhere((event) => !ignoredEvents.contains(event.runtimeType), orElse: () => null);
......
......@@ -69,4 +69,17 @@ FutureOr<String> nameOf(BuildContext context, Room room) {
return name.isNotEmpty ? name : room.id.toString();
});
}
List<Type> ignoredEventsOf(Room room, {@required bool isOverview}) {
List<Type> ignored = [
RedactionEvent,
AvatarUrlChangeEvent
];
if (isOverview) {
ignored.add(DisplayNameChangeEvent);
}
return ignored;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment