Compare commits
2 commits
75adf443f2
...
310384f0e9
| Author | SHA1 | Date | |
|---|---|---|---|
|
310384f0e9 |
|||
|
eb87cbc17b |
6 changed files with 55 additions and 47 deletions
|
|
@ -231,10 +231,10 @@ class ClientController extends AsyncNotifier<int> {
|
||||||
Future<Paginate> paginate(PaginateRequest request) async =>
|
Future<Paginate> paginate(PaginateRequest request) async =>
|
||||||
Paginate.fromJson(await _sendCommand("paginate", request.toJson()));
|
Paginate.fromJson(await _sendCommand("paginate", request.toJson()));
|
||||||
|
|
||||||
Future<Profile> getProfile(String userId) async => Profile.fromJsonWithCatch({
|
Future<Profile> getProfile(String userId) async {
|
||||||
...(await _sendCommand("get_profile", {"user_id": userId})),
|
final json = await _sendCommand("get_profile", {"user_id": userId});
|
||||||
"id": userId,
|
return Profile.fromJsonWithCatch({...json, "id": userId});
|
||||||
});
|
}
|
||||||
|
|
||||||
Future<void> reportEvent(ReportRequest request) =>
|
Future<void> reportEvent(ReportRequest request) =>
|
||||||
_sendCommand("report_event", request.toJson());
|
_sendCommand("report_event", request.toJson());
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,6 @@ class ProfileController extends AsyncNotifier<Profile> {
|
||||||
return client.getProfile(userId);
|
return client.getProfile(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final provider =
|
static final provider = AsyncNotifierProvider.family
|
||||||
AsyncNotifierProvider.family<ProfileController, Profile, String>(
|
.autoDispose<ProfileController, Profile, String>(ProfileController.new);
|
||||||
ProfileController.new,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,16 +44,11 @@ class RoomChatController extends AsyncNotifier<IList<Event>> {
|
||||||
loadOlder();
|
loadOlder();
|
||||||
}
|
}
|
||||||
|
|
||||||
return IMap<int, int?>.fromValues(
|
return room.timeline
|
||||||
keyMapper: (id) => 9999999 + (id ?? 0),
|
.toValueIList(sort: true, compare: (a, b) => (a ?? 0).compareTo(b ?? 0))
|
||||||
values: room.sticky,
|
.addAll(room.sticky)
|
||||||
)
|
|
||||||
.addAll(room.timeline)
|
|
||||||
.toEntryIList(compare: (a, b) => (b?.key ?? 0).compareTo(a?.key ?? 0))
|
|
||||||
.map((entry) {
|
.map((entry) {
|
||||||
final foundEvent = entry.value == null
|
final foundEvent = entry == null ? null : room.events[entry];
|
||||||
? null
|
|
||||||
: room.events[entry.value!];
|
|
||||||
|
|
||||||
final editedEvent =
|
final editedEvent =
|
||||||
foundEvent == null || foundEvent.lastEditRowId == 0
|
foundEvent == null || foundEvent.lastEditRowId == 0
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,16 @@ part "membership.g.dart";
|
||||||
@freezed
|
@freezed
|
||||||
abstract class MembershipContent extends Content with _$MembershipContent {
|
abstract class MembershipContent extends Content with _$MembershipContent {
|
||||||
MembershipContent._();
|
MembershipContent._();
|
||||||
|
|
||||||
|
static String? displaynameFromJson(String? displayName) =>
|
||||||
|
displayName?.isEmpty == true ? null : displayName;
|
||||||
|
|
||||||
factory MembershipContent({
|
factory MembershipContent({
|
||||||
@JsonKey(name: "displayname") required String? displayName,
|
@JsonKey(
|
||||||
|
name: "displayname",
|
||||||
|
fromJson: MembershipContent.displaynameFromJson,
|
||||||
|
)
|
||||||
|
required String? displayName,
|
||||||
@JsonKey(name: "membership") required MembershipStatus status,
|
@JsonKey(name: "membership") required MembershipStatus status,
|
||||||
Uri? avatarUrl,
|
Uri? avatarUrl,
|
||||||
String? reason,
|
String? reason,
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,32 @@
|
||||||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||||
import "package:freezed_annotation/freezed_annotation.dart";
|
import "package:freezed_annotation/freezed_annotation.dart";
|
||||||
|
import "package:nexus/models/content/membership.dart";
|
||||||
part "profile.freezed.dart";
|
part "profile.freezed.dart";
|
||||||
part "profile.g.dart";
|
part "profile.g.dart";
|
||||||
|
|
||||||
Object? readPronouns(Map<dynamic, dynamic> map, _) =>
|
|
||||||
map["m.pronouns"] ?? map["io.fsky.nyx.pronouns"];
|
|
||||||
|
|
||||||
Object? readTimezone(Map<dynamic, dynamic> map, _) =>
|
|
||||||
map["m.tz"] ?? map["us.cloke.msc4175.tz"];
|
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
abstract class Profile with _$Profile {
|
abstract class Profile with _$Profile {
|
||||||
|
static Object? readPronouns(Map<dynamic, dynamic> map, _) =>
|
||||||
|
map["m.pronouns"] ?? map["io.fsky.nyx.pronouns"];
|
||||||
|
|
||||||
|
static Object? readTimezone(Map<dynamic, dynamic> map, _) =>
|
||||||
|
map["m.tz"] ?? map["us.cloke.msc4175.tz"];
|
||||||
|
|
||||||
const factory Profile({
|
const factory Profile({
|
||||||
required String id,
|
required String id,
|
||||||
String? parseError,
|
String? parseError,
|
||||||
Uri? avatarUrl,
|
Uri? avatarUrl,
|
||||||
@JsonKey(name: "displayname") String? displayName,
|
|
||||||
|
|
||||||
@JsonKey(readValue: readTimezone, name: "m.tz") String? timezone,
|
@JsonKey(
|
||||||
|
name: "displayname",
|
||||||
|
fromJson: MembershipContent.displaynameFromJson,
|
||||||
|
)
|
||||||
|
String? displayName,
|
||||||
|
|
||||||
|
@JsonKey(readValue: Profile.readTimezone, name: "m.tz") String? timezone,
|
||||||
|
|
||||||
@Default(IList.empty())
|
@Default(IList.empty())
|
||||||
@JsonKey(readValue: readPronouns, name: "io.fsky.nyx.pronouns")
|
@JsonKey(readValue: Profile.readPronouns, name: "io.fsky.nyx.pronouns")
|
||||||
IList<Pronoun> pronouns,
|
IList<Pronoun> pronouns,
|
||||||
}) = _Profile;
|
}) = _Profile;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,10 @@ class RoomChat extends HookConsumerWidget {
|
||||||
final client = ref.watch(ClientController.provider.notifier);
|
final client = ref.watch(ClientController.provider.notifier);
|
||||||
|
|
||||||
final listController = useRef(ListController());
|
final listController = useRef(ListController());
|
||||||
final scrollController = useScrollController();
|
final scrollController = useScrollController(
|
||||||
|
initialScrollOffset: 99999,
|
||||||
|
keys: [roomId],
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
Future<void> listener() async {
|
Future<void> listener() async {
|
||||||
|
|
@ -90,9 +93,9 @@ class RoomChat extends HookConsumerWidget {
|
||||||
if (room == null) return;
|
if (room == null) return;
|
||||||
|
|
||||||
if (scrollController.position.pixels == 0) {
|
if (scrollController.position.pixels == 0) {
|
||||||
await client.markRead(room);
|
|
||||||
} else {
|
|
||||||
if (room.hasMore) await notifier.loadOlder();
|
if (room.hasMore) await notifier.loadOlder();
|
||||||
|
} else {
|
||||||
|
await client.markRead(room);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -323,7 +326,6 @@ class RoomChat extends HookConsumerWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
final controllerData = ref.watch(controllerProvider);
|
final controllerData = ref.watch(controllerProvider);
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: RoomAppbar(
|
appBar: RoomAppbar(
|
||||||
roomId: roomId,
|
roomId: roomId,
|
||||||
|
|
@ -345,12 +347,19 @@ class RoomChat extends HookConsumerWidget {
|
||||||
child: switch (controllerData) {
|
child: switch (controllerData) {
|
||||||
AsyncData(:final value) ||
|
AsyncData(:final value) ||
|
||||||
AsyncLoading(:final value?) => CustomScrollView(
|
AsyncLoading(:final value?) => CustomScrollView(
|
||||||
reverse: true,
|
|
||||||
controller: scrollController,
|
controller: scrollController,
|
||||||
slivers: [
|
slivers: [
|
||||||
SliverPadding(
|
SliverToBoxAdapter(
|
||||||
padding: EdgeInsetsGeometry.only(
|
child: Padding(
|
||||||
bottom: composerSize.value,
|
padding: EdgeInsets.symmetric(vertical: 36),
|
||||||
|
child: Center(
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: controllerData is AsyncLoading
|
||||||
|
? null
|
||||||
|
: notifier.loadOlder,
|
||||||
|
child: Text("Load More"),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
@ -359,7 +368,7 @@ class RoomChat extends HookConsumerWidget {
|
||||||
itemCount: value.length,
|
itemCount: value.length,
|
||||||
itemBuilder: (_, index) {
|
itemBuilder: (_, index) {
|
||||||
final event = value[index];
|
final event = value[index];
|
||||||
final previousEvent = value.getOrNull(index + 1);
|
final previousEvent = value.getOrNull(index - 1);
|
||||||
return FlashWrapper(
|
return FlashWrapper(
|
||||||
EventRenderer(
|
EventRenderer(
|
||||||
event,
|
event,
|
||||||
|
|
@ -401,17 +410,9 @@ class RoomChat extends HookConsumerWidget {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
SliverToBoxAdapter(
|
SliverPadding(
|
||||||
child: Padding(
|
padding: EdgeInsetsGeometry.only(
|
||||||
padding: EdgeInsets.symmetric(vertical: 36),
|
bottom: composerSize.value,
|
||||||
child: Center(
|
|
||||||
child: controllerData is AsyncLoading
|
|
||||||
? Loading()
|
|
||||||
: ElevatedButton(
|
|
||||||
onPressed: notifier.loadOlder,
|
|
||||||
child: Text("Load More"),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue