4
2
Fork 0

feat: logic for new group creation

pull/54/head
Sudharshan S. 2019-06-29 14:56:35 +08:00
parent 7ec27474ff
commit 366b329ce8
Signed by: sudharshan
GPG Key ID: C861C97AAF3D9559
2 changed files with 24 additions and 1 deletions

View File

@ -65,6 +65,17 @@ class ConversationApiProvider {
}
}
Future<void> createConversationMember(
String conversationId, String userId) async {
final jwt = await loginManager.getToken();
await http.post("$baseUrlCore/user/conversation/$conversationId/member",
headers: {
HttpHeaders.contentTypeHeader: "application/json",
HttpHeaders.authorizationHeader: "Bearer $jwt"
},
body: jsonEncode({"id": userId}));
}
Future<List<User>> fetchConversationMembers(String id) async {
final jwt = await loginManager.getToken();
try {

View File

@ -4,6 +4,8 @@ import "dart:io";
import "../../../models/user_model.dart";
import "../../../resources/conversation_api_provider.dart";
import "../../widgets/contact_item.dart";
import "../../widgets/top_bar.dart";
import "../../widgets/small_text_button.dart";
@ -23,6 +25,7 @@ class NewGroupInfoView extends StatefulWidget {
class _NewGroupInfoViewState extends State<NewGroupInfoView> {
final descriptionController = TextEditingController();
final nameController = TextEditingController();
final conversationApiProvider = ConversationApiProvider();
File _image;
@ -43,7 +46,16 @@ class _NewGroupInfoViewState extends State<NewGroupInfoView> {
Navigator.pop(context);
}),
Spacer(),
SmallTextButton(text: "Create", onClickCallback: () {})
SmallTextButton(
text: "Create",
onClickCallback: () async {
final conversation = await conversationApiProvider
.createConversation(nameController.text);
widget.users.forEach((user) async => await conversationApiProvider
.createConversationMember(conversation.id, user.id));
Navigator.pushNamed(context, "conversation/home");
})
]),
Padding(
padding: EdgeInsets.only(left: 15.0, right: 15.0, top: 10.0),