feat: mural feed com criador, descricao e contador de inscritos
This commit is contained in:
@@ -3,11 +3,13 @@
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:tatchat/l10n/l10n.dart';
|
||||
import 'package:tatchat/pages/chat_list/chat_list.dart';
|
||||
import 'package:tatchat/pages/chat_list/chat_list_item.dart';
|
||||
import 'package:tatchat/pages/chat_list/mural_list_item.dart';
|
||||
import 'package:tatchat/pages/chat_list/tabs/chat_tab_header.dart';
|
||||
import 'package:tatchat/pages/chat_list/tabs/empty_tab_view.dart';
|
||||
import 'package:tatchat/pages/chat_list/tabs/home_tab.dart';
|
||||
@@ -28,6 +30,7 @@ class MuralsTab extends StatefulWidget {
|
||||
class _MuralsTabState extends State<MuralsTab> {
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final FocusNode _searchFocusNode = FocusNode();
|
||||
final Set<String> _loadingRooms = {};
|
||||
bool _isSearchMode = false;
|
||||
|
||||
@override
|
||||
@@ -37,6 +40,25 @@ class _MuralsTabState extends State<MuralsTab> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Loads the missing state events (e.g. `m.room.topic` and `m.room.create`)
|
||||
/// of a mural room so that its description and creator are already visible in
|
||||
/// the list without having to open the mural first.
|
||||
Future<void> _loadMissingRoomState(Room room) async {
|
||||
final roomId = room.id;
|
||||
try {
|
||||
final stateEvents = await room.client.getRoomState(roomId);
|
||||
for (final state in stateEvents) {
|
||||
room.setState(StrippedStateEvent.fromJson(state.toJson()));
|
||||
}
|
||||
if (!mounted) return;
|
||||
setState(() {});
|
||||
} catch (_) {
|
||||
// State loading is best-effort, ignore failures (e.g. offline).
|
||||
} finally {
|
||||
_loadingRooms.remove(roomId);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final client = Matrix.of(context).client;
|
||||
@@ -91,15 +113,23 @@ class _MuralsTabState extends State<MuralsTab> {
|
||||
itemCount: murals.length,
|
||||
itemBuilder: (context, i) {
|
||||
final room = murals[i];
|
||||
final roomId = room.id;
|
||||
if ((room.topic.isEmpty || room.creatorUserIds.isEmpty) &&
|
||||
!_loadingRooms.contains(roomId)) {
|
||||
_loadingRooms.add(roomId);
|
||||
unawaited(_loadMissingRoomState(room));
|
||||
}
|
||||
final creatorId = room.creatorUserIds.isEmpty
|
||||
? null
|
||||
: room.creatorUserIds.first;
|
||||
final creatorState = creatorId == null
|
||||
? null
|
||||
: room.getState(EventTypes.RoomMember, creatorId);
|
||||
return ChatListItem(
|
||||
final creatorDisplayName = creatorState?.content
|
||||
.tryGet<String>('displayname');
|
||||
return MuralListItem(
|
||||
room,
|
||||
key: Key('mural_list_item_${room.id}'),
|
||||
key: Key('mural_list_item_$roomId'),
|
||||
onTap: () => widget.controller.onChatTap(room),
|
||||
onLongPress: (context) =>
|
||||
widget.controller.chatContextAction(room, context),
|
||||
@@ -108,9 +138,9 @@ class _MuralsTabState extends State<MuralsTab> {
|
||||
creatorState?.content.tryGet<String>('avatar_url') ??
|
||||
'',
|
||||
),
|
||||
displayAvatarName: creatorState?.content.tryGet<String>(
|
||||
'displayname',
|
||||
),
|
||||
displayAvatarName: creatorDisplayName,
|
||||
creatorName: creatorDisplayName ?? creatorId,
|
||||
description: room.topic,
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user