Remove flutter chat #26
3 changed files with 47 additions and 40 deletions
fix PMP rendering, add grouping
commit
5c6cc1d584
|
|
@ -8,11 +8,6 @@ part "event.g.dart";
|
|||
|
||||
@freezed
|
||||
abstract class Event with _$Event {
|
||||
static Profile? pmpFromJson(Map<String, dynamic>? json) {
|
||||
final pmp = json?["content"]?["com.beeper.per_message_profile"];
|
||||
return pmp == null ? null : Profile.fromJsonWithCatch(pmp);
|
||||
}
|
||||
|
||||
static String typeJsonFromJson(Map<dynamic, dynamic> json, _) =>
|
||||
json["decrypted_type"] ?? json["type"];
|
||||
|
||||
|
|
@ -43,7 +38,7 @@ abstract class Event with _$Event {
|
|||
@Default(IMap.empty()) IMap<String, int> reactions,
|
||||
@JsonKey(name: "last_edit_rowid") @Default(0) int lastEditRowId,
|
||||
@UnreadTypeConverter() UnreadType? unreadType,
|
||||
@JsonKey(fromJson: Event.pmpFromJson) Profile? pmp,
|
||||
Profile? pmp,
|
||||
required Content content,
|
||||
required Content? previousContent,
|
||||
}) = _Event;
|
||||
|
|
@ -53,6 +48,11 @@ abstract class Event with _$Event {
|
|||
replyTo: getContentFromJson(
|
||||
json,
|
||||
)["m.relates_to"]?["m.in_reply_to"]?["event_id"],
|
||||
pmp: json["content"]?["com.beeper.per_message_profile"] == null
|
||||
? null
|
||||
: Profile.fromJsonWithCatch(
|
||||
json["content"]?["com.beeper.per_message_profile"],
|
||||
),
|
||||
content: Content.fromEventJson(
|
||||
getContentFromJson(json),
|
||||
json["decrypted_type"] ?? json["type"],
|
||||
|
|
|
|||
|
|
@ -441,7 +441,9 @@ class EventRenderer extends ConsumerWidget {
|
|||
onSecondaryTapUp: contextMenuCallback,
|
||||
onLongPressStart: contextMenuCallback,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 8),
|
||||
padding: isGrouped
|
||||
? EdgeInsets.zero
|
||||
: EdgeInsets.symmetric(vertical: 8),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -333,39 +333,44 @@ class RoomChat extends HookConsumerWidget {
|
|||
SuperSliverList.builder(
|
||||
listController: listController.value,
|
||||
itemCount: value.length,
|
||||
itemBuilder: (_, index) => EventWrapper(
|
||||
value[index],
|
||||
EventRenderer(
|
||||
value[index],
|
||||
onTapReply: () async {
|
||||
final replyId = value[index].replyTo;
|
||||
listController.value.animateToItem(
|
||||
index: value.indexWhere(
|
||||
(element) => element.eventId == replyId,
|
||||
),
|
||||
scrollController: scrollController,
|
||||
alignment: 0.5,
|
||||
duration: (_) =>
|
||||
Duration(milliseconds: 700),
|
||||
curve: (_) => Curves.easeInOut,
|
||||
);
|
||||
flashingEvent.value = replyId;
|
||||
await Future.delayed(
|
||||
Duration(seconds: 1),
|
||||
() {
|
||||
if (flashingEvent.value == replyId) {
|
||||
flashingEvent.value = null;
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
getEventOptions: getEventOptions,
|
||||
// TODO: Reimplement grouping
|
||||
isGrouped: false,
|
||||
),
|
||||
isFlashing:
|
||||
flashingEvent.value == value[index].eventId,
|
||||
),
|
||||
itemBuilder: (_, index) {
|
||||
final event = value[index];
|
||||
final previousEvent = value.getOrNull(index - 1);
|
||||
return EventWrapper(
|
||||
event,
|
||||
EventRenderer(
|
||||
event,
|
||||
onTapReply: () async {
|
||||
final replyId = event.replyTo;
|
||||
listController.value.animateToItem(
|
||||
index: value.indexWhere(
|
||||
(element) => element.eventId == replyId,
|
||||
),
|
||||
scrollController: scrollController,
|
||||
alignment: 0.5,
|
||||
duration: (_) =>
|
||||
Duration(milliseconds: 700),
|
||||
curve: (_) => Curves.easeInOut,
|
||||
);
|
||||
flashingEvent.value = replyId;
|
||||
await Future.delayed(
|
||||
Duration(seconds: 1),
|
||||
() {
|
||||
if (flashingEvent.value == replyId) {
|
||||
flashingEvent.value = null;
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
getEventOptions: getEventOptions,
|
||||
isGrouped:
|
||||
"${event.sender}${event.pmp?.id}" ==
|
||||
"${previousEvent?.sender}${previousEvent?.pmp?.id}",
|
||||
),
|
||||
isFlashing:
|
||||
flashingEvent.value == event.eventId,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue