Skip to content

Commit

Permalink
Misc bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cenomla committed Apr 27, 2021
1 parent eb66475 commit 9d1c810
Show file tree
Hide file tree
Showing 48 changed files with 342 additions and 198 deletions.
5 changes: 5 additions & 0 deletions flokk_src/lib/_internal/http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ class HttpResponse {
else if (raw.statusCode >= 400 && raw.statusCode < 500) errorType = NetErrorType.denied;
}

// NOTE CE: This just crahes on construction
HttpResponse.error()
: raw = http.Response("", -1),
errorType = NetErrorType.unknown;

HttpResponse.empty()
: raw = http.Response("", 200),
errorType = NetErrorType.none;
}
4 changes: 2 additions & 2 deletions flokk_src/lib/commands/abstract_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class AbstractCommand {
/// Provide all commands access to the global context & navigator
late BuildContext context;

NavigatorState get rootNav => AppGlobals.nav;
NavigatorState? get rootNav => AppGlobals.nav;

AbstractCommand(BuildContext c) {
/// Get root context
Expand Down Expand Up @@ -73,7 +73,7 @@ mixin AuthorizedServiceCommandMixin on AbstractCommand {
Dialogs.show(OkCancelDialog(
title: "No Connection",
message: "It appears your device is offline. Please check your connection and try again.",
onOkPressed: () => rootNav.pop(),
onOkPressed: () => rootNav?.pop(),
));
}

Expand Down
4 changes: 2 additions & 2 deletions flokk_src/lib/commands/contacts/delete_contact_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class DeleteContactCommand extends AbstractCommand with AuthorizedServiceCommand
message: "Are you sure you want to delete $txt?",
okLabel: "Yes",
cancelLabel: "No",
onOkPressed: () => rootNav.pop(true),
onCancelPressed: () => rootNav.pop(false),
onOkPressed: () => rootNav?.pop(true),
onCancelPressed: () => rootNav?.pop(false),
),
);
if (!doDelete) return false;
Expand Down
4 changes: 2 additions & 2 deletions flokk_src/lib/commands/contacts/delete_pic_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class DeletePicCommand extends AbstractCommand with AuthorizedServiceCommandMixi
message: "Are you sure you want to delete profile pic?",
okLabel: "Yes",
cancelLabel: "No",
onOkPressed: () => rootNav.pop(true),
onCancelPressed: () => rootNav.pop(false),
onOkPressed: () => rootNav?.pop(true),
onCancelPressed: () => rootNav?.pop(false),
),
);
if (!doDelete) return false;
Expand Down
4 changes: 2 additions & 2 deletions flokk_src/lib/commands/contacts/refresh_contacts_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class RefreshContactsCommand extends AbstractCommand with AuthorizedServiceComma
ServiceResult<GetContactsResult> result =
await googleRestService.contacts.getAll(authModel.googleAccessToken, syncToken);
// Now do we have a sync token?
syncToken = result.content.syncToken ?? "";
List<ContactData> contacts = result.content.contacts ?? [];
syncToken = result.content?.syncToken ?? "";
List<ContactData> contacts = result.content?.contacts ?? [];
if (result.success) {
authModel.googleSyncToken = syncToken;
//Iterate through returned contacts and either update existing contact or append
Expand Down
8 changes: 4 additions & 4 deletions flokk_src/lib/commands/contacts/update_contact_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class UpdateContactCommand extends AbstractCommand with AuthorizedServiceCommand
/// Update remote database
result = await googleRestService.contacts.create(authModel.googleAccessToken, contact);
if (result.success) {
result.content.isRecentlyAdded = true;
contactsModel.addContact(result.content);
result.content!.isRecentlyAdded = true;
contactsModel.addContact(result.content!);
}
} else {
// Check whether git or twitter changed, if they did we want to reset their cooldowns
Expand Down Expand Up @@ -52,7 +52,7 @@ class UpdateContactCommand extends AbstractCommand with AuthorizedServiceCommand

/// Since we get back the updated object, we can inject it straight into the model to keep us in sync
if (result.success) {
contactsModel.swapContactById(result.content);
contactsModel.swapContactById(result.content!);
} else if (tryAgainOnError &&
result.response.statusCode == 400 &&
result.response.body.contains("person.etag")) {
Expand All @@ -67,6 +67,6 @@ class UpdateContactCommand extends AbstractCommand with AuthorizedServiceCommand

return result;
});
return result.success ? result.content : null;
return result.success ? result.content! : ContactData();
}
}
12 changes: 7 additions & 5 deletions flokk_src/lib/commands/dialogs/show_discard_warning_command.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import 'package:flokk/commands/abstract_command.dart';
import 'package:flokk/styled_components/styled_dialogs.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';

import 'package:flokk/data/contact_data.dart';
import 'package:flokk/commands/abstract_command.dart';
import 'package:flokk/styled_components/styled_dialogs.dart';

class ShowDiscardWarningCommand extends AbstractCommand {
ShowDiscardWarningCommand(BuildContext c) : super(c);

Future<bool> execute() async {
if (appModel.selectedContact == null) return true;
if (appModel.selectedContact == ContactData()) return true;
bool isNew = appModel.selectedContact.isNew;
return await Dialogs.show(OkCancelDialog(
okLabel: "DISCARD",
title: "UNSAVED CHANGES FOR ${isNew ? "NEW " : ""}CONTACT",
message: "You have unsaved changes which will be lost if you navigate away.\n"
"Are you sure you wish to discard these changes?",
onOkPressed: () => rootNav.pop(true),
onCancelPressed: () => rootNav.pop(false),
onOkPressed: () => rootNav?.pop(true),
onCancelPressed: () => rootNav?.pop(false),
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ShowServiceErrorCommand extends AbstractCommand {
OkCancelDialog(
title: "Connection Error",
message: msg,
onOkPressed: () => rootNav.pop(),
onOkPressed: () => rootNav?.pop(),
),
);
isShowingError = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AddLabelToContactCommand extends AbstractCommand with AuthorizedServiceCom
//use existing label
group = existingGroup;
}
ServiceResult result = ServiceResult(null, HttpResponse.error());
ServiceResult result = ServiceResult(null, HttpResponse.empty());
if (group != GroupData()) {
result = await googleRestService.groups.modify(authModel.googleAccessToken, group, addContacts: contacts);
}
Expand Down
2 changes: 1 addition & 1 deletion flokk_src/lib/commands/groups/create_label_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CreateLabelCommand extends AbstractCommand with AuthorizedServiceCommandMi
GroupData newGroup = GroupData()..name = labelName;
ServiceResult<GroupData> result = await executeAuthServiceCmd(() async {
ServiceResult<GroupData> result = await googleRestService.groups.create(authModel.googleAccessToken, newGroup);
newGroup = result.content;
newGroup = result.content ?? GroupData();

if (result.success) {
contactsModel.allGroups.add(newGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ class RefreshContactGroupsCommand extends AbstractCommand with AuthorizedService

await executeAuthServiceCmd(() async {
GoogleRestContactGroupsService groupsApi = googleRestService.groups;
ServiceResult<GroupData> result = ServiceResult(null, null);
ServiceResult<GroupData> result = ServiceResult(null, HttpResponse.empty());
if (onlyStarred) {
result =
await groupsApi.getById(authModel.googleAccessToken, GoogleRestService.kStarredGroupId);
if (result.success) {
GroupData starred = contactsModel.getGroupById(GoogleRestService.kStarredGroupId);
if (starred != null) {
starred.members = result.content.members;
if (starred != GroupData()) {
starred.members = result.content?.members ?? [];
} else {
contactsModel.allGroups.add(starred);
}
}
} else {
ServiceResult<Tuple2<List<GroupData>, String>> result = await groupsApi.get(authModel.googleAccessToken);
List<GroupData> groups = result.content.item1;
String nextPageToken = result.content.item2;
List<GroupData> groups = result.content?.item1 ?? [];
String nextPageToken = result.content?.item2 ?? "";

while (nextPageToken != "" && result.success) {
ServiceResult<Tuple2<List<GroupData>, String>> result =
await groupsApi.get(authModel.googleAccessToken, nextPageToken: nextPageToken);
groups.addAll(result.content.item1);
nextPageToken = result.content.item2;
groups.addAll(result.content?.item1 ?? []);
nextPageToken = result.content?.item2 ?? "";
}

if (groups.isNotEmpty && result.success) {
Expand All @@ -51,7 +51,7 @@ class RefreshContactGroupsCommand extends AbstractCommand with AuthorizedService
ServiceResult<GroupData> groupResult =
await groupsApi.getById(authModel.googleAccessToken, groups[i].id);
if (groupResult.success) {
groups[i].members = groupResult.content.members;
groups[i].members = groupResult.content?.members ?? [];
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions flokk_src/lib/commands/logout_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class LogoutCommand extends AbstractCommand {
bool doLogout = await Dialogs.show(OkCancelDialog(
title: "Sign Out?",
message: "Are you sure you want to sign-out?",
onOkPressed: () => rootNav.pop<bool>(true),
onCancelPressed: () => rootNav.pop<bool>(false),
onOkPressed: () => rootNav?.pop<bool>(true),
onCancelPressed: () => rootNav?.pop<bool>(false),
));
if (!doLogout) return;
}
Expand All @@ -34,6 +34,6 @@ class LogoutCommand extends AbstractCommand {
appModel.reset(false);

//Show login page
rootNav.pushReplacement(PageRoutes.fade(() => WelcomePage(initialPanelOpen: true)));
rootNav?.pushReplacement(PageRoutes.fade(() => WelcomePage(initialPanelOpen: true)));
}
}
6 changes: 3 additions & 3 deletions flokk_src/lib/commands/refresh_auth_tokens_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class RefreshAuthTokensCommand extends AbstractCommand {
if (onlyIfExpired && !authModel.isExpired) return true;

//Query server, see if we can get a new auth token
ServiceResult<GoogleAuthResults> result = await googleRestService.auth.refresh(authModel.googleRefreshToken);
ServiceResult<GoogleAuthResults> result = await googleRestService.auth.refresh(authModel.googleRefreshToken ?? "");
//If the request succeeded, inject the model with the latest authToken and write to disk
if (result.success) {
authModel.googleAccessToken = result.content.accessToken;
authModel.setExpiry(result.content.expiresIn);
authModel.googleAccessToken = result.content?.accessToken ?? "";
authModel.setExpiry(result.content?.expiresIn ?? 0);
authModel.scheduleSave();
Log.p(
"Refresh token success. authKey = ${authModel.googleAccessToken}, refreshToken = ${authModel.googleRefreshToken}",
Expand Down
6 changes: 3 additions & 3 deletions flokk_src/lib/commands/social/refresh_github_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class RefreshGithubCommand extends AbstractCommand {
break;
}

List<GitEvent> events = eventResult?.content ?? [];
List<GitEvent> events = eventResult.content ?? [];
githubModel.addEvents(githubUsername, events);

//Fetch the repos for each event contact was involved in
Expand All @@ -46,8 +46,8 @@ class RefreshGithubCommand extends AbstractCommand {

if (githubModel.repoIsStale(fullName)) {
ServiceResult<GitRepo> repoResult = await gitService.getRepo(fullName);
if (repoResult?.success == true) {
GitRepo repo = repoResult.content;
if (repoResult.success == true) {
GitRepo repo = repoResult.content!;
githubModel.addRepo(repo);
}
}
Expand Down
2 changes: 1 addition & 1 deletion flokk_src/lib/commands/web_sign_in_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class WebSignInCommand extends AbstractCommand {
Log.p("[WebSignInCommand] Success");
authModel.googleSignIn =
gs; //save off instance of GoogleSignIn, so it can be used to call googleSignIn.disconnect() if needed
authModel.googleAccessToken = auth.accessToken;
authModel.googleAccessToken = auth.accessToken ?? "";
authModel.scheduleSave();
return true;
} else {
Expand Down
6 changes: 6 additions & 0 deletions flokk_src/lib/data/contact_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ class ContactData {
}

Map<String, dynamic> toJson() => _$ContactDataToJson(this);

@override
bool operator==(covariant ContactData other) => other.id == id;

@override
int get hashCode => id.hashCode;
}

@JsonSerializable()
Expand Down
Loading

0 comments on commit 9d1c810

Please sign in to comment.