Added basic Text sending
This commit is contained in:
		
							
								
								
									
										25
									
								
								lib/api/marianumcloud/talk/sendMessage/sendMessage.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								lib/api/marianumcloud/talk/sendMessage/sendMessage.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
import 'package:http/http.dart' as http;
 | 
			
		||||
import 'package:http/src/response.dart';
 | 
			
		||||
import 'package:marianum_mobile/api/marianumcloud/talk/sendMessage/sendMessageParams.dart';
 | 
			
		||||
import 'package:marianum_mobile/api/marianumcloud/talk/talkApi.dart';
 | 
			
		||||
 | 
			
		||||
import '../../../apiParams.dart';
 | 
			
		||||
 | 
			
		||||
class SendMessage extends TalkApi {
 | 
			
		||||
  String chatToken;
 | 
			
		||||
  SendMessage(this.chatToken, SendMessageParams params) : super("v1/chat/$chatToken", params);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  assemble(String raw) {
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  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;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
import 'package:json_annotation/json_annotation.dart';
 | 
			
		||||
import 'package:marianum_mobile/api/apiParams.dart';
 | 
			
		||||
 | 
			
		||||
part 'sendMessageParams.g.dart';
 | 
			
		||||
 | 
			
		||||
@JsonSerializable(explicitToJson: true, includeIfNull: false)
 | 
			
		||||
class SendMessageParams extends ApiParams {
 | 
			
		||||
  String message;
 | 
			
		||||
  int? replyTo;
 | 
			
		||||
 | 
			
		||||
  SendMessageParams(this.message, {this.replyTo});
 | 
			
		||||
 | 
			
		||||
  factory SendMessageParams.fromJson(Map<String, dynamic> json) => _$SendMessageParamsFromJson(json);
 | 
			
		||||
  Map<String, dynamic> toJson() => _$SendMessageParamsToJson(this);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,28 @@
 | 
			
		||||
// GENERATED CODE - DO NOT MODIFY BY HAND
 | 
			
		||||
 | 
			
		||||
part of 'sendMessageParams.dart';
 | 
			
		||||
 | 
			
		||||
// **************************************************************************
 | 
			
		||||
// JsonSerializableGenerator
 | 
			
		||||
// **************************************************************************
 | 
			
		||||
 | 
			
		||||
SendMessageParams _$SendMessageParamsFromJson(Map<String, dynamic> json) =>
 | 
			
		||||
    SendMessageParams(
 | 
			
		||||
      json['message'] as String,
 | 
			
		||||
      replyTo: json['replyTo'] as int?,
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
Map<String, dynamic> _$SendMessageParamsToJson(SendMessageParams instance) {
 | 
			
		||||
  final val = <String, dynamic>{
 | 
			
		||||
    'message': instance.message,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  void writeNotNull(String key, dynamic value) {
 | 
			
		||||
    if (value != null) {
 | 
			
		||||
      val[key] = value;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  writeNotNull('replyTo', instance.replyTo);
 | 
			
		||||
  return val;
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,5 @@
 | 
			
		||||
import 'package:marianum_mobile/api/apiResponse.dart';
 | 
			
		||||
 | 
			
		||||
class SendMessageResponse extends ApiResponse {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
import 'package:http/http.dart' as http;
 | 
			
		||||
import 'package:marianum_mobile/api/apiError.dart';
 | 
			
		||||
import 'package:marianum_mobile/api/apiRequest.dart';
 | 
			
		||||
import 'package:shared_preferences/shared_preferences.dart';
 | 
			
		||||
 | 
			
		||||
@@ -21,7 +22,7 @@ abstract class TalkApi<T> extends ApiRequest {
 | 
			
		||||
 | 
			
		||||
  TalkApi(this.path, this.body, {this.headers, this.getParameters});
 | 
			
		||||
 | 
			
		||||
  Future<http.Response> request(Uri uri, Object? 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 {
 | 
			
		||||
@@ -37,7 +38,10 @@ abstract class TalkApi<T> extends ApiRequest {
 | 
			
		||||
    headers?.putIfAbsent("Accept", () => "application/json");
 | 
			
		||||
    headers?.putIfAbsent("OCS-APIRequest", () => "true");
 | 
			
		||||
 | 
			
		||||
    http.Response data = await request(endpoint, body, headers);
 | 
			
		||||
    http.Response? data = await request(endpoint, body, headers);
 | 
			
		||||
    if(data == null) {
 | 
			
		||||
      throw ApiError("Request could not be dispatched!");
 | 
			
		||||
    }
 | 
			
		||||
    //dynamic jsonData = jsonDecode(data.body);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,8 @@ import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:jiffy/jiffy.dart';
 | 
			
		||||
import 'package:marianum_mobile/api/marianumcloud/talk/chat/richObjectStringProcessor.dart';
 | 
			
		||||
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart';
 | 
			
		||||
import 'package:marianum_mobile/api/marianumcloud/talk/sendMessage/sendMessage.dart';
 | 
			
		||||
import 'package:marianum_mobile/api/marianumcloud/talk/sendMessage/sendMessageParams.dart';
 | 
			
		||||
import 'package:marianum_mobile/data/chatList/chatProps.dart';
 | 
			
		||||
import 'package:provider/provider.dart';
 | 
			
		||||
 | 
			
		||||
@@ -46,6 +48,7 @@ class _ChatViewState extends State<ChatView> {
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  final ScrollController _listController = ScrollController();
 | 
			
		||||
  final TextEditingController _textBoxController = TextEditingController();
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
@@ -151,17 +154,23 @@ class _ChatViewState extends State<ChatView> {
 | 
			
		||||
                  padding: const EdgeInsets.all(10),
 | 
			
		||||
                  child: Row(
 | 
			
		||||
                    children: [
 | 
			
		||||
                      const Expanded(
 | 
			
		||||
                      Expanded(
 | 
			
		||||
                        child: TextField(
 | 
			
		||||
                          controller: _textBoxController,
 | 
			
		||||
                          maxLines: null,
 | 
			
		||||
                          decoration: InputDecoration(
 | 
			
		||||
                          decoration: const InputDecoration(
 | 
			
		||||
                            hintText: "Nachricht",
 | 
			
		||||
                            border: OutlineInputBorder(),
 | 
			
		||||
                            labelText: "",
 | 
			
		||||
                          ),
 | 
			
		||||
                        ),
 | 
			
		||||
                      ),
 | 
			
		||||
                      IconButton(onPressed: () {}, icon: const Icon(Icons.send))
 | 
			
		||||
                      IconButton(onPressed: () {
 | 
			
		||||
                        SendMessage(widget.user.token, SendMessageParams(_textBoxController.text)).run().then((value) => {
 | 
			
		||||
                          Provider.of<ChatProps>(context, listen: false).run(),
 | 
			
		||||
                          _textBoxController.text = "",
 | 
			
		||||
                        });
 | 
			
		||||
                      }, icon: const Icon(Icons.send))
 | 
			
		||||
                    ],
 | 
			
		||||
                  ),
 | 
			
		||||
                )
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user