develop-replyToMessages #67
lib
model/chatList
storage/talk
view
@ -1,16 +1,23 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../api/apiResponse.dart';
|
||||
import '../../api/marianumcloud/talk/chat/getChatCache.dart';
|
||||
import '../../api/marianumcloud/talk/chat/getChatResponse.dart';
|
||||
import '../../storage/base/settingsProvider.dart';
|
||||
import '../dataHolder.dart';
|
||||
|
||||
class ChatProps extends DataHolder {
|
||||
String _queryToken = '';
|
||||
DateTime _lastTokenSet = DateTime.now();
|
||||
int? referenceMessageId;
|
||||
int? _referenceMessageId;
|
||||
|
||||
GetChatResponse? _getChatResponse;
|
||||
GetChatResponse get getChatResponse => _getChatResponse!;
|
||||
|
||||
int? get getReferenceMessageId => _referenceMessageId;
|
||||
set unsafeInternalSetReferenceMessageId(int? reference) => _referenceMessageId = reference;
|
||||
|
||||
@override
|
||||
List<ApiResponse?> properties() => [_getChatResponse];
|
||||
|
||||
@ -31,9 +38,18 @@ class ChatProps extends DataHolder {
|
||||
);
|
||||
}
|
||||
|
||||
void setReferenceMessageId(int? messageId) {
|
||||
referenceMessageId = messageId;
|
||||
notifyListeners();
|
||||
void setReferenceMessageId(int? messageId, BuildContext context, String sendToToken) {
|
||||
Future.microtask(() {
|
||||
_referenceMessageId = messageId;
|
||||
notifyListeners();
|
||||
|
||||
var settings = Provider.of<SettingsProvider>(context, listen: false);
|
||||
if(messageId != null) {
|
||||
settings.val(write: true).talkSettings.draftReplies[sendToToken] = messageId;
|
||||
} else {
|
||||
settings.val(write: true).talkSettings.draftReplies.removeWhere((key, value) => key == sendToToken);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void setQueryToken(String token) {
|
||||
|
@ -7,8 +7,9 @@ class TalkSettings {
|
||||
bool sortFavoritesToTop;
|
||||
bool sortUnreadToTop;
|
||||
Map<String, String> drafts;
|
||||
Map<String, int> draftReplies;
|
||||
|
||||
TalkSettings({required this.sortFavoritesToTop, required this.sortUnreadToTop, required this.drafts});
|
||||
TalkSettings({required this.sortFavoritesToTop, required this.sortUnreadToTop, required this.drafts, required this.draftReplies});
|
||||
|
||||
factory TalkSettings.fromJson(Map<String, dynamic> json) => _$TalkSettingsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$TalkSettingsToJson(this);
|
||||
|
@ -10,6 +10,7 @@ TalkSettings _$TalkSettingsFromJson(Map<String, dynamic> json) => TalkSettings(
|
||||
sortFavoritesToTop: json['sortFavoritesToTop'] as bool,
|
||||
sortUnreadToTop: json['sortUnreadToTop'] as bool,
|
||||
drafts: Map<String, String>.from(json['drafts'] as Map),
|
||||
draftReplies: Map<String, int>.from(json['draftReplies'] as Map),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$TalkSettingsToJson(TalkSettings instance) =>
|
||||
@ -17,4 +18,5 @@ Map<String, dynamic> _$TalkSettingsToJson(TalkSettings instance) =>
|
||||
'sortFavoritesToTop': instance.sortFavoritesToTop,
|
||||
'sortUnreadToTop': instance.sortUnreadToTop,
|
||||
'drafts': instance.drafts,
|
||||
'draftReplies': instance.draftReplies,
|
||||
};
|
||||
|
@ -279,7 +279,7 @@ class _ChatBubbleState extends State<ChatBubble> with SingleTickerProviderStateM
|
||||
_position = const Offset(0, 0);
|
||||
});
|
||||
if(widget.bubbleData.isReplyable) {
|
||||
Provider.of<ChatProps>(context, listen: false).setReferenceMessageId(widget.bubbleData.id);
|
||||
Provider.of<ChatProps>(context, listen: false).setReferenceMessageId(widget.bubbleData.id, context, widget.chatData.token);
|
||||
}
|
||||
},
|
||||
onLongPress: showOptionsDialog,
|
||||
|
@ -1,6 +1,5 @@
|
||||
|
||||
import 'dart:io';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nextcloud/nextcloud.dart';
|
||||
import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';
|
||||
@ -81,7 +80,8 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
settings = Provider.of<SettingsProvider>(context, listen: false);
|
||||
Provider.of<ChatProps>(context, listen: false).referenceMessageId = null;
|
||||
Provider.of<ChatProps>(context, listen: false).unsafeInternalSetReferenceMessageId =
|
||||
settings.val().talkSettings.draftReplies[widget.sendToToken];
|
||||
}
|
||||
|
||||
@override
|
||||
@ -99,8 +99,8 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
children: [
|
||||
Consumer<ChatProps>(
|
||||
builder: (context, data, child) {
|
||||
if(data.referenceMessageId != null) {
|
||||
var referenceMessage = data.getChatResponse.sortByTimestamp().where((element) => element.id == data.referenceMessageId).last;
|
||||
if(data.getReferenceMessageId != null) {
|
||||
var referenceMessage = data.getChatResponse.sortByTimestamp().where((element) => element.id == data.getReferenceMessageId).last;
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
@ -111,7 +111,7 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => data.setReferenceMessageId(null),
|
||||
onPressed: () => data.setReferenceMessageId(null, context, widget.sendToToken),
|
||||
icon: const Icon(Icons.close_outlined),
|
||||
padding: const EdgeInsets.only(left: 0),
|
||||
),
|
||||
@ -194,7 +194,7 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
const SizedBox(width: 15),
|
||||
FloatingActionButton(
|
||||
mini: true,
|
||||
onPressed: (){
|
||||
onPressed: () {
|
||||
if(_textBoxController.text.isEmpty) return;
|
||||
if(isLoading) return;
|
||||
|
||||
@ -203,7 +203,7 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
});
|
||||
SendMessage(widget.sendToToken, SendMessageParams(
|
||||
_textBoxController.text,
|
||||
replyTo: Provider.of<ChatProps>(context, listen: false).referenceMessageId.toString()
|
||||
replyTo: Provider.of<ChatProps>(context, listen: false).getReferenceMessageId.toString()
|
||||
)).run().then((value) {
|
||||
_query();
|
||||
setState(() {
|
||||
@ -211,8 +211,8 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
});
|
||||
_textBoxController.text = '';
|
||||
setDraft('');
|
||||
Provider.of<ChatProps>(context, listen: false).setReferenceMessageId(null, context, widget.sendToToken);
|
||||
});
|
||||
Provider.of<ChatProps>(context, listen: false).referenceMessageId = null;
|
||||
},
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
elevation: 5,
|
||||
|
@ -29,6 +29,7 @@ class DefaultSettings {
|
||||
sortFavoritesToTop: true,
|
||||
sortUnreadToTop: false,
|
||||
drafts: {},
|
||||
draftReplies: {},
|
||||
),
|
||||
fileSettings: FileSettings(
|
||||
sortFoldersToTop: true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user