show messages whilst sending
This commit is contained in:
parent
d9f62a9de9
commit
b836c3b06e
5 changed files with 51 additions and 35 deletions
|
|
@ -15,7 +15,6 @@ import "package:nexus/controllers/top_level_spaces_controller.dart";
|
|||
import "package:nexus/helpers/extensions/gomuks_buffer.dart";
|
||||
import "package:nexus/main.dart";
|
||||
import "package:nexus/models/client_state.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
import "package:nexus/models/event.dart";
|
||||
import "package:nexus/models/paginate.dart";
|
||||
import "package:nexus/models/requests/get_event_request.dart";
|
||||
|
|
@ -79,10 +78,17 @@ class ClientController extends AsyncNotifier<int> {
|
|||
break;
|
||||
case "send_complete":
|
||||
final event = Event.fromJson(decodedMuksEvent["event"]);
|
||||
ref
|
||||
.watch(RoomsController.provider.notifier)
|
||||
.update(
|
||||
{
|
||||
event.roomId: Room(
|
||||
events: {event.rowId: event}.toIMap(),
|
||||
),
|
||||
}.toIMap(),
|
||||
const ISet.empty(),
|
||||
);
|
||||
|
||||
if (event.type == EventType.message.type) {
|
||||
// ref.watch(provider.notifier).addEvent(event); TODO
|
||||
}
|
||||
break;
|
||||
case "sync_complete":
|
||||
final syncData = SyncData.fromJson(decodedMuksEvent);
|
||||
|
|
|
|||
|
|
@ -44,12 +44,16 @@ class RoomChatController extends AsyncNotifier<IList<Event>> {
|
|||
loadOlder();
|
||||
}
|
||||
|
||||
return room.timeline
|
||||
return IMap<int, int?>.fromValues(
|
||||
keyMapper: (id) => 9999999 + (id ?? 0),
|
||||
values: room.sticky,
|
||||
)
|
||||
.addAll(room.timeline)
|
||||
.toEntryIList(compare: (a, b) => (b?.key ?? 0).compareTo(a?.key ?? 0))
|
||||
.map((entry) {
|
||||
if (entry.value == null) return null;
|
||||
|
||||
final foundEvent = room.events[entry.value!];
|
||||
final foundEvent = entry.value == null
|
||||
? null
|
||||
: room.events[entry.value!];
|
||||
|
||||
final editedEvent =
|
||||
foundEvent == null || foundEvent.lastEditRowId == 0
|
||||
|
|
@ -153,23 +157,17 @@ class RoomChatController extends AsyncNotifier<IList<Event>> {
|
|||
),
|
||||
);
|
||||
|
||||
// TODO: Add new event to timeline whilst its sending
|
||||
// ref
|
||||
// .watch(RoomsController.provider.notifier)
|
||||
// .update(
|
||||
// {
|
||||
// roomId: Room(
|
||||
// events: [event].toIList(),
|
||||
// timeline: [
|
||||
// TimelineRowTuple(
|
||||
// timelineRowId: event.timelineRowId,
|
||||
// eventRowId: event.rowId,
|
||||
// ),
|
||||
// ].toIList(),
|
||||
// ),
|
||||
// }.toIMap(),
|
||||
// const ISet.empty(),
|
||||
// );
|
||||
ref
|
||||
.watch(RoomsController.provider.notifier)
|
||||
.update(
|
||||
{
|
||||
roomId: Room(
|
||||
events: {event.rowId: event}.toIMap(),
|
||||
sticky: {event.rowId}.toISet(),
|
||||
),
|
||||
}.toIMap(),
|
||||
const ISet.empty(),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> removeReaction(
|
||||
|
|
|
|||
|
|
@ -50,6 +50,13 @@ class RoomsController extends Notifier<IMap<String, Room>> {
|
|||
roomId,
|
||||
existing?.copyWith(
|
||||
hasMore: incoming.hasMore,
|
||||
sticky:
|
||||
(incoming.sticky.isEmpty == true
|
||||
? existing.sticky
|
||||
: existing.sticky.addAll(incoming.sticky))
|
||||
.removeWhere(
|
||||
(rowId) => incoming.timeline.values.contains(rowId),
|
||||
),
|
||||
metadata: incoming.metadata ?? existing.metadata,
|
||||
events: incoming.events.isEmpty
|
||||
? existing.events
|
||||
|
|
|
|||
|
|
@ -28,11 +28,13 @@ abstract class Room with _$Room {
|
|||
|
||||
/// [timeline] is an IMap of timelineRowId to eventRowId
|
||||
/// [events] is an IMap of eventRowId to event
|
||||
/// [sticky] is an ISet of eventRowId
|
||||
const factory Room({
|
||||
@JsonKey(name: "meta") RoomMetadata? metadata,
|
||||
@Default(IMap.empty())
|
||||
@JsonKey(fromJson: Room.timelineTupleJsonToIMap)
|
||||
IMap<int, int?> timeline,
|
||||
@Default(ISet.empty()) ISet<int> sticky,
|
||||
|
||||
@Default(IMap.empty())
|
||||
@JsonKey(fromJson: Room.eventsJsonToIMap)
|
||||
|
|
|
|||
|
|
@ -446,19 +446,22 @@ class EventRenderer extends ConsumerWidget {
|
|||
),
|
||||
),
|
||||
|
||||
if (event.content is! MessageContent)
|
||||
Padding(
|
||||
padding: EdgeInsetsGeometry.only(left: 12),
|
||||
child: ReactionRow(event),
|
||||
),
|
||||
...[
|
||||
if (event.content is! MessageContent) ReactionRow(event),
|
||||
|
||||
if (event.sendError != null && event.sendError != "not sent")
|
||||
Text(
|
||||
event.sendError!,
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
color: theme.colorScheme.error,
|
||||
if (event.sendError != null && event.sendError != "not sent")
|
||||
Text(
|
||||
event.sendError!,
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
color: theme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
].map(
|
||||
(child) => Padding(
|
||||
padding: EdgeInsetsGeometry.only(left: 4),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
] else if (textOnly)
|
||||
Text("Unknown event type", style: errorStyle),
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue