Skip to content

Commit

Permalink
Notifications, accepting, rejecting, bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jumpiniasty committed Jul 16, 2023
1 parent 5fe5442 commit 0f4a897
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 96 deletions.
53 changes: 48 additions & 5 deletions lib/controllers/party_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PartyController {
final url = "$mainUrl/parties/requests/${party.publicId}/";
final res = await http.post(
Uri.parse(url),
body: {
body: jsonEncode({
"party": {
"owner": {},
"owner_public_id": party.ownerPublicId,
Expand All @@ -31,17 +31,15 @@ class PartyController {
"party_public_id": party.publicId,
"sender": {},
"sender_public_id": userId,
},
}),
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer $token",
},
);
return res.statusCode == 201;
}

///Leaves from the provided [party]
static Future<void> leaveParty(Party party) async {}

///Returns all party invitation user has got
static Future<List<PartyInvitation>> invitations() async {
const storage = FlutterSecureStorage();
Expand Down Expand Up @@ -77,4 +75,49 @@ class PartyController {
];
return parties;
}

// FIXME url
static Future<bool> acceptPartyInvitation(PartyInvitation inv) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/invitations/${inv.partyPublicId}/${inv.id}";
final res = await http.post(
Uri.parse(url),
body: {
"party": {
"owner": {},
"owner_public_id": inv.party!.ownerPublicId,
"name": inv.party!.name,
"privacy_status": inv.party!.privacyStatus,
"description": inv.party!.description,
"location": inv.party!.location!.toPOINT(),
"start_time": inv.party!.startTime.toIso8601String(),
"stop_time": inv.party!.stopTime.toIso8601String(),
},
"party_public_id": inv.partyPublicId,
"receiver": {},
"receiver_public_id": inv.receiverPublicId,
},
headers: {
"Authorization": "Bearer $token",
},
);

return res.statusCode == 201;
}

// FIXME url
static Future<bool> rejectPartyInvitation(PartyInvitation inv) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/invitations/${inv.partyPublicId}/${inv.id}";
final res = await http.delete(
Uri.parse(url),
headers: {
"Authorization": "Bearer $token",
},
);

return res.statusCode == 204;
}
}
46 changes: 46 additions & 0 deletions lib/controllers/party_creator_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,50 @@ class PartyCreatorController {

return res.statusCode == 204;
}

//FIXME url
static Future<bool> acceptPartyRequest(PartyRequest req) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/requests/${req.partyPublicId}/${req.id}/";
final res = await http.post(
Uri.parse(url),
body: jsonEncode({
"party": {
"owner": {},
"owner_public_id": req.party!.ownerPublicId,
"name": req.party!.name,
"privacy_status": req.party!.privacyStatus,
"description": req.party!.description,
"location": req.party!.location!.toPOINT(),
"start_time": req.party!.startTime.toIso8601String(),
"stop_time": req.party!.stopTime.toIso8601String(),
},
"party_public_id": req.partyPublicId,
"sender": {},
"sender_public_id": req.senderPublicId,
}),
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer $token",
},
);

return res.statusCode == 201;
}

//FIXME url
static Future<bool> rejectPartyRequest(PartyRequest req) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/parties/requests/${req.partyPublicId}/${req.id}/";
final res = await http.delete(
Uri.parse(url),
headers: {
"Authorization": "Bearer $token",
},
);

return res.statusCode == 204;
}
}
37 changes: 37 additions & 0 deletions lib/controllers/user_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,43 @@ class UserController {
return invitations;
}

// FIXME url
static Future<bool> acceptFriendInvitation(FriendInvitation inv) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/friends/invitations/${inv.id}/";
final res = await http.post(
Uri.parse(url),
body: jsonEncode({
"sender": {},
"receiver": {},
"receiver_public_id": inv.receiverPublicId,
"sender_public_id": inv.senderPublicId,
}),
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer $token",
},
);

return res.statusCode == 201;
}

// FIXME url
static Future<bool> rejectFriendInvitation(FriendInvitation inv) async {
const storage = FlutterSecureStorage();
final token = await storage.read(key: "access");
final url = "$mainUrl/friends/invitations/${inv.id}/";
final res = await http.delete(
Uri.parse(url),
headers: {
"Authorization": "Bearer $token",
},
);

return res.statusCode == 201;
}

///Retrieves a list of party invitations
static Future<List<PartyInvitation>> partyInvitations() async {
const storage = FlutterSecureStorage();
Expand Down
4 changes: 2 additions & 2 deletions lib/models/friend_invitiation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class FriendInvitation {
id: m["id"],
receiver: Friend.fromMap(m["receiver"]),
sender: Friend.fromMap(m["sender"]),
receiverPublicId: m["receiver_public_id"],
senderPublicId: m["sender_public_id"],
receiverPublicId: m["receiver_public_id"] ?? "",
senderPublicId: m["sender_public_id"] ?? "",
createdAt: DateTime.parse(m["created_at"]),
);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/models/party_invitation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import './friend.dart';
import './party.dart';

class PartyInvitation {
final int? id;
final Party? party;
final String partyPublicId;
final Friend? receiver;
final String receiverPublicId;
final DateTime? createdAt;

const PartyInvitation({
this.id,
this.party,
required this.partyPublicId,
this.receiver,
Expand All @@ -18,6 +20,7 @@ class PartyInvitation {

factory PartyInvitation.fromMap(Map<String, dynamic> m) {
return PartyInvitation(
id: m["id"],
party: Party.fromMap(m["party"]),
partyPublicId: m["party_public_id"],
receiver: Friend.fromMap(m["receiver"]),
Expand Down
10 changes: 8 additions & 2 deletions lib/models/party_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import './friend.dart';
import './party.dart';

class PartyRequest {
final int? id;
final Party? party;
final String partyPublicId;
final Friend? sender;
final String senderPublicId;
final DateTime? createdAt;

const PartyRequest({
this.id,
this.party,
required this.partyPublicId,
this.sender,
Expand All @@ -18,11 +20,15 @@ class PartyRequest {

factory PartyRequest.fromMap(Map<String, dynamic> m) {
return PartyRequest(
id: m["id"],
party: Party.fromMap(m["party"]),
partyPublicId: m["party_public_id"],
partyPublicId: m["party_public_id"] ?? "",
sender: Friend.fromMap(m["sender"]),
senderPublicId: m["sender_public_id"],
senderPublicId: m["sender_public_id"] ?? "",
createdAt: DateTime.parse(m["created_at"]),
);
}

@override
String toString() => "$id $partyPublicId $senderPublicId $createdAt";
}
41 changes: 14 additions & 27 deletions lib/routes/parties_users_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,33 +112,20 @@ class _PartiesUsersPageState extends State<PartiesUsersPage> {
),
);

if (success && mounted) {
showModalBottomSheet(
context: context,
backgroundColor: Theming.bgColor,
isScrollControlled: true,
builder: (ctx) => SuccessSheet(
success: true,
successMsg: AppLocalizations.of(ctx)!
.successFriendInvite,
failureMsg: AppLocalizations.of(ctx)!
.failureFriendInvite,
),
);
} else {
showModalBottomSheet(
context: context,
backgroundColor: Theming.bgColor,
isScrollControlled: true,
builder: (ctx) => SuccessSheet(
success: false,
successMsg: AppLocalizations.of(ctx)!
.successFriendInvite,
failureMsg: AppLocalizations.of(ctx)!
.failureFriendInvite,
),
);
}
if (!mounted) return;
showModalBottomSheet(
context: context,
backgroundColor: Theming.bgColor,
isScrollControlled: true,
useRootNavigator: true,
builder: (ctx) => SuccessSheet(
success: success,
successMsg: AppLocalizations.of(ctx)!
.successFriendInvite,
failureMsg: AppLocalizations.of(ctx)!
.failureFriendInvite,
),
);
},
buttonChild: const Icon(
Icons.person_add_alt_1_rounded,
Expand Down
8 changes: 5 additions & 3 deletions lib/routes/selected_party_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ class _SelectedPartyPage extends State<SelectedPartyPage> {
visible: showMore,
child: GestureDetector(
onTap: () async {
if (!showMore) return;
final success =
await PartyController.sendJoinRequest(widget.party);
final success = await PartyController.sendJoinRequest(
widget.party,
);
if (!mounted) return;
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Theming.bgColor,
builder: (ctx) {
return SuccessSheet(
success: success,
Expand Down
Loading

0 comments on commit 0f4a897

Please sign in to comment.