using System.Collections.Generic; namespace ChatComponents { public class UnsupportedMessage : Message { /// Creates a text message. public UnsupportedMessage( User author, string id, int? createdAt = null, Dictionary metadata = null, string roomId = null, Status? status = default ) : base( author, createdAt, id, metadata, roomId, status, MessageType.unsupported ) { } public override List props => new List { author, createdAt, id, metadata, roomId, status }; /// Creates a text message from a map (decoded JSON). private UnsupportedMessage fromJson(Dictionary json) { var test = json["size"]; return new UnsupportedMessage( User.fromJson(json["author"] as Dictionary), createdAt: json["createdAt"] as int?, id: json["id"] as string, metadata: json["metadata"] as Dictionary, roomId: json["roomId"] as string, status: ChatRoomUtils.getStatusFromString(json["status"] as string) ); } public override Dictionary toJson() { return new Dictionary { {"author", author.toJson()}, {"createdAt", createdAt}, {"id", id}, {"metadata", metadata}, {"roomId", roomId}, {"status", ChatRoomUtils.toShortString(status)}, {"type", ChatRoomUtils.toShortString(MessageType.file)}, }; } /// Converts a text message to the map representation, encodable to JSON. /// Creates a copy of the text message with an updated data /// [metadata] with null value will nullify existing metadata, otherwise /// both metadatas will be merged into one Map, where keys from a passed /// metadata will overwite keys from the previous one. /// [status] with null value will be overwritten by the previous status. public override Message copyWith( Dictionary metadata = null, PreviewData previewData = null, Status? status = null, string text = null ) { var result = new Dictionary(); if (this.metadata != null) foreach (var metaItem in this.metadata) result.Add(metaItem.Key, metaItem.Value); foreach (var metaItem in metadata) result.Add(metaItem.Key, metaItem.Value); return new UnsupportedMessage( author, createdAt: createdAt, id: id, metadata: metadata == null ? null : result, roomId: roomId, status: status ?? this.status ); } } }