Skip to content

Commit

Permalink
fix: Identical chat display name as current user fix, issues removing…
Browse files Browse the repository at this point in the history
… / leaving chats, rejecting chat option added
  • Loading branch information
ereio committed Jun 26, 2021
1 parent 237c7d7 commit 06ba040
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 175 deletions.
29 changes: 29 additions & 0 deletions lib/cache/middleware.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:redux/redux.dart';
import 'package:syphon/global/print.dart';
import 'package:syphon/store/auth/actions.dart';
import 'package:syphon/store/crypto/actions.dart';
import 'package:syphon/store/index.dart';
import 'package:syphon/store/rooms/actions.dart';

///
/// Cache Middleware
///
/// Saves store data to cold storage based
/// on which redux actions are fired.
///
bool cacheMiddleware(Store<AppState> store, dynamic action) {
switch (action.runtimeType) {
case SetRoom:
case RemoveRoom:
case SetOlmAccount:
case SetOlmAccountBackup:
case SetDeviceKeysOwned:
case SetUser:
case ResetCrypto:
case ResetUser:
printInfo('[initStore] persistor saving from ${action.runtimeType}');
return true;
default:
return false;
}
}
14 changes: 4 additions & 10 deletions lib/global/libs/matrix/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,14 @@ abstract class Auth {
String? email,
int? sendAttempt = 1,
}) async {
final String url =
'$protocol$homeserver/_matrix/client/r0/register/email/requestToken';
final String url = '$protocol$homeserver/_matrix/client/r0/register/email/requestToken';

final Map body = {
'email': email,
'client_secret': clientSecret,
'send_attempt': sendAttempt,
};

printJson(body);

final response = await http.post(
Uri.parse(url),
headers: {...Values.defaultHeaders},
Expand Down Expand Up @@ -334,8 +331,7 @@ abstract class Auth {
String? password,
String? currentPassword,
}) async {
final String url =
'$protocol$homeserver/_matrix/client/r0/account/password';
final String url = '$protocol$homeserver/_matrix/client/r0/account/password';

final Map<String, String> headers = {
'Authorization': 'Bearer $accessToken',
Expand Down Expand Up @@ -379,8 +375,7 @@ abstract class Auth {
String? session,
int sendAttempt = 1,
}) async {
final String url =
'$protocol$homeserver/_matrix/client/r0/account/password';
final String url = '$protocol$homeserver/_matrix/client/r0/account/password';

final Map body = {
'auth': {
Expand Down Expand Up @@ -418,8 +413,7 @@ abstract class Auth {
String? email,
int sendAttempt = 1,
}) async {
final String url =
'$protocol$homeserver/_matrix/client/r0/account/password/email/requestToken';
final String url = '$protocol$homeserver/_matrix/client/r0/account/password/email/requestToken';

final Map body = {
'email': email,
Expand Down
10 changes: 7 additions & 3 deletions lib/storage/middleware.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ dynamic storageMiddleware<State>(
case UpdateRoom:
// TODO: create a mutation like SetSyncing to distinguish small but important room mutations
if (action.syncing == null) {
// printInfo(
// '[storageMiddleware] saving room ${action.runtimeType.toString()}',
// );
final room = store.state.roomStore.rooms[action.id];
if (room != null) {
saveRoom(room, storage: Storage.main);
}
}
break;
case RemoveRoom:
final _action = action as RemoveRoom;
final room = store.state.roomStore.rooms[_action.roomId];
if (room != null) {
deleteRooms({room.id: room}, storage: Storage.main);
}
break;
case SetTheme:
case SetPrimaryColor:
case SetAvatarShape:
Expand Down
69 changes: 20 additions & 49 deletions lib/store/auth/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ ThunkAction<AppState> initDeepLinks() => (Store<AppState> store) async {
} on PlatformException {
addAlert(
origin: 'initDeepLinks',
message:
'Failed to SSO Login, please try again later or contact support',
message: 'Failed to SSO Login, please try again later or contact support',
);
// Handle exception by warning the user their action did not succeed
// return?
Expand Down Expand Up @@ -310,11 +309,8 @@ ThunkAction<AppState> generateDeviceId({String? salt}) {
// hash it
final deviceIdDigest = sha256.convert(utf8.encode(deviceId + salt));

final deviceIdHash = base64
.encode(deviceIdDigest.bytes)
.toUpperCase()
.replaceAll(RegExp(r'[^\w]'), '')
.substring(0, 10);
final deviceIdHash =
base64.encode(deviceIdDigest.bytes).toUpperCase().replaceAll(RegExp(r'[^\w]'), '').substring(0, 10);

return Device(
deviceId: deviceIdHash,
Expand Down Expand Up @@ -583,8 +579,7 @@ ThunkAction<AppState> checkUsernameAvailability() {
ThunkAction<AppState> setInteractiveAuths({Map? auths}) {
return (Store<AppState> store) async {
try {
final List<String> completed =
List<String>.from(auths!['completed'] ?? []);
final List<String> completed = List<String>.from(auths!['completed'] ?? []);

await store.dispatch(SetSession(session: auths['session']));
await store.dispatch(SetCompleted(completed: completed));
Expand Down Expand Up @@ -641,8 +636,7 @@ ThunkAction<AppState> checkPasswordResetVerification({
session: session,
);

if (data['errcode'] != null &&
data['errcode'] == MatrixErrors.not_authorized) {
if (data['errcode'] != null && data['errcode'] == MatrixErrors.not_authorized) {
throw data['error'];
}

Expand Down Expand Up @@ -748,8 +742,7 @@ ThunkAction<AppState> submitEmail({int? sendAttempt = 1}) {
final currentCredential = store.state.authStore.credential!;
final protocol = store.state.authStore.protocol;

if (currentCredential.params!.containsValue(emailSubmitted) &&
sendAttempt! < 2) {
if (currentCredential.params!.containsValue(emailSubmitted) && sendAttempt! < 2) {
return true;
}

Expand All @@ -761,8 +754,6 @@ ThunkAction<AppState> submitEmail({int? sendAttempt = 1}) {
sendAttempt: sendAttempt,
);

printJson(data);

if (data['errcode'] != null) {
throw data['error'];
}
Expand Down Expand Up @@ -824,21 +815,17 @@ ThunkAction<AppState> createUser({enableErrors = false}) {
);

if (data['errcode'] != null) {
if (data['errcode'] == MatrixErrors.not_authorized &&
credential!.type == MatrixAuthTypes.EMAIL) {
if (data['errcode'] == MatrixErrors.not_authorized && credential!.type == MatrixAuthTypes.EMAIL) {
store.dispatch(SetVerificationNeeded(needed: true));
return false;
}
throw data['error'];
}

printJson(data);

if (data['flows'] != null) {
await store.dispatch(setInteractiveAuths(auths: data));

final List<dynamic> stages =
store.state.authStore.interactiveAuths['flows'][0]['stages'];
final List<dynamic> stages = store.state.authStore.interactiveAuths['flows'][0]['stages'];
final completed = store.state.authStore.completed;

// Compare the completed stages to the flow stages provided
Expand Down Expand Up @@ -1057,8 +1044,7 @@ ThunkAction<AppState> deactivateAccount() => (Store<AppState> store) async {
try {
store.dispatch(SetLoading(loading: true));

final currentCredential =
store.state.authStore.credential ?? Credential();
final currentCredential = store.state.authStore.credential ?? Credential();

final idServer = store.state.authStore.user.idserver;
final homeserver = store.state.authStore.user.homeserver;
Expand Down Expand Up @@ -1122,17 +1108,10 @@ ThunkAction<AppState> fetchHomeservers() {
hostname: hostnameBase,
location: data['location'] ?? '',
description: data['description'] ?? '',
usersActive: data['users_active'] != null
? data['users_active'].toString()
: null,
roomsTotal: data['public_room_count'] != null
? data['public_room_count'].toString()
: null,
founded:
data['online_since'] != null ? data['online_since'].toString() : '',
responseTime: data['last_response_time'] != null
? data['last_response_time'].toString()
: '',
usersActive: data['users_active'] != null ? data['users_active'].toString() : null,
roomsTotal: data['public_room_count'] != null ? data['public_room_count'].toString() : null,
founded: data['online_since'] != null ? data['online_since'].toString() : '',
responseTime: data['last_response_time'] != null ? data['last_response_time'].toString() : '',
);
}).toList();

Expand Down Expand Up @@ -1215,20 +1194,17 @@ ThunkAction<AppState> fetchHomeserver({String? hostname}) {
};
}

ThunkAction<AppState> initClientSecret({String? hostname}) =>
(Store<AppState> store) {
ThunkAction<AppState> initClientSecret({String? hostname}) => (Store<AppState> store) {
store.dispatch(SetClientSecret(
clientSecret: generateClientSecret(length: 24),
));
};

ThunkAction<AppState> setHostname({String? hostname}) =>
(Store<AppState> store) {
ThunkAction<AppState> setHostname({String? hostname}) => (Store<AppState> store) {
store.dispatch(SetHostname(hostname: hostname!.trim()));
};

ThunkAction<AppState> setHomeserver({Homeserver? homeserver}) =>
(Store<AppState> store) {
ThunkAction<AppState> setHomeserver({Homeserver? homeserver}) => (Store<AppState> store) {
store.dispatch(SetHomeserver(homeserver: homeserver));
};

Expand All @@ -1246,8 +1222,7 @@ ThunkAction<AppState> setEmail({String? email}) {

ThunkAction<AppState> setUsername({String? username}) {
return (Store<AppState> store) {
store.dispatch(
SetUsernameValid(valid: username != null && username.isNotEmpty));
store.dispatch(SetUsernameValid(valid: username != null && username.isNotEmpty));
store.dispatch(SetUsername(username: username!.trim()));
};
}
Expand Down Expand Up @@ -1278,8 +1253,7 @@ ThunkAction<AppState> resolveUsername({String? username}) {
};
}

ThunkAction<AppState> setLoginPassword({String? password}) =>
(Store<AppState> store) {
ThunkAction<AppState> setLoginPassword({String? password}) => (Store<AppState> store) {
store.dispatch(SetPassword(password: password));
store.dispatch(SetPasswordValid(
valid: password != null && password.isNotEmpty,
Expand All @@ -1297,8 +1271,7 @@ ThunkAction<AppState> setPassword({
final currentConfirm = store.state.authStore.passwordConfirm;

store.dispatch(SetPasswordValid(
valid: (currentPassword == currentConfirm || ignoreConfirm) &&
password.length > 8,
valid: (currentPassword == currentConfirm || ignoreConfirm) && password.length > 8,
));
};
}
Expand All @@ -1317,9 +1290,7 @@ ThunkAction<AppState> setPasswordConfirm({String? password}) {
final currentConfirm = store.state.authStore.passwordConfirm;

store.dispatch(SetPasswordValid(
valid: password != null &&
password.length > 6 &&
currentPassword == currentConfirm,
valid: password != null && password.length > 6 && currentPassword == currentConfirm,
));
};
}
Expand Down
Loading

0 comments on commit 06ba040

Please sign in to comment.