2021-07-06 19:46:39 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:cwtch/models/message.dart';
|
|
|
|
import 'package:cwtch/models/messages/malformedmessage.dart';
|
2021-12-15 21:43:14 +00:00
|
|
|
import 'package:cwtch/widgets/malformedbubble.dart';
|
2021-07-06 19:46:39 +00:00
|
|
|
import 'package:cwtch/widgets/messagerow.dart';
|
|
|
|
import 'package:cwtch/widgets/quotedmessage.dart';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
import '../../main.dart';
|
2022-01-20 14:13:54 +00:00
|
|
|
import '../messagecache.dart';
|
|
|
|
import '../profile.dart';
|
2021-07-06 19:46:39 +00:00
|
|
|
|
2021-07-13 21:46:47 +00:00
|
|
|
class QuotedMessageStructure {
|
|
|
|
final String quotedHash;
|
|
|
|
final String body;
|
|
|
|
QuotedMessageStructure(this.quotedHash, this.body);
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
|
|
'quotedHash': quotedHash,
|
|
|
|
'body': body,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-06 19:46:39 +00:00
|
|
|
class QuotedMessage extends Message {
|
|
|
|
final MessageMetadata metadata;
|
|
|
|
final String content;
|
|
|
|
QuotedMessage(this.metadata, this.content);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget getPreviewWidget(BuildContext context) {
|
|
|
|
return ChangeNotifierProvider.value(
|
|
|
|
value: this.metadata,
|
|
|
|
builder: (bcontext, child) {
|
|
|
|
try {
|
|
|
|
dynamic message = jsonDecode(this.content);
|
2021-07-07 17:05:25 +00:00
|
|
|
return Text(message["body"]);
|
2021-07-06 19:46:39 +00:00
|
|
|
} catch (e) {
|
2021-12-15 21:43:14 +00:00
|
|
|
return MalformedBubble();
|
2021-07-06 19:46:39 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
MessageMetadata getMetadata() {
|
|
|
|
return this.metadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-04-29 23:00:52 +00:00
|
|
|
Widget getWidget(BuildContext context, Key key, int index) {
|
2021-07-06 19:46:39 +00:00
|
|
|
try {
|
|
|
|
dynamic message = jsonDecode(this.content);
|
2021-07-07 18:24:31 +00:00
|
|
|
|
|
|
|
if (message["body"] == null || message["quotedHash"] == null) {
|
2021-12-15 21:43:14 +00:00
|
|
|
return MalformedBubble();
|
2021-07-07 18:24:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-06 19:46:39 +00:00
|
|
|
return ChangeNotifierProvider.value(
|
|
|
|
value: this.metadata,
|
|
|
|
builder: (bcontext, child) {
|
2022-04-29 23:00:52 +00:00
|
|
|
return MessageRow(QuotedMessageBubble(message["body"], messageHandler(bcontext, metadata.profileOnion, metadata.conversationIdentifier, ByContentHash(message["quotedHash"]))), index, key: key);
|
2021-07-06 19:46:39 +00:00
|
|
|
});
|
|
|
|
} catch (e) {
|
2021-12-15 21:43:14 +00:00
|
|
|
return MalformedBubble();
|
2021-07-06 19:46:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|