Browse Source

GetMessage* on android; make reply to use message cache; New Messages bubble doesn't reup

replyFix
Dan Ballard 4 weeks ago
parent
commit
e6c9f7becb
  1. 6
      android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt
  2. 2
      lib/models/contact.dart
  3. 18
      lib/views/messageview.dart

6
android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt

@ -341,21 +341,21 @@ class MainActivity: FlutterActivity() {
val profile: String = call.argument("ProfileOnion") ?: ""
val conversation: Int = call.argument("conversation") ?: 0
val indexI: Int = call.argument("index") ?: 0
result.success(Data.Builder().putString("result", Cwtch.getMessage(profile, conversation.toLong(), indexI.toLong())).build())
result.success(Cwtch.getMessage(profile, conversation.toLong(), indexI.toLong()))
return
}
"GetMessageByID" -> {
val profile: String = call.argument("ProfileOnion") ?: ""
val conversation: Int = call.argument("conversation") ?: 0
val id: Int = call.argument("id") ?: 0
result.success(Data.Builder().putString("result", Cwtch.getMessageByID(profile, conversation.toLong(), id.toLong())).build())
result.success(Cwtch.getMessageByID(profile, conversation.toLong(), id.toLong()))
return
}
"GetMessageByContentHash" -> {
val profile: String = call.argument("ProfileOnion") ?: ""
val conversation: Int = call.argument("conversation") ?: 0
val contentHash: String = call.argument("contentHash") ?: ""
result.success(Data.Builder().putString("result", Cwtch.getMessagesByContentHash(profile, conversation.toLong(), contentHash)).build())
result.success(Cwtch.getMessagesByContentHash(profile, conversation.toLong(), contentHash))
return
}
"SetMessageAttribute" -> {

2
lib/models/contact.dart

@ -148,7 +148,7 @@ class ContactInfoState extends ChangeNotifier {
int get unreadMessages => this._unreadMessages;
set unreadMessages(int newVal) {
if (newVal == 0) {
if (newVal == 0 && this._unreadMessages != 0) {
// conversation has been selected, start the countdown for the New Messager marker to be reset
this._newMarkerClearAt = DateTime.now().add(const Duration(minutes: 2));
}

18
lib/views/messageview.dart

@ -7,6 +7,7 @@ import 'package:cwtch/models/appstate.dart';
import 'package:cwtch/models/chatmessage.dart';
import 'package:cwtch/models/contact.dart';
import 'package:cwtch/models/message.dart';
import 'package:cwtch/models/messagecache.dart';
import 'package:cwtch/models/messages/quotedmessage.dart';
import 'package:cwtch/models/profile.dart';
import 'package:cwtch/widgets/malformedbubble.dart';
@ -24,6 +25,7 @@ import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import '../config.dart';
import '../constants.dart';
import '../main.dart';
import '../settings.dart';
@ -216,14 +218,12 @@ class _MessageViewState extends State<MessageView> {
if (ctrlrCompose.value.text.isNotEmpty && lengthOk) {
if (Provider.of<AppState>(context, listen: false).selectedConversation != null && Provider.of<AppState>(context, listen: false).selectedIndex != null) {
Provider.of<FlwtchState>(context, listen: false)
.cwtch
.GetMessageByID(Provider.of<AppState>(context, listen: false).selectedProfile!, Provider.of<AppState>(context, listen: false).selectedConversation!,
Provider.of<AppState>(context, listen: false).selectedIndex!)
.then((data) {
var conversationId = Provider.of<AppState>(context, listen: false).selectedConversation!;
MessageCache? cache = Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(conversationId)?.messageCache;
ById(Provider.of<AppState>(context, listen: false).selectedIndex!).get(Provider.of<FlwtchState>(context, listen: false).cwtch, Provider.of<AppState>(context, listen: false).selectedProfile!, conversationId, cache!)
.then((MessageInfo? data) {
try {
var messageWrapper = jsonDecode(data! as String);
var bytes1 = utf8.encode(messageWrapper["PeerID"] + messageWrapper['Message']);
var bytes1 = utf8.encode(data!.metadata.senderHandle + data.wrapper);
var digest1 = sha256.convert(bytes1);
var contentHash = base64Encode(digest1.bytes);
var quotedMessage = jsonEncode(QuotedMessageStructure(contentHash, ctrlrCompose.value.text));
@ -232,7 +232,9 @@ class _MessageViewState extends State<MessageView> {
.cwtch
.SendMessage(Provider.of<ContactInfoState>(context, listen: false).profileOnion, Provider.of<ContactInfoState>(context, listen: false).identifier, jsonEncode(cm))
.then(_sendMessageHandler);
} catch (e) {}
} catch (e) {
EnvironmentConfig.debugLog("Exception: reply to message could not be found: " + e.toString());
}
Provider.of<AppState>(context, listen: false).selectedIndex = null;
});
} else {

Loading…
Cancel
Save