Files
Client/lib/api/marianumcloud/talk/room/get_room_response.dart
T

138 lines
3.5 KiB
Dart

import 'package:json_annotation/json_annotation.dart';
import '../../../api_response.dart';
import '../chat/get_chat_response.dart';
part 'get_room_response.g.dart';
@JsonSerializable(explicitToJson: true)
class GetRoomResponse extends ApiResponse {
Set<GetRoomResponseObject> data;
GetRoomResponse(this.data);
factory GetRoomResponse.fromJson(Map<String, dynamic> json) => _$GetRoomResponseFromJson(json);
Map<String, dynamic> toJson() => _$GetRoomResponseToJson(this);
List<GetRoomResponseObject> sortBy({bool lastActivity = true, required bool favoritesToTop, required bool unreadToTop}) {
for (var chat in data) {
final buffer = StringBuffer();
if(favoritesToTop) {
buffer.write(chat.isFavorite ? 'b' : 'a');
}
if(unreadToTop) {
buffer.write(chat.unreadMessages > 0 ? 'b' : 'a');
}
buffer.write(chat.lastActivity);
chat.sort = buffer.toString();
}
return data.toList()..sort((a, b) => b.sort!.compareTo(a.sort!));
}
}
@JsonSerializable(explicitToJson: true)
class GetRoomResponseObject {
int id;
String token;
GetRoomResponseObjectConversationType type;
String name;
String displayName;
String description;
int participantType;
int participantFlags;
int readOnly;
int listable;
int lastPing;
String sessionId;
bool hasPassword;
bool hasCall;
int callFlag;
bool canStartCall;
bool canDeleteConversation;
bool canLeaveConversation;
int lastActivity;
bool isFavorite;
GetRoomResponseObjectParticipantNotificationLevel notificationLevel;
int unreadMessages;
bool unreadMention;
bool unreadMentionDirect;
int lastReadMessage;
int lastCommonReadMessage;
GetChatResponseObject lastMessage;
String? status;
String? statusIcon;
String? statusMessage;
String? sort;
GetRoomResponseObject(
this.id,
this.token,
this.type,
this.name,
this.displayName,
this.description,
this.participantType,
this.participantFlags,
this.readOnly,
this.listable,
this.lastPing,
this.sessionId,
this.hasPassword,
this.hasCall,
this.callFlag,
this.canStartCall,
this.canDeleteConversation,
this.canLeaveConversation,
this.lastActivity,
this.isFavorite,
this.notificationLevel,
this.unreadMessages,
this.unreadMention,
this.unreadMentionDirect,
this.lastReadMessage,
this.lastCommonReadMessage,
this.lastMessage,
this.status,
this.statusIcon,
this.statusMessage);
factory GetRoomResponseObject.fromJson(Map<String, dynamic> json) => _$GetRoomResponseObjectFromJson(json);
Map<String, dynamic> toJson() => _$GetRoomResponseObjectToJson(this);
}
enum GetRoomResponseObjectConversationType {
@JsonValue(1) oneToOne,
@JsonValue(2) group,
@JsonValue(3) public,
@JsonValue(4) changelog,
@JsonValue(5) deleted,
@JsonValue(6) noteToSelf,
}
enum GetRoomResponseObjectParticipantNotificationLevel {
@JsonValue(0) defaultLevel,
@JsonValue(1) alwaysNotify,
@JsonValue(2) notifyOnMention,
@JsonValue(3) neverNotify,
}
enum GetRoomResponseObjectMessageActorType {
@JsonValue('deleted_users') deletedUsers,
@JsonValue('users') user,
@JsonValue('guests') guest,
@JsonValue('bots') bot,
@JsonValue('bridged') bridge,
}
enum GetRoomResponseObjectMessageType {
@JsonValue('comment') comment,
@JsonValue('voice-message') voiceMessage,
@JsonValue('comment_deleted') deletedComment,
@JsonValue('system') system,
@JsonValue('command') command,
}