Added Nextcloud base
This commit is contained in:
26
lib/api/marianumcloud/talk/chat/getChat.dart
Normal file
26
lib/api/marianumcloud/talk/chat/getChat.dart
Normal 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);
|
||||
}
|
||||
|
||||
}
|
30
lib/api/marianumcloud/talk/chat/getChatCache.dart
Normal file
30
lib/api/marianumcloud/talk/chat/getChatCache.dart
Normal 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));
|
||||
}
|
||||
|
||||
}
|
33
lib/api/marianumcloud/talk/chat/getChatParams.dart
Normal file
33
lib/api/marianumcloud/talk/chat/getChatParams.dart
Normal 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,
|
||||
}
|
48
lib/api/marianumcloud/talk/chat/getChatParams.g.dart
Normal file
48
lib/api/marianumcloud/talk/chat/getChatParams.g.dart
Normal 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,
|
||||
};
|
53
lib/api/marianumcloud/talk/chat/getChatResponse.dart
Normal file
53
lib/api/marianumcloud/talk/chat/getChatResponse.dart
Normal 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);
|
||||
}
|
||||
|
69
lib/api/marianumcloud/talk/chat/getChatResponse.g.dart
Normal file
69
lib/api/marianumcloud/talk/chat/getChatResponse.g.dart
Normal 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',
|
||||
};
|
32
lib/api/marianumcloud/talk/room/getRoom.dart
Normal file
32
lib/api/marianumcloud/talk/room/getRoom.dart
Normal file
@ -0,0 +1,32 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/talkApi.dart';
|
||||
|
||||
import 'getRoomParams.dart';
|
||||
|
||||
|
||||
class GetRoom extends TalkApi<GetRoomResponse> {
|
||||
GetRoomParams params;
|
||||
GetRoom(this.params) : super("v4/room", null, getParameters: params.toJson());
|
||||
|
||||
|
||||
|
||||
@override
|
||||
GetRoomResponse assemble(String raw) {
|
||||
log("ASSEMBLING");
|
||||
log(raw);
|
||||
return GetRoomResponse.fromJson(jsonDecode(raw)['ocs']);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<http.Response> request(Uri uri, Object? body, Map<String, String>? headers) {
|
||||
log("REQUSTING...");
|
||||
log(uri.toString());
|
||||
log(headers.toString());
|
||||
return http.get(uri, headers: headers);
|
||||
}
|
||||
|
||||
}
|
30
lib/api/marianumcloud/talk/room/getRoomCache.dart
Normal file
30
lib/api/marianumcloud/talk/room/getRoomCache.dart
Normal file
@ -0,0 +1,30 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomParams.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart';
|
||||
import 'package:marianum_mobile/api/requestCache.dart';
|
||||
|
||||
import 'getRoom.dart';
|
||||
|
||||
class GetRoomCache extends RequestCache<GetRoomResponse> {
|
||||
GetRoomCache({onUpdate}) : super(RequestCache.cacheMinute, onUpdate) {
|
||||
start("MarianumMobile", "nc-rooms");
|
||||
}
|
||||
|
||||
@override
|
||||
GetRoomResponse onLocalData(String json) {
|
||||
log("LOCAL DATA FOUND");
|
||||
return GetRoomResponse.fromJson(jsonDecode(json));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GetRoomResponse> onLoad() {
|
||||
log("FETCHING DATA");
|
||||
return GetRoom(
|
||||
GetRoomParams(
|
||||
includeStatus: true,
|
||||
)
|
||||
).run();
|
||||
}
|
||||
}
|
26
lib/api/marianumcloud/talk/room/getRoomParams.dart
Normal file
26
lib/api/marianumcloud/talk/room/getRoomParams.dart
Normal file
@ -0,0 +1,26 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../../apiParams.dart';
|
||||
|
||||
part 'getRoomParams.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GetRoomParams extends ApiParams {
|
||||
GetRoomParamsStatusUpdate? noStatusUpdate;
|
||||
@JsonKey(toJson: _format) bool? includeStatus;
|
||||
int? modifiedSince;
|
||||
|
||||
GetRoomParams({this.noStatusUpdate, this.includeStatus, this.modifiedSince});
|
||||
|
||||
factory GetRoomParams.fromJson(Map<String, dynamic> json) => _$GetRoomParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetRoomParamsToJson(this);
|
||||
|
||||
static String _format(bool? v) => v.toString();
|
||||
}
|
||||
|
||||
enum GetRoomParamsStatusUpdate {
|
||||
@JsonValue(0) defaults,
|
||||
@JsonValue(1) keepAlive,
|
||||
}
|
28
lib/api/marianumcloud/talk/room/getRoomParams.g.dart
Normal file
28
lib/api/marianumcloud/talk/room/getRoomParams.g.dart
Normal file
@ -0,0 +1,28 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'getRoomParams.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
GetRoomParams _$GetRoomParamsFromJson(Map<String, dynamic> json) =>
|
||||
GetRoomParams(
|
||||
noStatusUpdate: $enumDecodeNullable(
|
||||
_$GetRoomParamsStatusUpdateEnumMap, json['noStatusUpdate']),
|
||||
includeStatus: json['includeStatus'] as bool?,
|
||||
modifiedSince: json['modifiedSince'] as int?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetRoomParamsToJson(GetRoomParams instance) =>
|
||||
<String, dynamic>{
|
||||
'noStatusUpdate':
|
||||
_$GetRoomParamsStatusUpdateEnumMap[instance.noStatusUpdate],
|
||||
'includeStatus': GetRoomParams._format(instance.includeStatus),
|
||||
'modifiedSince': instance.modifiedSince,
|
||||
};
|
||||
|
||||
const _$GetRoomParamsStatusUpdateEnumMap = {
|
||||
GetRoomParamsStatusUpdate.defaults: 0,
|
||||
GetRoomParamsStatusUpdate.keepAlive: 1,
|
||||
};
|
151
lib/api/marianumcloud/talk/room/getRoomResponse.dart
Normal file
151
lib/api/marianumcloud/talk/room/getRoomResponse.dart
Normal file
@ -0,0 +1,151 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:marianum_mobile/api/apiResponse.dart';
|
||||
|
||||
part 'getRoomResponse.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> sortByLastActivity() {
|
||||
List<GetRoomResponseObject> sorted = data.toList();
|
||||
sorted.sort((a, b) => -a.lastActivity.compareTo(b.lastActivity));
|
||||
return sorted;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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;
|
||||
GetRoomResponseObjectMessage lastMessage;
|
||||
String? status;
|
||||
String? statusIcon;
|
||||
String? statusMessage;
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
enum GetRoomResponseObjectParticipantNotificationLevel {
|
||||
@JsonValue(0) defaultLevel,
|
||||
@JsonValue(1) alwaysNotify,
|
||||
@JsonValue(2) notifyOnMention,
|
||||
@JsonValue(3) neverNotify,
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GetRoomResponseObjectMessage {
|
||||
int id;
|
||||
String token;
|
||||
GetRoomResponseObjectMessageActorType actorType;
|
||||
String actorId;
|
||||
String actorDisplayName;
|
||||
int timestamp;
|
||||
String message;
|
||||
String systemMessage;
|
||||
GetRoomResponseObjectMessageType messageType;
|
||||
bool isReplyable;
|
||||
String referenceId;
|
||||
|
||||
|
||||
GetRoomResponseObjectMessage(
|
||||
this.id,
|
||||
this.token,
|
||||
this.actorType,
|
||||
this.actorId,
|
||||
this.actorDisplayName,
|
||||
this.timestamp,
|
||||
this.message,
|
||||
this.systemMessage,
|
||||
this.messageType,
|
||||
this.isReplyable,
|
||||
this.referenceId);
|
||||
|
||||
factory GetRoomResponseObjectMessage.fromJson(Map<String, dynamic> json) => _$GetRoomResponseObjectMessageFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetRoomResponseObjectMessageToJson(this);
|
||||
}
|
||||
|
||||
enum GetRoomResponseObjectMessageActorType {
|
||||
@JsonValue("users") user,
|
||||
@JsonValue("guests") guest,
|
||||
@JsonValue("bots") bot,
|
||||
@JsonValue("bridged") bridge,
|
||||
}
|
||||
|
||||
enum GetRoomResponseObjectMessageType {
|
||||
@JsonValue("comment") comment,
|
||||
@JsonValue("comment_deleted") deletedComment,
|
||||
@JsonValue("system") system,
|
||||
@JsonValue("command") command,
|
||||
}
|
158
lib/api/marianumcloud/talk/room/getRoomResponse.g.dart
Normal file
158
lib/api/marianumcloud/talk/room/getRoomResponse.g.dart
Normal file
@ -0,0 +1,158 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'getRoomResponse.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
GetRoomResponse _$GetRoomResponseFromJson(Map<String, dynamic> json) =>
|
||||
GetRoomResponse(
|
||||
(json['data'] as List<dynamic>)
|
||||
.map((e) => GetRoomResponseObject.fromJson(e as Map<String, dynamic>))
|
||||
.toSet(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetRoomResponseToJson(GetRoomResponse instance) =>
|
||||
<String, dynamic>{
|
||||
'data': instance.data.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
|
||||
GetRoomResponseObject _$GetRoomResponseObjectFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
GetRoomResponseObject(
|
||||
json['id'] as int,
|
||||
json['token'] as String,
|
||||
$enumDecode(_$GetRoomResponseObjectConversationTypeEnumMap, json['type']),
|
||||
json['name'] as String,
|
||||
json['displayName'] as String,
|
||||
json['description'] as String,
|
||||
json['participantType'] as int,
|
||||
json['participantFlags'] as int,
|
||||
json['readOnly'] as int,
|
||||
json['listable'] as int,
|
||||
json['lastPing'] as int,
|
||||
json['sessionId'] as String,
|
||||
json['hasPassword'] as bool,
|
||||
json['hasCall'] as bool,
|
||||
json['callFlag'] as int,
|
||||
json['canStartCall'] as bool,
|
||||
json['canDeleteConversation'] as bool,
|
||||
json['canLeaveConversation'] as bool,
|
||||
json['lastActivity'] as int,
|
||||
json['isFavorite'] as bool,
|
||||
$enumDecode(_$GetRoomResponseObjectParticipantNotificationLevelEnumMap,
|
||||
json['notificationLevel']),
|
||||
json['unreadMessages'] as int,
|
||||
json['unreadMention'] as bool,
|
||||
json['unreadMentionDirect'] as bool,
|
||||
json['lastReadMessage'] as int,
|
||||
json['lastCommonReadMessage'] as int,
|
||||
GetRoomResponseObjectMessage.fromJson(
|
||||
json['lastMessage'] as Map<String, dynamic>),
|
||||
json['status'] as String?,
|
||||
json['statusIcon'] as String?,
|
||||
json['statusMessage'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetRoomResponseObjectToJson(
|
||||
GetRoomResponseObject instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'token': instance.token,
|
||||
'type': _$GetRoomResponseObjectConversationTypeEnumMap[instance.type]!,
|
||||
'name': instance.name,
|
||||
'displayName': instance.displayName,
|
||||
'description': instance.description,
|
||||
'participantType': instance.participantType,
|
||||
'participantFlags': instance.participantFlags,
|
||||
'readOnly': instance.readOnly,
|
||||
'listable': instance.listable,
|
||||
'lastPing': instance.lastPing,
|
||||
'sessionId': instance.sessionId,
|
||||
'hasPassword': instance.hasPassword,
|
||||
'hasCall': instance.hasCall,
|
||||
'callFlag': instance.callFlag,
|
||||
'canStartCall': instance.canStartCall,
|
||||
'canDeleteConversation': instance.canDeleteConversation,
|
||||
'canLeaveConversation': instance.canLeaveConversation,
|
||||
'lastActivity': instance.lastActivity,
|
||||
'isFavorite': instance.isFavorite,
|
||||
'notificationLevel':
|
||||
_$GetRoomResponseObjectParticipantNotificationLevelEnumMap[
|
||||
instance.notificationLevel]!,
|
||||
'unreadMessages': instance.unreadMessages,
|
||||
'unreadMention': instance.unreadMention,
|
||||
'unreadMentionDirect': instance.unreadMentionDirect,
|
||||
'lastReadMessage': instance.lastReadMessage,
|
||||
'lastCommonReadMessage': instance.lastCommonReadMessage,
|
||||
'lastMessage': instance.lastMessage.toJson(),
|
||||
'status': instance.status,
|
||||
'statusIcon': instance.statusIcon,
|
||||
'statusMessage': instance.statusMessage,
|
||||
};
|
||||
|
||||
const _$GetRoomResponseObjectConversationTypeEnumMap = {
|
||||
GetRoomResponseObjectConversationType.oneToOne: 1,
|
||||
GetRoomResponseObjectConversationType.group: 2,
|
||||
GetRoomResponseObjectConversationType.public: 3,
|
||||
GetRoomResponseObjectConversationType.changelog: 4,
|
||||
GetRoomResponseObjectConversationType.deleted: 5,
|
||||
};
|
||||
|
||||
const _$GetRoomResponseObjectParticipantNotificationLevelEnumMap = {
|
||||
GetRoomResponseObjectParticipantNotificationLevel.defaultLevel: 0,
|
||||
GetRoomResponseObjectParticipantNotificationLevel.alwaysNotify: 1,
|
||||
GetRoomResponseObjectParticipantNotificationLevel.notifyOnMention: 2,
|
||||
GetRoomResponseObjectParticipantNotificationLevel.neverNotify: 3,
|
||||
};
|
||||
|
||||
GetRoomResponseObjectMessage _$GetRoomResponseObjectMessageFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
GetRoomResponseObjectMessage(
|
||||
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['message'] as String,
|
||||
json['systemMessage'] as String,
|
||||
$enumDecode(
|
||||
_$GetRoomResponseObjectMessageTypeEnumMap, json['messageType']),
|
||||
json['isReplyable'] as bool,
|
||||
json['referenceId'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetRoomResponseObjectMessageToJson(
|
||||
GetRoomResponseObjectMessage instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'token': instance.token,
|
||||
'actorType':
|
||||
_$GetRoomResponseObjectMessageActorTypeEnumMap[instance.actorType]!,
|
||||
'actorId': instance.actorId,
|
||||
'actorDisplayName': instance.actorDisplayName,
|
||||
'timestamp': instance.timestamp,
|
||||
'message': instance.message,
|
||||
'systemMessage': instance.systemMessage,
|
||||
'messageType':
|
||||
_$GetRoomResponseObjectMessageTypeEnumMap[instance.messageType]!,
|
||||
'isReplyable': instance.isReplyable,
|
||||
'referenceId': instance.referenceId,
|
||||
};
|
||||
|
||||
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',
|
||||
};
|
51
lib/api/marianumcloud/talk/talkApi.dart
Normal file
51
lib/api/marianumcloud/talk/talkApi.dart
Normal file
@ -0,0 +1,51 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:marianum_mobile/api/apiRequest.dart';
|
||||
import 'package:marianum_mobile/api/apiResponse.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../apiParams.dart';
|
||||
|
||||
enum TalkApiMethod {
|
||||
get,
|
||||
post,
|
||||
put,
|
||||
delete,
|
||||
}
|
||||
|
||||
abstract class TalkApi<T> extends ApiRequest {
|
||||
String path;
|
||||
ApiParams? body;
|
||||
Map<String, String>? headers = {};
|
||||
Map<String, dynamic>? getParameters;
|
||||
|
||||
http.Response? response;
|
||||
|
||||
TalkApi(this.path, this.body, {this.headers, this.getParameters});
|
||||
|
||||
Future<http.Response> request(Uri uri, Object? body, Map<String, String>? headers);
|
||||
T assemble(String raw);
|
||||
|
||||
Future<T> run() async {
|
||||
getParameters?.forEach((key, value) {
|
||||
getParameters?.update(key, (value) => value.toString());
|
||||
});
|
||||
|
||||
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||
|
||||
Uri endpoint = Uri.https("${preferences.getString("username")!}:${preferences.getString("password")!}@cloud.marianum-fulda.de", "/ocs/v2.php/apps/spreed/api/$path", getParameters);
|
||||
|
||||
headers ??= {};
|
||||
headers?.putIfAbsent("Accept", () => "application/json");
|
||||
headers?.putIfAbsent("OCS-APIRequest", () => "true");
|
||||
|
||||
http.Response data = await request(endpoint, body, headers);
|
||||
dynamic jsonData = jsonDecode(data.body);
|
||||
|
||||
|
||||
return assemble(data.body);
|
||||
}
|
||||
|
||||
}
|
12
lib/api/marianumcloud/talk/talkError.dart
Normal file
12
lib/api/marianumcloud/talk/talkError.dart
Normal file
@ -0,0 +1,12 @@
|
||||
class TalkError {
|
||||
String status;
|
||||
int code;
|
||||
String message;
|
||||
|
||||
TalkError(this.status, this.code, this.message);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "Talk - $status - ($code): $message";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user