Added details for chats with participants list

This commit is contained in:
2023-09-13 18:57:52 +02:00
parent 3b673537e5
commit 0b48c2e7ab
13 changed files with 380 additions and 20 deletions

View File

@ -0,0 +1,22 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../talkApi.dart';
import 'getParticipantsResponse.dart';
class GetParticipants extends TalkApi<GetParticipantsResponse> {
String token;
GetParticipants(this.token) : super("v4/room/$token/participants", null);
@override
GetParticipantsResponse assemble(String raw) {
return GetParticipantsResponse.fromJson(jsonDecode(raw)['ocs']);
}
@override
Future<http.Response> request(Uri uri, Object? body, Map<String, String>? headers) {
return http.get(uri, headers: headers);
}
}

View File

@ -0,0 +1,26 @@
import 'dart:convert';
import '../../../requestCache.dart';
import 'getParticipants.dart';
import 'getParticipantsResponse.dart';
class GetParticipantsCache extends RequestCache<GetParticipantsResponse> {
String chatToken;
GetParticipantsCache({required onUpdate, required this.chatToken}) : super(RequestCache.cacheNothing, onUpdate) {
start("MarianumMobile", "nc-chat-participants-$chatToken");
}
@override
Future<GetParticipantsResponse> onLoad() {
return GetParticipants(
chatToken,
).run();
}
@override
GetParticipantsResponse onLocalData(String json) {
return GetParticipantsResponse.fromJson(jsonDecode(json));
}
}

View File

@ -0,0 +1,70 @@
import 'package:json_annotation/json_annotation.dart';
part 'getParticipantsResponse.g.dart';
@JsonSerializable(explicitToJson: true)
class GetParticipantsResponse {
Set<GetParticipantsResponseObject> data;
GetParticipantsResponse(this.data);
factory GetParticipantsResponse.fromJson(Map<String, dynamic> json) => _$GetParticipantsResponseFromJson(json);
Map<String, dynamic> toJson() => _$GetParticipantsResponseToJson(this);
}
@JsonSerializable(explicitToJson: true)
class GetParticipantsResponseObject {
int attendeeId;
String actorType;
String actorId;
String displayName;
GetParticipantsResponseObjectParticipantType participantType;
int lastPing;
GetParticipantsResponseObjectParticipantsInCallFlags inCall;
int permissions;
int attendeePermissions;
String? sessionId;
List<String> sessionIds;
String? status;
String? statusIcon;
String? statusMessage;
String? roomToken;
GetParticipantsResponseObject(
this.attendeeId,
this.actorType,
this.actorId,
this.displayName,
this.participantType,
this.lastPing,
this.inCall,
this.permissions,
this.attendeePermissions,
this.sessionId,
this.sessionIds,
this.status,
this.statusIcon,
this.statusMessage,
this.roomToken);
factory GetParticipantsResponseObject.fromJson(Map<String, dynamic> json) => _$GetParticipantsResponseObjectFromJson(json);
Map<String, dynamic> toJson() => _$GetParticipantsResponseObjectToJson(this);
}
enum GetParticipantsResponseObjectParticipantType {
@JsonValue(1) owner,
@JsonValue(2) moderator,
@JsonValue(3) user,
@JsonValue(4) guest,
@JsonValue(5) userFollowingPublicLink,
@JsonValue(6) guestWithModeratorPermissions
}
enum GetParticipantsResponseObjectParticipantsInCallFlags {
@JsonValue(0) disconnected,
@JsonValue(1) inCall,
@JsonValue(2) providesAudio,
@JsonValue(3) providesVideo,
@JsonValue(4) usesSipDialIn
}

View File

@ -0,0 +1,83 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'getParticipantsResponse.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
GetParticipantsResponse _$GetParticipantsResponseFromJson(
Map<String, dynamic> json) =>
GetParticipantsResponse(
(json['data'] as List<dynamic>)
.map((e) =>
GetParticipantsResponseObject.fromJson(e as Map<String, dynamic>))
.toSet(),
);
Map<String, dynamic> _$GetParticipantsResponseToJson(
GetParticipantsResponse instance) =>
<String, dynamic>{
'data': instance.data.map((e) => e.toJson()).toList(),
};
GetParticipantsResponseObject _$GetParticipantsResponseObjectFromJson(
Map<String, dynamic> json) =>
GetParticipantsResponseObject(
json['attendeeId'] as int,
json['actorType'] as String,
json['actorId'] as String,
json['displayName'] as String,
$enumDecode(_$GetParticipantsResponseObjectParticipantTypeEnumMap,
json['participantType']),
json['lastPing'] as int,
$enumDecode(_$GetParticipantsResponseObjectParticipantsInCallFlagsEnumMap,
json['inCall']),
json['permissions'] as int,
json['attendeePermissions'] as int,
json['sessionId'] as String?,
(json['sessionIds'] as List<dynamic>).map((e) => e as String).toList(),
json['status'] as String?,
json['statusIcon'] as String?,
json['statusMessage'] as String?,
json['roomToken'] as String?,
);
Map<String, dynamic> _$GetParticipantsResponseObjectToJson(
GetParticipantsResponseObject instance) =>
<String, dynamic>{
'attendeeId': instance.attendeeId,
'actorType': instance.actorType,
'actorId': instance.actorId,
'displayName': instance.displayName,
'participantType': _$GetParticipantsResponseObjectParticipantTypeEnumMap[
instance.participantType]!,
'lastPing': instance.lastPing,
'inCall': _$GetParticipantsResponseObjectParticipantsInCallFlagsEnumMap[
instance.inCall]!,
'permissions': instance.permissions,
'attendeePermissions': instance.attendeePermissions,
'sessionId': instance.sessionId,
'sessionIds': instance.sessionIds,
'status': instance.status,
'statusIcon': instance.statusIcon,
'statusMessage': instance.statusMessage,
'roomToken': instance.roomToken,
};
const _$GetParticipantsResponseObjectParticipantTypeEnumMap = {
GetParticipantsResponseObjectParticipantType.owner: 1,
GetParticipantsResponseObjectParticipantType.moderator: 2,
GetParticipantsResponseObjectParticipantType.user: 3,
GetParticipantsResponseObjectParticipantType.guest: 4,
GetParticipantsResponseObjectParticipantType.userFollowingPublicLink: 5,
GetParticipantsResponseObjectParticipantType.guestWithModeratorPermissions: 6,
};
const _$GetParticipantsResponseObjectParticipantsInCallFlagsEnumMap = {
GetParticipantsResponseObjectParticipantsInCallFlags.disconnected: 0,
GetParticipantsResponseObjectParticipantsInCallFlags.inCall: 1,
GetParticipantsResponseObjectParticipantsInCallFlags.providesAudio: 2,
GetParticipantsResponseObjectParticipantsInCallFlags.providesVideo: 3,
GetParticipantsResponseObjectParticipantsInCallFlags.usesSipDialIn: 4,
};

View File

@ -55,9 +55,9 @@ abstract class TalkApi<T> extends ApiRequest {
try {
assembled = assemble(data.body);
return assembled;
} catch (_) {
} catch (e) {
// TODO report error
log("Error assembling Talk API ${T.toString()} response on ${endpoint.path} with body: $body and headers: ${headers.toString()}");
log("Error assembling Talk API ${T.toString()} message: ${e.toString()} response on ${endpoint.path} with request body: $body and request headers: ${headers.toString()}");
}
throw Exception("Error assembling Talk API response");