dart format
This commit is contained in:
@@ -12,39 +12,53 @@ class SetFavorite extends TalkApi {
|
||||
final String chatToken;
|
||||
final bool favoriteState;
|
||||
|
||||
SetFavorite(this.chatToken, this.favoriteState) : super('v4/room/$chatToken/favorite', null);
|
||||
SetFavorite(this.chatToken, this.favoriteState)
|
||||
: super('v4/room/$chatToken/favorite', null);
|
||||
|
||||
@override
|
||||
ApiResponse? assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<http.Response> request(Uri uri, ApiParams? body, Map<String, String>? headers) =>
|
||||
favoriteState ? http.post(uri, headers: headers) : http.delete(uri, headers: headers);
|
||||
Future<http.Response> request(
|
||||
Uri uri,
|
||||
ApiParams? body,
|
||||
Map<String, String>? headers,
|
||||
) => favoriteState
|
||||
? http.post(uri, headers: headers)
|
||||
: http.delete(uri, headers: headers);
|
||||
}
|
||||
|
||||
class LeaveRoom extends TalkApi {
|
||||
final String chatToken;
|
||||
|
||||
LeaveRoom(this.chatToken) : super('v4/room/$chatToken/participants/self', null);
|
||||
LeaveRoom(this.chatToken)
|
||||
: super('v4/room/$chatToken/participants/self', null);
|
||||
|
||||
@override
|
||||
ApiResponse? assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<http.Response> request(Uri uri, ApiParams? body, Map<String, String>? headers) =>
|
||||
http.delete(uri, headers: headers);
|
||||
Future<http.Response> request(
|
||||
Uri uri,
|
||||
ApiParams? body,
|
||||
Map<String, String>? headers,
|
||||
) => http.delete(uri, headers: headers);
|
||||
}
|
||||
|
||||
class DeleteMessage extends TalkApi {
|
||||
final String chatToken;
|
||||
final int messageId;
|
||||
|
||||
DeleteMessage(this.chatToken, this.messageId) : super('v1/chat/$chatToken/$messageId', null);
|
||||
DeleteMessage(this.chatToken, this.messageId)
|
||||
: super('v1/chat/$chatToken/$messageId', null);
|
||||
|
||||
@override
|
||||
ApiResponse? assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<http.Response> request(Uri uri, ApiParams? body, Map<String, String>? headers) =>
|
||||
http.delete(uri, headers: headers);
|
||||
Future<http.Response> request(
|
||||
Uri uri,
|
||||
ApiParams? body,
|
||||
Map<String, String>? headers,
|
||||
) => http.delete(uri, headers: headers);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ class GetChat extends TalkApi<GetChatResponse> {
|
||||
String chatToken;
|
||||
|
||||
GetChatParams params;
|
||||
GetChat(this.chatToken, this.params) : super('v1/chat/$chatToken', null, getParameters: params.toJson());
|
||||
GetChat(this.chatToken, this.params)
|
||||
: super('v1/chat/$chatToken', null, getParameters: params.toJson());
|
||||
|
||||
@override
|
||||
GetChatResponse assemble(String raw) {
|
||||
@@ -20,6 +21,9 @@ class GetChat extends TalkApi<GetChatResponse> {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Response> request(Uri uri, Object? body, Map<String, String>? headers) => http.get(uri, headers: headers);
|
||||
|
||||
Future<Response> request(
|
||||
Uri uri,
|
||||
Object? body,
|
||||
Map<String, String>? headers,
|
||||
) => http.get(uri, headers: headers);
|
||||
}
|
||||
|
||||
@@ -10,17 +10,17 @@ class GetChatCache extends SimpleCache<GetChatResponse> {
|
||||
super.onError,
|
||||
required String chatToken,
|
||||
}) : super(
|
||||
cacheTime: RequestCache.cacheNothing,
|
||||
loader: () => GetChat(
|
||||
chatToken,
|
||||
GetChatParams(
|
||||
lookIntoFuture: GetChatParamsSwitch.off,
|
||||
setReadMarker: GetChatParamsSwitch.on,
|
||||
limit: 200,
|
||||
),
|
||||
).run(),
|
||||
fromJson: GetChatResponse.fromJson,
|
||||
) {
|
||||
cacheTime: RequestCache.cacheNothing,
|
||||
loader: () => GetChat(
|
||||
chatToken,
|
||||
GetChatParams(
|
||||
lookIntoFuture: GetChatParamsSwitch.off,
|
||||
setReadMarker: GetChatParamsSwitch.on,
|
||||
limit: 200,
|
||||
),
|
||||
).run(),
|
||||
fromJson: GetChatResponse.fromJson,
|
||||
) {
|
||||
start('nc-chat-$chatToken');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,20 +15,23 @@ class GetChatParams extends ApiParams {
|
||||
GetChatParamsSwitch? includeLastKnown;
|
||||
|
||||
GetChatParams({
|
||||
required this.lookIntoFuture,
|
||||
this.limit,
|
||||
this.lastKnownMessageId,
|
||||
this.lastCommonReadId,
|
||||
this.timeout,
|
||||
this.setReadMarker,
|
||||
this.includeLastKnown
|
||||
required this.lookIntoFuture,
|
||||
this.limit,
|
||||
this.lastKnownMessageId,
|
||||
this.lastCommonReadId,
|
||||
this.timeout,
|
||||
this.setReadMarker,
|
||||
this.includeLastKnown,
|
||||
});
|
||||
|
||||
factory GetChatParams.fromJson(Map<String, dynamic> json) => _$GetChatParamsFromJson(json);
|
||||
factory GetChatParams.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetChatParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetChatParamsToJson(this);
|
||||
}
|
||||
|
||||
enum GetChatParamsSwitch {
|
||||
@JsonValue(1) on,
|
||||
@JsonValue(0) off,
|
||||
@JsonValue(1)
|
||||
on,
|
||||
@JsonValue(0)
|
||||
off,
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ class GetChatResponse extends ApiResponse {
|
||||
|
||||
GetChatResponse(this.data);
|
||||
|
||||
factory GetChatResponse.fromJson(Map<String, dynamic> json) => _$GetChatResponseFromJson(json);
|
||||
factory GetChatResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetChatResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetChatResponseToJson(this);
|
||||
|
||||
List<GetChatResponseObject> sortByTimestamp() {
|
||||
@@ -37,28 +38,30 @@ class GetChatResponseObject {
|
||||
String message;
|
||||
Map<String, int>? reactions;
|
||||
List<String>? reactionsSelf;
|
||||
@JsonKey(fromJson: _fromJson) Map<String, RichObjectString>? messageParameters;
|
||||
@JsonKey(fromJson: _fromJson)
|
||||
Map<String, RichObjectString>? messageParameters;
|
||||
GetChatResponseObject? parent;
|
||||
|
||||
GetChatResponseObject(
|
||||
this.id,
|
||||
this.token,
|
||||
this.actorType,
|
||||
this.actorId,
|
||||
this.actorDisplayName,
|
||||
this.timestamp,
|
||||
this.systemMessage,
|
||||
this.messageType,
|
||||
this.isReplyable,
|
||||
this.referenceId,
|
||||
this.message,
|
||||
this.messageParameters,
|
||||
this.reactions,
|
||||
this.reactionsSelf,
|
||||
this.parent,
|
||||
this.id,
|
||||
this.token,
|
||||
this.actorType,
|
||||
this.actorId,
|
||||
this.actorDisplayName,
|
||||
this.timestamp,
|
||||
this.systemMessage,
|
||||
this.messageType,
|
||||
this.isReplyable,
|
||||
this.referenceId,
|
||||
this.message,
|
||||
this.messageParameters,
|
||||
this.reactions,
|
||||
this.reactionsSelf,
|
||||
this.parent,
|
||||
);
|
||||
|
||||
factory GetChatResponseObject.fromJson(Map<String, dynamic> json) => _$GetChatResponseObjectFromJson(json);
|
||||
factory GetChatResponseObject.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetChatResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetChatResponseObjectToJson(this);
|
||||
|
||||
static GetChatResponseObject getDateDummy(int timestamp) {
|
||||
@@ -66,7 +69,8 @@ class GetChatResponseObject {
|
||||
return getTextDummy(elementDate.formatDate());
|
||||
}
|
||||
|
||||
static GetChatResponseObject getTextDummy(String text) => GetChatResponseObject(
|
||||
static GetChatResponseObject getTextDummy(String text) =>
|
||||
GetChatResponseObject(
|
||||
0,
|
||||
'',
|
||||
GetRoomResponseObjectMessageActorType.user,
|
||||
@@ -82,15 +86,17 @@ class GetChatResponseObject {
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, RichObjectString>? _fromJson(dynamic json) {
|
||||
if (json is Map<String, dynamic>) {
|
||||
final data = <String, RichObjectString>{};
|
||||
for (final element in json.keys) {
|
||||
data.putIfAbsent(element, () => RichObjectString.fromJson(json[element] as Map<String, dynamic>));
|
||||
data.putIfAbsent(
|
||||
element,
|
||||
() => RichObjectString.fromJson(json[element] as Map<String, dynamic>),
|
||||
);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@@ -109,17 +115,26 @@ class RichObjectString {
|
||||
|
||||
RichObjectString(this.type, this.id, this.name, this.path, this.link);
|
||||
|
||||
factory RichObjectString.fromJson(Map<String, dynamic> json) => _$RichObjectStringFromJson(json);
|
||||
factory RichObjectString.fromJson(Map<String, dynamic> json) =>
|
||||
_$RichObjectStringFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$RichObjectStringToJson(this);
|
||||
}
|
||||
|
||||
enum RichObjectStringObjectType {
|
||||
@JsonValue('user') user,
|
||||
@JsonValue('group') group,
|
||||
@JsonValue('file') file,
|
||||
@JsonValue('guest') guest,
|
||||
@JsonValue('highlight') highlight,
|
||||
@JsonValue('talk-poll') talkPoll,
|
||||
@JsonValue('geo-location') geoLocation,
|
||||
@JsonValue('call') call,
|
||||
@JsonValue('user')
|
||||
user,
|
||||
@JsonValue('group')
|
||||
group,
|
||||
@JsonValue('file')
|
||||
file,
|
||||
@JsonValue('guest')
|
||||
guest,
|
||||
@JsonValue('highlight')
|
||||
highlight,
|
||||
@JsonValue('talk-poll')
|
||||
talkPoll,
|
||||
@JsonValue('geo-location')
|
||||
geoLocation,
|
||||
@JsonValue('call')
|
||||
call,
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
|
||||
import 'get_chat_response.dart';
|
||||
|
||||
class RichObjectStringProcessor {
|
||||
static String parseToString(String message, Map<String, RichObjectString>? data) {
|
||||
if(data == null) return message;
|
||||
static String parseToString(
|
||||
String message,
|
||||
Map<String, RichObjectString>? data,
|
||||
) {
|
||||
if (data == null) return message;
|
||||
|
||||
data.forEach((key, value) {
|
||||
message = message.replaceAll(RegExp('{$key}'), value.name);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
|
||||
import '../talk_api.dart';
|
||||
import 'create_room_params.dart';
|
||||
|
||||
class CreateRoom extends TalkApi {
|
||||
CreateRoomParams params;
|
||||
|
||||
@@ -13,9 +13,19 @@ class CreateRoom extends TalkApi {
|
||||
Null assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri, Object? body, Map<String, String>? headers) {
|
||||
if(body is CreateRoomParams) {
|
||||
return http.post(uri, headers: headers, body: body.toJson().map((key, value) => MapEntry(key, value.toString())));
|
||||
Future<Response>? request(
|
||||
Uri uri,
|
||||
Object? body,
|
||||
Map<String, String>? headers,
|
||||
) {
|
||||
if (body is CreateRoomParams) {
|
||||
return http.post(
|
||||
uri,
|
||||
headers: headers,
|
||||
body: body.toJson().map(
|
||||
(key, value) => MapEntry(key, value.toString()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -19,9 +19,10 @@ class CreateRoomParams extends ApiParams {
|
||||
this.source,
|
||||
this.roomName,
|
||||
this.objectType,
|
||||
this.objectId
|
||||
this.objectId,
|
||||
});
|
||||
|
||||
factory CreateRoomParams.fromJson(Map<String, dynamic> json) => _$CreateRoomParamsFromJson(json);
|
||||
factory CreateRoomParams.fromJson(Map<String, dynamic> json) =>
|
||||
_$CreateRoomParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$CreateRoomParamsToJson(this);
|
||||
}
|
||||
|
||||
@@ -8,17 +8,24 @@ import 'delete_react_message_params.dart';
|
||||
class DeleteReactMessage extends TalkApi {
|
||||
String chatToken;
|
||||
int messageId;
|
||||
DeleteReactMessage({required this.chatToken, required this.messageId, required DeleteReactMessageParams params}) : super('v1/reaction/$chatToken/$messageId', params);
|
||||
DeleteReactMessage({
|
||||
required this.chatToken,
|
||||
required this.messageId,
|
||||
required DeleteReactMessageParams params,
|
||||
}) : super('v1/reaction/$chatToken/$messageId', params);
|
||||
|
||||
@override
|
||||
Null assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri, ApiParams? body, Map<String, String>? headers) {
|
||||
if(body is DeleteReactMessageParams) {
|
||||
Future<Response>? request(
|
||||
Uri uri,
|
||||
ApiParams? body,
|
||||
Map<String, String>? headers,
|
||||
) {
|
||||
if (body is DeleteReactMessageParams) {
|
||||
return http.delete(uri, headers: headers, body: body.toJson());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ class DeleteReactMessageParams extends ApiParams {
|
||||
|
||||
DeleteReactMessageParams(this.reaction);
|
||||
|
||||
factory DeleteReactMessageParams.fromJson(Map<String, dynamic> json) => _$DeleteReactMessageParamsFromJson(json);
|
||||
factory DeleteReactMessageParams.fromJson(Map<String, dynamic> json) =>
|
||||
_$DeleteReactMessageParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$DeleteReactMessageParamsToJson(this);
|
||||
}
|
||||
|
||||
@@ -12,10 +12,15 @@ class GetParticipants extends TalkApi<GetParticipantsResponse> {
|
||||
@override
|
||||
GetParticipantsResponse assemble(String raw) {
|
||||
final decoded = jsonDecode(raw) as Map<String, dynamic>;
|
||||
return GetParticipantsResponse.fromJson(decoded['ocs'] as Map<String, dynamic>);
|
||||
return GetParticipantsResponse.fromJson(
|
||||
decoded['ocs'] as Map<String, dynamic>,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<http.Response> request(Uri uri, Object? body, Map<String, String>? headers) => http.get(uri, headers: headers);
|
||||
|
||||
Future<http.Response> request(
|
||||
Uri uri,
|
||||
Object? body,
|
||||
Map<String, String>? headers,
|
||||
) => http.get(uri, headers: headers);
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ class GetParticipantsCache extends SimpleCache<GetParticipantsResponse> {
|
||||
required void Function(GetParticipantsResponse) onUpdate,
|
||||
required String chatToken,
|
||||
}) : super(
|
||||
cacheTime: RequestCache.cacheNothing,
|
||||
loader: () => GetParticipants(chatToken).run(),
|
||||
fromJson: GetParticipantsResponse.fromJson,
|
||||
onUpdate: onUpdate,
|
||||
) {
|
||||
cacheTime: RequestCache.cacheNothing,
|
||||
loader: () => GetParticipants(chatToken).run(),
|
||||
fromJson: GetParticipantsResponse.fromJson,
|
||||
onUpdate: onUpdate,
|
||||
) {
|
||||
start('nc-chat-participants-$chatToken');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../../api_response.dart';
|
||||
@@ -11,7 +10,8 @@ class GetParticipantsResponse extends ApiResponse {
|
||||
|
||||
GetParticipantsResponse(this.data);
|
||||
|
||||
factory GetParticipantsResponse.fromJson(Map<String, dynamic> json) => _$GetParticipantsResponseFromJson(json);
|
||||
factory GetParticipantsResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetParticipantsResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetParticipantsResponseToJson(this);
|
||||
}
|
||||
|
||||
@@ -34,42 +34,55 @@ class GetParticipantsResponseObject {
|
||||
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);
|
||||
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);
|
||||
factory GetParticipantsResponseObject.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetParticipantsResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetParticipantsResponseObjectToJson(this);
|
||||
}
|
||||
|
||||
enum GetParticipantsResponseObjectParticipantType {
|
||||
@JsonValue(1) owner('Besitzer'),
|
||||
@JsonValue(2) moderator('Moderator'),
|
||||
@JsonValue(3) user('Teilnehmer'),
|
||||
@JsonValue(4) guest('Gast'),
|
||||
@JsonValue(5) userFollowingPublicLink('Teilnehmer über Link'),
|
||||
@JsonValue(6) guestWithModeratorPermissions('Gast Moderator');
|
||||
@JsonValue(1)
|
||||
owner('Besitzer'),
|
||||
@JsonValue(2)
|
||||
moderator('Moderator'),
|
||||
@JsonValue(3)
|
||||
user('Teilnehmer'),
|
||||
@JsonValue(4)
|
||||
guest('Gast'),
|
||||
@JsonValue(5)
|
||||
userFollowingPublicLink('Teilnehmer über Link'),
|
||||
@JsonValue(6)
|
||||
guestWithModeratorPermissions('Gast Moderator');
|
||||
|
||||
const GetParticipantsResponseObjectParticipantType(this.prettyName);
|
||||
final String prettyName;
|
||||
}
|
||||
|
||||
enum GetParticipantsResponseObjectParticipantsInCallFlags {
|
||||
@JsonValue(0) disconnected,
|
||||
@JsonValue(1) inCall,
|
||||
@JsonValue(2) providesAudio,
|
||||
@JsonValue(3) providesVideo,
|
||||
@JsonValue(4) usesSipDialIn
|
||||
@JsonValue(0)
|
||||
disconnected,
|
||||
@JsonValue(1)
|
||||
inCall,
|
||||
@JsonValue(2)
|
||||
providesAudio,
|
||||
@JsonValue(3)
|
||||
providesVideo,
|
||||
@JsonValue(4)
|
||||
usesSipDialIn,
|
||||
}
|
||||
|
||||
@@ -8,14 +8,21 @@ import 'get_poll_state_response.dart';
|
||||
class GetPollState extends TalkApi<GetPollStateResponse> {
|
||||
String token;
|
||||
int pollId;
|
||||
GetPollState({required this.token, required this.pollId}) : super('v1/poll/$token/$pollId', null);
|
||||
GetPollState({required this.token, required this.pollId})
|
||||
: super('v1/poll/$token/$pollId', null);
|
||||
|
||||
@override
|
||||
GetPollStateResponse assemble(String raw) {
|
||||
final decoded = jsonDecode(raw) as Map<String, dynamic>;
|
||||
return GetPollStateResponse.fromJson(decoded['ocs'] as Map<String, dynamic>);
|
||||
return GetPollStateResponse.fromJson(
|
||||
decoded['ocs'] as Map<String, dynamic>,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<http.Response> request(Uri uri, Object? body, Map<String, String>? headers) => http.get(uri, headers: headers);
|
||||
Future<http.Response> request(
|
||||
Uri uri,
|
||||
Object? body,
|
||||
Map<String, String>? headers,
|
||||
) => http.get(uri, headers: headers);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ class GetPollStateResponse extends ApiResponse {
|
||||
|
||||
GetPollStateResponse(this.data);
|
||||
|
||||
factory GetPollStateResponse.fromJson(Map<String, dynamic> json) => _$GetPollStateResponseFromJson(json);
|
||||
factory GetPollStateResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetPollStateResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetPollStateResponseToJson(this);
|
||||
}
|
||||
|
||||
@@ -31,20 +32,22 @@ class GetPollStateResponseObject {
|
||||
List<dynamic>? details;
|
||||
|
||||
GetPollStateResponseObject(
|
||||
this.id,
|
||||
this.question,
|
||||
this.options,
|
||||
this.votes,
|
||||
this.actorType,
|
||||
this.actorId,
|
||||
this.actorDisplayName,
|
||||
this.status,
|
||||
this.resultMode,
|
||||
this.maxVotes,
|
||||
this.votedSelf,
|
||||
this.numVoters,
|
||||
this.details);
|
||||
this.id,
|
||||
this.question,
|
||||
this.options,
|
||||
this.votes,
|
||||
this.actorType,
|
||||
this.actorId,
|
||||
this.actorDisplayName,
|
||||
this.status,
|
||||
this.resultMode,
|
||||
this.maxVotes,
|
||||
this.votedSelf,
|
||||
this.numVoters,
|
||||
this.details,
|
||||
);
|
||||
|
||||
factory GetPollStateResponseObject.fromJson(Map<String, dynamic> json) => _$GetPollStateResponseObjectFromJson(json);
|
||||
factory GetPollStateResponseObject.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetPollStateResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetPollStateResponseObjectToJson(this);
|
||||
}
|
||||
|
||||
@@ -10,15 +10,21 @@ import 'get_reactions_response.dart';
|
||||
class GetReactions extends TalkApi<GetReactionsResponse> {
|
||||
String chatToken;
|
||||
int messageId;
|
||||
GetReactions({required this.chatToken, required this.messageId}) : super('v1/reaction/$chatToken/$messageId', null);
|
||||
GetReactions({required this.chatToken, required this.messageId})
|
||||
: super('v1/reaction/$chatToken/$messageId', null);
|
||||
|
||||
@override
|
||||
GetReactionsResponse assemble(String raw) {
|
||||
final decoded = jsonDecode(raw) as Map<String, dynamic>;
|
||||
return GetReactionsResponse.fromJson(decoded['ocs'] as Map<String, dynamic>);
|
||||
return GetReactionsResponse.fromJson(
|
||||
decoded['ocs'] as Map<String, dynamic>,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri, ApiParams? body, Map<String, String>? headers) => http.get(uri, headers: headers);
|
||||
|
||||
Future<Response>? request(
|
||||
Uri uri,
|
||||
ApiParams? body,
|
||||
Map<String, String>? headers,
|
||||
) => http.get(uri, headers: headers);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ class GetReactionsResponse extends ApiResponse {
|
||||
|
||||
GetReactionsResponse(this.data);
|
||||
|
||||
factory GetReactionsResponse.fromJson(Map<String, dynamic> json) => _$GetReactionsResponseFromJson(json);
|
||||
factory GetReactionsResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetReactionsResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetReactionsResponseToJson(this);
|
||||
}
|
||||
|
||||
@@ -21,13 +22,21 @@ class GetReactionsResponseObject {
|
||||
String actorDisplayName;
|
||||
int timestamp;
|
||||
|
||||
GetReactionsResponseObject(this.actorType, this.actorId, this.actorDisplayName, this.timestamp);
|
||||
GetReactionsResponseObject(
|
||||
this.actorType,
|
||||
this.actorId,
|
||||
this.actorDisplayName,
|
||||
this.timestamp,
|
||||
);
|
||||
|
||||
factory GetReactionsResponseObject.fromJson(Map<String, dynamic> json) => _$GetReactionsResponseObjectFromJson(json);
|
||||
factory GetReactionsResponseObject.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetReactionsResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetReactionsResponseObjectToJson(this);
|
||||
}
|
||||
|
||||
enum GetReactionsResponseObjectActorType {
|
||||
@JsonValue('guests') guests,
|
||||
@JsonValue('users') users,
|
||||
@JsonValue('guests')
|
||||
guests,
|
||||
@JsonValue('users')
|
||||
users,
|
||||
}
|
||||
|
||||
@@ -8,17 +8,24 @@ import 'react_message_params.dart';
|
||||
class ReactMessage extends TalkApi {
|
||||
String chatToken;
|
||||
int messageId;
|
||||
ReactMessage({required this.chatToken, required this.messageId, required ReactMessageParams params}) : super('v1/reaction/$chatToken/$messageId', params);
|
||||
ReactMessage({
|
||||
required this.chatToken,
|
||||
required this.messageId,
|
||||
required ReactMessageParams params,
|
||||
}) : super('v1/reaction/$chatToken/$messageId', params);
|
||||
|
||||
@override
|
||||
Null assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri, ApiParams? body, Map<String, String>? headers) {
|
||||
if(body is ReactMessageParams) {
|
||||
Future<Response>? request(
|
||||
Uri uri,
|
||||
ApiParams? body,
|
||||
Map<String, String>? headers,
|
||||
) {
|
||||
if (body is ReactMessageParams) {
|
||||
return http.post(uri, headers: headers, body: body.toJson());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ class ReactMessageParams extends ApiParams {
|
||||
|
||||
ReactMessageParams(this.reaction);
|
||||
|
||||
factory ReactMessageParams.fromJson(Map<String, dynamic> json) => _$ReactMessageParamsFromJson(json);
|
||||
factory ReactMessageParams.fromJson(Map<String, dynamic> json) =>
|
||||
_$ReactMessageParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ReactMessageParamsToJson(this);
|
||||
}
|
||||
|
||||
@@ -6,13 +6,10 @@ import '../talk_api.dart';
|
||||
import 'get_room_params.dart';
|
||||
import 'get_room_response.dart';
|
||||
|
||||
|
||||
class GetRoom extends TalkApi<GetRoomResponse> {
|
||||
GetRoomParams params;
|
||||
GetRoom(this.params) : super('v4/room', null, getParameters: params.toJson());
|
||||
|
||||
|
||||
|
||||
@override
|
||||
GetRoomResponse assemble(String raw) {
|
||||
final decoded = jsonDecode(raw) as Map<String, dynamic>;
|
||||
@@ -20,6 +17,9 @@ class GetRoom extends TalkApi<GetRoomResponse> {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<http.Response> request(Uri uri, Object? body, Map<String, String>? headers) => http.get(uri, headers: headers);
|
||||
|
||||
Future<http.Response> request(
|
||||
Uri uri,
|
||||
Object? body,
|
||||
Map<String, String>? headers,
|
||||
) => http.get(uri, headers: headers);
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ import 'get_room_response.dart';
|
||||
|
||||
class GetRoomCache extends SimpleCache<GetRoomResponse> {
|
||||
GetRoomCache({super.onUpdate, super.onError, super.renew})
|
||||
: super(
|
||||
cacheTime: RequestCache.cacheMinute,
|
||||
loader: () => GetRoom(GetRoomParams(includeStatus: true)).run(),
|
||||
fromJson: GetRoomResponse.fromJson,
|
||||
) {
|
||||
: super(
|
||||
cacheTime: RequestCache.cacheMinute,
|
||||
loader: () => GetRoom(GetRoomParams(includeStatus: true)).run(),
|
||||
fromJson: GetRoomResponse.fromJson,
|
||||
) {
|
||||
start('nc-rooms');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../../api_params.dart';
|
||||
@@ -8,18 +7,22 @@ part 'get_room_params.g.dart';
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GetRoomParams extends ApiParams {
|
||||
GetRoomParamsStatusUpdate? noStatusUpdate;
|
||||
@JsonKey(toJson: _format) bool? includeStatus;
|
||||
@JsonKey(toJson: _format)
|
||||
bool? includeStatus;
|
||||
int? modifiedSince;
|
||||
|
||||
GetRoomParams({this.noStatusUpdate, this.includeStatus, this.modifiedSince});
|
||||
|
||||
factory GetRoomParams.fromJson(Map<String, dynamic> json) => _$GetRoomParamsFromJson(json);
|
||||
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,
|
||||
@JsonValue(0)
|
||||
defaults,
|
||||
@JsonValue(1)
|
||||
keepAlive,
|
||||
}
|
||||
|
||||
@@ -11,17 +11,22 @@ class GetRoomResponse extends ApiResponse {
|
||||
|
||||
GetRoomResponse(this.data);
|
||||
|
||||
factory GetRoomResponse.fromJson(Map<String, dynamic> json) => _$GetRoomResponseFromJson(json);
|
||||
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}) {
|
||||
List<GetRoomResponseObject> sortBy({
|
||||
bool lastActivity = true,
|
||||
required bool favoritesToTop,
|
||||
required bool unreadToTop,
|
||||
}) {
|
||||
for (var chat in data) {
|
||||
final buffer = StringBuffer();
|
||||
|
||||
if(favoritesToTop) {
|
||||
if (favoritesToTop) {
|
||||
buffer.write(chat.isFavorite ? 'b' : 'a');
|
||||
}
|
||||
if(unreadToTop) {
|
||||
if (unreadToTop) {
|
||||
buffer.write(chat.unreadMessages > 0 ? 'b' : 'a');
|
||||
}
|
||||
|
||||
@@ -69,69 +74,91 @@ class GetRoomResponseObject {
|
||||
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);
|
||||
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);
|
||||
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,
|
||||
@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,
|
||||
@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,
|
||||
@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,
|
||||
@JsonValue('comment')
|
||||
comment,
|
||||
@JsonValue('voice-message')
|
||||
voiceMessage,
|
||||
@JsonValue('comment_deleted')
|
||||
deletedComment,
|
||||
@JsonValue('system')
|
||||
system,
|
||||
@JsonValue('command')
|
||||
command,
|
||||
}
|
||||
|
||||
@@ -7,17 +7,21 @@ import 'send_message_params.dart';
|
||||
|
||||
class SendMessage extends TalkApi {
|
||||
String chatToken;
|
||||
SendMessage(this.chatToken, SendMessageParams params) : super('v1/chat/$chatToken', params);
|
||||
SendMessage(this.chatToken, SendMessageParams params)
|
||||
: super('v1/chat/$chatToken', params);
|
||||
|
||||
@override
|
||||
Null assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri, ApiParams? body, Map<String, String>? headers) {
|
||||
if(body is SendMessageParams) {
|
||||
Future<Response>? request(
|
||||
Uri uri,
|
||||
ApiParams? body,
|
||||
Map<String, String>? headers,
|
||||
) {
|
||||
if (body is SendMessageParams) {
|
||||
return http.post(uri, headers: headers, body: body.toJson());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ class SendMessageParams extends ApiParams {
|
||||
|
||||
SendMessageParams(this.message, {this.replyTo});
|
||||
|
||||
factory SendMessageParams.fromJson(Map<String, dynamic> json) => _$SendMessageParamsFromJson(json);
|
||||
factory SendMessageParams.fromJson(Map<String, dynamic> json) =>
|
||||
_$SendMessageParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$SendMessageParamsToJson(this);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
|
||||
@@ -10,21 +9,28 @@ class SetReadMarker extends TalkApi {
|
||||
bool readState;
|
||||
SetReadMarkerParams? setReadMarkerParams;
|
||||
|
||||
SetReadMarker(this.chatToken, this.readState, {this.setReadMarkerParams}) : super('v1/chat/$chatToken/read', null, getParameters: setReadMarkerParams?.toJson()) {
|
||||
if(readState) assert(setReadMarkerParams?.lastReadMessage != null);
|
||||
SetReadMarker(this.chatToken, this.readState, {this.setReadMarkerParams})
|
||||
: super(
|
||||
'v1/chat/$chatToken/read',
|
||||
null,
|
||||
getParameters: setReadMarkerParams?.toJson(),
|
||||
) {
|
||||
if (readState) assert(setReadMarkerParams?.lastReadMessage != null);
|
||||
}
|
||||
|
||||
@override
|
||||
Null assemble(String raw) => null;
|
||||
|
||||
@override
|
||||
Future<Response> request(Uri uri, Object? body, Map<String, String>? headers) {
|
||||
if(readState) {
|
||||
|
||||
Future<Response> request(
|
||||
Uri uri,
|
||||
Object? body,
|
||||
Map<String, String>? headers,
|
||||
) {
|
||||
if (readState) {
|
||||
return http.post(uri, headers: headers);
|
||||
} else {
|
||||
return http.delete(uri, headers: headers);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,10 +8,9 @@ part 'set_read_marker_params.g.dart';
|
||||
class SetReadMarkerParams extends ApiParams {
|
||||
int? lastReadMessage;
|
||||
|
||||
SetReadMarkerParams({
|
||||
this.lastReadMessage
|
||||
});
|
||||
SetReadMarkerParams({this.lastReadMessage});
|
||||
|
||||
factory SetReadMarkerParams.fromJson(Map<String, dynamic> json) => _$SetReadMarkerParamsFromJson(json);
|
||||
factory SetReadMarkerParams.fromJson(Map<String, dynamic> json) =>
|
||||
_$SetReadMarkerParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$SetReadMarkerParamsToJson(this);
|
||||
}
|
||||
|
||||
@@ -14,12 +14,7 @@ import '../../errors/parse_exception.dart';
|
||||
import '../../errors/server_exception.dart';
|
||||
import '../nextcloud_ocs.dart';
|
||||
|
||||
enum TalkApiMethod {
|
||||
get,
|
||||
post,
|
||||
put,
|
||||
delete,
|
||||
}
|
||||
enum TalkApiMethod { get, post, put, delete }
|
||||
|
||||
abstract class TalkApi<T extends ApiResponse?> extends ApiRequest {
|
||||
String path;
|
||||
@@ -31,11 +26,18 @@ abstract class TalkApi<T extends ApiResponse?> extends ApiRequest {
|
||||
|
||||
TalkApi(this.path, this.body, {this.headers, this.getParameters});
|
||||
|
||||
Future<http.Response>? request(Uri uri, ApiParams? body, Map<String, String>? headers);
|
||||
Future<http.Response>? request(
|
||||
Uri uri,
|
||||
ApiParams? body,
|
||||
Map<String, String>? headers,
|
||||
);
|
||||
T assemble(String raw);
|
||||
|
||||
Future<T> run() async {
|
||||
final endpoint = NextcloudOcs.uri('apps/spreed/api/$path', queryParameters: getParameters);
|
||||
final endpoint = NextcloudOcs.uri(
|
||||
'apps/spreed/api/$path',
|
||||
queryParameters: getParameters,
|
||||
);
|
||||
final mergedHeaders = {...NextcloudOcs.headers(), ...?headers};
|
||||
|
||||
final http.Response data;
|
||||
@@ -60,8 +62,12 @@ abstract class TalkApi<T extends ApiResponse?> extends ApiRequest {
|
||||
if (status < 200 || status >= 300) {
|
||||
final detail = 'Talk $endpoint -> HTTP $status';
|
||||
log(detail);
|
||||
if (status == 401) throw AuthException.unauthorized(technicalDetails: detail);
|
||||
if (status == 403) throw AuthException.forbidden(technicalDetails: detail);
|
||||
if (status == 401) {
|
||||
throw AuthException.unauthorized(technicalDetails: detail);
|
||||
}
|
||||
if (status == 403) {
|
||||
throw AuthException.forbidden(technicalDetails: detail);
|
||||
}
|
||||
if (status == 404) throw NotFoundException(technicalDetails: detail);
|
||||
throw ServerException(statusCode: status, technicalDetails: detail);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user