Added Nextcloud base

This commit is contained in:
2023-02-20 10:56:51 +01:00
parent e54ae9c2ff
commit fea36b9a6d
63 changed files with 1863 additions and 700 deletions

View File

@ -0,0 +1,26 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:http/src/response.dart';
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChatResponse.dart';
import 'package:marianum_mobile/api/marianumcloud/talk/talkApi.dart';
import 'getChatParams.dart';
class GetChat extends TalkApi<GetChatResponse> {
String chatToken;
GetChatParams params;
GetChat(this.chatToken, this.params) : super("v1/chat/$chatToken", null, getParameters: params.toJson());
@override
assemble(String raw) {
return GetChatResponse.fromJson(jsonDecode(raw)['ocs']); // TODO move "ocs" to superclass
}
@override
Future<Response> request(Uri uri, Object? body, Map<String, String>? headers) {
return http.get(uri, headers: headers);
}
}

View File

@ -0,0 +1,30 @@
import 'dart:convert';
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChat.dart';
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChatParams.dart';
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChatResponse.dart';
import 'package:marianum_mobile/api/requestCache.dart';
class GetChatCache extends RequestCache<GetChatResponse> {
String chatToken;
GetChatCache({required onUpdate, required this.chatToken}) : super(RequestCache.cacheNothing, onUpdate) {
start("MarianumMobile", "nc-chat-$chatToken");
}
@override
Future<GetChatResponse> onLoad() {
return GetChat(
chatToken,
GetChatParams(
lookIntoFuture: GetChatParamsSwitch.off
)
).run();
}
@override
GetChatResponse onLocalData(String json) {
return GetChatResponse.fromJson(jsonDecode(json));
}
}

View File

@ -0,0 +1,33 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:marianum_mobile/api/apiParams.dart';
part 'getChatParams.g.dart';
@JsonSerializable(explicitToJson: true, includeIfNull: false)
class GetChatParams extends ApiParams {
GetChatParamsSwitch lookIntoFuture;
int? limit;
int? lastKnownMessageId;
int? lastCommonReadId;
int? timeout;
GetChatParamsSwitch? setReadMarker;
GetChatParamsSwitch? includeLastKnown;
GetChatParams({
required this.lookIntoFuture,
this.limit,
this.lastKnownMessageId,
this.lastCommonReadId,
this.timeout,
this.setReadMarker,
this.includeLastKnown
});
factory GetChatParams.fromJson(Map<String, dynamic> json) => _$GetChatParamsFromJson(json);
Map<String, dynamic> toJson() => _$GetChatParamsToJson(this);
}
enum GetChatParamsSwitch {
@JsonValue(1) on,
@JsonValue(0) off,
}

View File

@ -0,0 +1,48 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'getChatParams.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
GetChatParams _$GetChatParamsFromJson(Map<String, dynamic> json) =>
GetChatParams(
lookIntoFuture:
$enumDecode(_$GetChatParamsSwitchEnumMap, json['lookIntoFuture']),
limit: json['limit'] as int?,
lastKnownMessageId: json['lastKnownMessageId'] as int?,
lastCommonReadId: json['lastCommonReadId'] as int?,
timeout: json['timeout'] as int?,
setReadMarker: $enumDecodeNullable(
_$GetChatParamsSwitchEnumMap, json['setReadMarker']),
includeLastKnown: $enumDecodeNullable(
_$GetChatParamsSwitchEnumMap, json['includeLastKnown']),
);
Map<String, dynamic> _$GetChatParamsToJson(GetChatParams instance) {
final val = <String, dynamic>{
'lookIntoFuture': _$GetChatParamsSwitchEnumMap[instance.lookIntoFuture]!,
};
void writeNotNull(String key, dynamic value) {
if (value != null) {
val[key] = value;
}
}
writeNotNull('limit', instance.limit);
writeNotNull('lastKnownMessageId', instance.lastKnownMessageId);
writeNotNull('lastCommonReadId', instance.lastCommonReadId);
writeNotNull('timeout', instance.timeout);
writeNotNull(
'setReadMarker', _$GetChatParamsSwitchEnumMap[instance.setReadMarker]);
writeNotNull('includeLastKnown',
_$GetChatParamsSwitchEnumMap[instance.includeLastKnown]);
return val;
}
const _$GetChatParamsSwitchEnumMap = {
GetChatParamsSwitch.on: 1,
GetChatParamsSwitch.off: 0,
};

View File

@ -0,0 +1,53 @@
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;
GetChatResponseObject(
this.id,
this.token,
this.actorType,
this.actorId,
this.actorDisplayName,
this.timestamp,
this.systemMessage,
this.messageType,
this.isReplyable,
this.referenceId,
this.message);
factory GetChatResponseObject.fromJson(Map<String, dynamic> json) => _$GetChatResponseObjectFromJson(json);
Map<String, dynamic> toJson() => _$GetChatResponseObjectToJson(this);
}

View File

@ -0,0 +1,69 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'getChatResponse.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
GetChatResponse _$GetChatResponseFromJson(Map<String, dynamic> json) =>
GetChatResponse(
(json['data'] as List<dynamic>)
.map((e) => GetChatResponseObject.fromJson(e as Map<String, dynamic>))
.toSet(),
);
Map<String, dynamic> _$GetChatResponseToJson(GetChatResponse instance) =>
<String, dynamic>{
'data': instance.data.map((e) => e.toJson()).toList(),
};
GetChatResponseObject _$GetChatResponseObjectFromJson(
Map<String, dynamic> json) =>
GetChatResponseObject(
json['id'] as int,
json['token'] as String,
$enumDecode(
_$GetRoomResponseObjectMessageActorTypeEnumMap, json['actorType']),
json['actorId'] as String,
json['actorDisplayName'] as String,
json['timestamp'] as int,
json['systemMessage'] as String,
$enumDecode(
_$GetRoomResponseObjectMessageTypeEnumMap, json['messageType']),
json['isReplyable'] as bool,
json['referenceId'] as String,
json['message'] as String,
);
Map<String, dynamic> _$GetChatResponseObjectToJson(
GetChatResponseObject instance) =>
<String, dynamic>{
'id': instance.id,
'token': instance.token,
'actorType':
_$GetRoomResponseObjectMessageActorTypeEnumMap[instance.actorType]!,
'actorId': instance.actorId,
'actorDisplayName': instance.actorDisplayName,
'timestamp': instance.timestamp,
'systemMessage': instance.systemMessage,
'messageType':
_$GetRoomResponseObjectMessageTypeEnumMap[instance.messageType]!,
'isReplyable': instance.isReplyable,
'referenceId': instance.referenceId,
'message': instance.message,
};
const _$GetRoomResponseObjectMessageActorTypeEnumMap = {
GetRoomResponseObjectMessageActorType.user: 'users',
GetRoomResponseObjectMessageActorType.guest: 'guests',
GetRoomResponseObjectMessageActorType.bot: 'bots',
GetRoomResponseObjectMessageActorType.bridge: 'bridged',
};
const _$GetRoomResponseObjectMessageTypeEnumMap = {
GetRoomResponseObjectMessageType.comment: 'comment',
GetRoomResponseObjectMessageType.deletedComment: 'comment_deleted',
GetRoomResponseObjectMessageType.system: 'system',
GetRoomResponseObjectMessageType.command: 'command',
};