Added user search in talk, currently with no further functionality
This commit is contained in:
parent
4ef21a362b
commit
e969e25e9e
37
lib/api/marianumcloud/autocomplete/autocompleteApi.dart
Normal file
37
lib/api/marianumcloud/autocomplete/autocompleteApi.dart
Normal file
@ -0,0 +1,37 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'autocompleteResponse.dart';
|
||||
|
||||
class AutocompleteApi {
|
||||
Future<AutocompleteResponse> find(String query) async {
|
||||
log("query starting");
|
||||
var preferences = await SharedPreferences.getInstance();
|
||||
Map<String, dynamic> getParameters = {
|
||||
"search": query,
|
||||
"itemType": " ",
|
||||
"itemId": " ",
|
||||
"shareTypes[]": ["0"],
|
||||
"limit": "10",
|
||||
};
|
||||
|
||||
Map<String, String> headers = {};
|
||||
headers.putIfAbsent("Accept", () => "application/json");
|
||||
headers.putIfAbsent("OCS-APIRequest", () => "true");
|
||||
|
||||
Uri endpoint = Uri.https("${preferences.getString("username")!}:${preferences.getString("password")!}@cloud.marianum-fulda.de", "/ocs/v2.php/core/autocomplete/get", getParameters);
|
||||
log(endpoint.query);
|
||||
|
||||
Response response = await http.get(endpoint, headers: headers);
|
||||
log(response.statusCode.toString());
|
||||
String result = response.body;
|
||||
log(result);
|
||||
|
||||
return AutocompleteResponse.fromJson(jsonDecode(result)['ocs']);
|
||||
}
|
||||
|
||||
}
|
30
lib/api/marianumcloud/autocomplete/autocompleteResponse.dart
Normal file
30
lib/api/marianumcloud/autocomplete/autocompleteResponse.dart
Normal file
@ -0,0 +1,30 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'autocompleteResponse.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class AutocompleteResponse {
|
||||
List<AutocompleteResponseObject> data;
|
||||
|
||||
AutocompleteResponse(this.data);
|
||||
|
||||
factory AutocompleteResponse.fromJson(Map<String, dynamic> json) => _$AutocompleteResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$AutocompleteResponseToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class AutocompleteResponseObject {
|
||||
String id;
|
||||
String label;
|
||||
String? icon;
|
||||
String? source;
|
||||
List<String>? status;
|
||||
String? subline;
|
||||
String? shareWithDisplayNameUniqe;
|
||||
|
||||
AutocompleteResponseObject(this.id, this.label, this.icon, this.source, this.status,
|
||||
this.subline, this.shareWithDisplayNameUniqe);
|
||||
|
||||
factory AutocompleteResponseObject.fromJson(Map<String, dynamic> json) => _$AutocompleteResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$AutocompleteResponseObjectToJson(this);
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'autocompleteResponse.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
AutocompleteResponse _$AutocompleteResponseFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
AutocompleteResponse(
|
||||
(json['data'] as List<dynamic>)
|
||||
.map((e) =>
|
||||
AutocompleteResponseObject.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$AutocompleteResponseToJson(
|
||||
AutocompleteResponse instance) =>
|
||||
<String, dynamic>{
|
||||
'data': instance.data.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
|
||||
AutocompleteResponseObject _$AutocompleteResponseObjectFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
AutocompleteResponseObject(
|
||||
json['id'] as String,
|
||||
json['label'] as String,
|
||||
json['icon'] as String?,
|
||||
json['source'] as String?,
|
||||
(json['status'] as List<dynamic>?)?.map((e) => e as String).toList(),
|
||||
json['subline'] as String?,
|
||||
json['shareWithDisplayNameUniqe'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$AutocompleteResponseObjectToJson(
|
||||
AutocompleteResponseObject instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'label': instance.label,
|
||||
'icon': instance.icon,
|
||||
'source': instance.source,
|
||||
'status': instance.status,
|
||||
'subline': instance.subline,
|
||||
'shareWithDisplayNameUniqe': instance.shareWithDisplayNameUniqe,
|
||||
};
|
@ -1,9 +1,9 @@
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/setReadMarker/setReadMarkerParams.dart';
|
||||
|
||||
import '../talkApi.dart';
|
||||
import 'setReadMarkerParams.dart';
|
||||
|
||||
class SetReadMarker extends TalkApi<void> {
|
||||
String chatToken;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:marianum_mobile/api/apiParams.dart';
|
||||
|
||||
import '../../../apiParams.dart';
|
||||
|
||||
part 'setReadMarkerParams.g.dart';
|
||||
|
||||
|
@ -2,20 +2,21 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/leaveRoom/leaveRoom.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/setReadMarker/setReadMarker.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/setReadMarker/setReadMarkerParams.dart';
|
||||
import 'package:persistent_bottom_nav_bar/persistent_tab_view.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../../api/marianumcloud/talk/chat/richObjectStringProcessor.dart';
|
||||
import '../../../api/marianumcloud/talk/leaveRoom/leaveRoom.dart';
|
||||
import '../../../api/marianumcloud/talk/room/getRoomResponse.dart';
|
||||
import '../../../api/marianumcloud/talk/setFavorite/setFavorite.dart';
|
||||
import '../../../api/marianumcloud/talk/setReadMarker/setReadMarker.dart';
|
||||
import '../../../api/marianumcloud/talk/setReadMarker/setReadMarkerParams.dart';
|
||||
import '../../../model/chatList/chatListProps.dart';
|
||||
import '../../../widget/confirmDialog.dart';
|
||||
import '../../../widget/unimplementedDialog.dart';
|
||||
import 'chatView.dart';
|
||||
import 'joinChat.dart';
|
||||
|
||||
class ChatList extends StatefulWidget {
|
||||
const ChatList({Key? key}) : super(key: key);
|
||||
@ -59,6 +60,13 @@ class _ChatListState extends State<ChatList> {
|
||||
)
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
onPressed: () {
|
||||
showSearch(context: context, delegate: JoinChat());
|
||||
},
|
||||
child: const Icon(Icons.add_comment_outlined),
|
||||
),
|
||||
body: Consumer<ChatListProps>(
|
||||
builder: (context, data, child) {
|
||||
|
||||
|
98
lib/view/pages/talk/joinChat.dart
Normal file
98
lib/view/pages/talk/joinChat.dart
Normal file
@ -0,0 +1,98 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:async/async.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../api/marianumcloud/autocomplete/autocompleteApi.dart';
|
||||
import '../../../api/marianumcloud/autocomplete/autocompleteResponse.dart';
|
||||
import '../../../widget/errorView.dart';
|
||||
|
||||
class JoinChat extends SearchDelegate<String> {
|
||||
CancelableOperation? future;
|
||||
|
||||
@override
|
||||
List<Widget>? buildActions(BuildContext context) {
|
||||
return [
|
||||
if(future != null && query.isNotEmpty) FutureBuilder(
|
||||
future: future!.value,
|
||||
builder: (context, snapshot) {
|
||||
if(snapshot.connectionState != ConnectionState.done) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: const Center(
|
||||
child: SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 3,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
if(query.isNotEmpty) IconButton(onPressed: () => query = "", icon: const Icon(Icons.delete)),
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget? buildLeading(BuildContext context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildResults(BuildContext context) {
|
||||
if(future != null) future!.cancel();
|
||||
|
||||
log("search started");
|
||||
if(query.isEmpty) {
|
||||
return const ErrorView(
|
||||
text: "Suche nach benutzern",
|
||||
icon: Icons.person_search_outlined,
|
||||
);
|
||||
}
|
||||
|
||||
future = CancelableOperation.fromFuture(AutocompleteApi().find(query));
|
||||
return FutureBuilder(
|
||||
future: future!.value,
|
||||
builder: (context, snapshot) {
|
||||
if(snapshot.hasData) {
|
||||
return ListView.builder(
|
||||
itemCount: snapshot.data!.data.length,
|
||||
itemBuilder: (context, index) {
|
||||
AutocompleteResponseObject object = snapshot.data!.data[index];
|
||||
CircleAvatar circleAvatar = CircleAvatar(
|
||||
foregroundImage: Image.network("https://cloud.marianum-fulda.de/avatar/${object.id}/128").image,
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
child: const Icon(Icons.person),
|
||||
);
|
||||
return ListTile(
|
||||
leading: circleAvatar,
|
||||
title: Text(object.label),
|
||||
subtitle: Text(object.id),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () {
|
||||
close(context, object.id);
|
||||
},
|
||||
);
|
||||
}
|
||||
);
|
||||
} else if(snapshot.hasError) {
|
||||
log(snapshot.error.toString());
|
||||
return ErrorView(text: snapshot.error.toString());
|
||||
}
|
||||
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildSuggestions(BuildContext context) {
|
||||
return buildResults(context);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user