90 lines
2.5 KiB
Dart
90 lines
2.5 KiB
Dart
import 'package:json_annotation/json_annotation.dart';
|
|
import 'package:marianum_mobile/api/apiResponse.dart';
|
|
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart';
|
|
|
|
part 'getChatResponse.g.dart';
|
|
|
|
@JsonSerializable(explicitToJson: true)
|
|
class GetChatResponse extends ApiResponse {
|
|
Set<GetChatResponseObject> data;
|
|
|
|
GetChatResponse(this.data);
|
|
|
|
factory GetChatResponse.fromJson(Map<String, dynamic> json) => _$GetChatResponseFromJson(json);
|
|
Map<String, dynamic> toJson() => _$GetChatResponseToJson(this);
|
|
|
|
List<GetChatResponseObject> sortByTimestamp() {
|
|
List<GetChatResponseObject> sorted = data.toList();
|
|
sorted.sort((a, b) => a.timestamp.compareTo(b.timestamp));
|
|
return sorted;
|
|
}
|
|
}
|
|
|
|
@JsonSerializable(explicitToJson: true)
|
|
class GetChatResponseObject {
|
|
int id;
|
|
String token;
|
|
GetRoomResponseObjectMessageActorType actorType;
|
|
String actorId;
|
|
String actorDisplayName;
|
|
int timestamp;
|
|
String systemMessage;
|
|
GetRoomResponseObjectMessageType messageType;
|
|
bool isReplyable;
|
|
String referenceId;
|
|
String message;
|
|
@JsonKey(fromJson: _fromJson) Map<String, RichObjectString>? messageParameters;
|
|
|
|
GetChatResponseObject(
|
|
this.id,
|
|
this.token,
|
|
this.actorType,
|
|
this.actorId,
|
|
this.actorDisplayName,
|
|
this.timestamp,
|
|
this.systemMessage,
|
|
this.messageType,
|
|
this.isReplyable,
|
|
this.referenceId,
|
|
this.message,
|
|
this.messageParameters);
|
|
|
|
factory GetChatResponseObject.fromJson(Map<String, dynamic> json) => _$GetChatResponseObjectFromJson(json);
|
|
Map<String, dynamic> toJson() => _$GetChatResponseObjectToJson(this);
|
|
|
|
}
|
|
|
|
Map<String, RichObjectString>? _fromJson(json) {
|
|
if(json is Map<String, dynamic>) {
|
|
Map<String, RichObjectString> data = {};
|
|
for (var element in json.keys) {
|
|
data.putIfAbsent(element, () => RichObjectString.fromJson(json[element]));
|
|
}
|
|
return data;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
@JsonSerializable(explicitToJson: true)
|
|
class RichObjectString {
|
|
RichObjectStringObjectType type;
|
|
String id;
|
|
String name;
|
|
|
|
String? path;
|
|
String? link;
|
|
|
|
RichObjectString(this.type, this.id, this.name, this.path, this.link);
|
|
|
|
factory RichObjectString.fromJson(Map<String, dynamic> json) => _$RichObjectStringFromJson(json);
|
|
Map<String, dynamic> toJson() => _$RichObjectStringToJson(this);
|
|
}
|
|
|
|
enum RichObjectStringObjectType {
|
|
@JsonValue("user") user,
|
|
@JsonValue("group") group,
|
|
@JsonValue("file") file,
|
|
@JsonValue("guest") guest,
|
|
@JsonValue("highlight") highlight,
|
|
} |