parseMessageReply static method
- String? jsonString
Parses the given jsonString
to extract the messageSender, messageAbstract, and messageID.
The jsonString
should be a JSON string with the following structure:
{
"messageReply": {
"messageID": "144115216452519330-1698670328-3674128",
"messageAbstract": "hi, beauty",
"messageSender": "qwe2203",
"messageType": 1,
"version": 1
}
}
The function first checks if there is a "messageReply" key in the JSON object. If it exists, the function extracts the "messageSender", "messageAbstract", and "messageID" keys.
If the JSON parsing fails or the relevant information is not found, all values (messageSender, messageAbstract, and messageID) will be returned as null.
Returns a tuple containing the messageSender, messageAbstract, and messageID.
Implementation
static ({String? messageAbstract, String? messageID, String? messageSender, int? messageSeq, int? messageTimestamp})
parseMessageReply(String? jsonString) {
String? messageSender;
String? messageAbstract;
String? messageID;
int? messageSeq;
int? messageTimestamp;
if (TencentCloudChatUtils.checkString(jsonString) != null) {
try {
Map<String, dynamic> jsonData = json.decode(jsonString!);
Map<String, dynamic>? messageReply = jsonData["messageReply"];
if (messageReply != null) {
messageSender = messageReply["messageSender"] as String?;
messageAbstract = messageReply["messageAbstract"] as String?;
messageID = messageReply["messageID"] as String?;
messageSeq = messageReply["messageSeq"] as int?;
messageTimestamp = messageReply["messageTimestamp"] as int?;
if (TencentCloudChatUtils.checkString(messageAbstract) != null) {
final tryParseMessageAbstract = json.decode(messageAbstract!);
final tryMessageAbstract = tryParseMessageAbstract["summary"];
if (TencentCloudChatUtils.checkString(tryMessageAbstract) != null) {
messageAbstract = tryMessageAbstract;
}
}
}
// ignore: empty_catches
} catch (e) {}
}
return (
messageSender: messageSender,
messageAbstract: messageAbstract,
messageID: messageID,
messageTimestamp: messageTimestamp,
messageSeq: messageSeq,
);
}