mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Display conversation
This commit is contained in:
		@@ -1,4 +1,6 @@
 | 
			
		||||
import 'package:comunic/helpers/conversations_helper.dart';
 | 
			
		||||
import 'package:comunic/models/conversation.dart';
 | 
			
		||||
import 'package:comunic/ui/screens/conversation_screen.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/safe_state.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/tablet_mode/conversations/conversation_window_container.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
@@ -28,13 +30,71 @@ class ConversationWindow extends StatefulWidget {
 | 
			
		||||
class _ConversationWindowState extends SafeState<ConversationWindow> {
 | 
			
		||||
  Conversation _conversation;
 | 
			
		||||
  String _convTitle;
 | 
			
		||||
  bool _error = false;
 | 
			
		||||
 | 
			
		||||
  int get _convID => widget.convID;
 | 
			
		||||
 | 
			
		||||
  void _setError(bool e) => setState(() => _error = e);
 | 
			
		||||
 | 
			
		||||
  Future<void> _refresh() async {
 | 
			
		||||
    try {
 | 
			
		||||
      _setError(false);
 | 
			
		||||
 | 
			
		||||
      final conversation =
 | 
			
		||||
          await ConversationsHelper().getSingle(_convID, force: true);
 | 
			
		||||
      assert(conversation != null);
 | 
			
		||||
      final name =
 | 
			
		||||
          await ConversationsHelper.getConversationNameAsync(conversation);
 | 
			
		||||
      assert(name != null);
 | 
			
		||||
 | 
			
		||||
      setState(() {
 | 
			
		||||
        _conversation = conversation;
 | 
			
		||||
        _convTitle = name;
 | 
			
		||||
      });
 | 
			
		||||
    } catch (e, s) {
 | 
			
		||||
      _setError(true);
 | 
			
		||||
      print("Could not refresh the list of conversations! $e\n$s");
 | 
			
		||||
      showSimpleSnack(context, tr("Could not load conversation information!"));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
    super.initState();
 | 
			
		||||
    _refresh();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    // In case of error
 | 
			
		||||
    if (_error)
 | 
			
		||||
      return ConversationWindowContainer(
 | 
			
		||||
        title: Text(tr("Error")),
 | 
			
		||||
        onClose: widget.onClose,
 | 
			
		||||
        body: buildErrorCard(tr("Could not load conversation information!"),
 | 
			
		||||
            actions: [
 | 
			
		||||
              FlatButton(
 | 
			
		||||
                textColor: Colors.white,
 | 
			
		||||
                onPressed: _refresh,
 | 
			
		||||
                child: Text(tr("Try again").toUpperCase()),
 | 
			
		||||
              )
 | 
			
		||||
            ]),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
    // If it is still loading
 | 
			
		||||
    if (_conversation == null)
 | 
			
		||||
      return ConversationWindowContainer(
 | 
			
		||||
        title: Text(tr("Loading...")),
 | 
			
		||||
        onClose: widget.onClose,
 | 
			
		||||
        body: buildCenteredProgressBar(),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
    return ConversationWindowContainer(
 | 
			
		||||
      title: Text(_convTitle),
 | 
			
		||||
      onClose: widget.onClose,
 | 
			
		||||
      body: ConversationScreen(
 | 
			
		||||
        conversationID: _convID,
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user