Added option to add reactions to talk messages
This commit is contained in:
@ -0,0 +1,26 @@
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
|
||||
import '../../../apiParams.dart';
|
||||
import '../talkApi.dart';
|
||||
import 'deleteReactMessageParams.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);
|
||||
|
||||
@override
|
||||
assemble(String raw) {
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../../apiParams.dart';
|
||||
|
||||
part 'deleteReactMessageParams.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class DeleteReactMessageParams extends ApiParams {
|
||||
String reaction;
|
||||
|
||||
DeleteReactMessageParams(this.reaction);
|
||||
|
||||
factory DeleteReactMessageParams.fromJson(Map<String, dynamic> json) => _$DeleteReactMessageParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$DeleteReactMessageParamsToJson(this);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'deleteReactMessageParams.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
DeleteReactMessageParams _$DeleteReactMessageParamsFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
DeleteReactMessageParams(
|
||||
json['reaction'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$DeleteReactMessageParamsToJson(
|
||||
DeleteReactMessageParams instance) =>
|
||||
<String, dynamic>{
|
||||
'reaction': instance.reaction,
|
||||
};
|
26
lib/api/marianumcloud/talk/reactMessage/reactMessage.dart
Normal file
26
lib/api/marianumcloud/talk/reactMessage/reactMessage.dart
Normal file
@ -0,0 +1,26 @@
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
|
||||
import '../../../apiParams.dart';
|
||||
import '../talkApi.dart';
|
||||
import 'reactMessageParams.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);
|
||||
|
||||
@override
|
||||
assemble(String raw) {
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../../apiParams.dart';
|
||||
|
||||
part 'reactMessageParams.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class ReactMessageParams extends ApiParams {
|
||||
String reaction;
|
||||
|
||||
ReactMessageParams(this.reaction);
|
||||
|
||||
factory ReactMessageParams.fromJson(Map<String, dynamic> json) => _$ReactMessageParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ReactMessageParamsToJson(this);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'reactMessageParams.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
ReactMessageParams _$ReactMessageParamsFromJson(Map<String, dynamic> json) =>
|
||||
ReactMessageParams(
|
||||
json['reaction'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ReactMessageParamsToJson(ReactMessageParams instance) =>
|
||||
<String, dynamic>{
|
||||
'reaction': instance.reaction,
|
||||
};
|
@ -42,9 +42,11 @@ abstract class TalkApi<T> extends ApiRequest {
|
||||
|
||||
try {
|
||||
data = await request(endpoint, body, headers);
|
||||
if(data == null) throw Exception();
|
||||
if(data == null) throw Exception("No response Data");
|
||||
if(data.statusCode >= 400 || data.statusCode < 200) throw Exception("Response status code '${data.statusCode}' might indicate an error");
|
||||
} catch(e) {
|
||||
throw ApiError("Request could not be dispatched!");
|
||||
log(e.toString());
|
||||
throw ApiError("Request could not be dispatched: ${e.toString()}");
|
||||
}
|
||||
//dynamic jsonData = jsonDecode(data.body);
|
||||
|
||||
|
Reference in New Issue
Block a user