Skip to content

Commit

Permalink
Merge pull request #229 from syphon-org/fix-batch-0.1.6+3
Browse files Browse the repository at this point in the history
[fix] Batched Fixes 0.1.6+3
  • Loading branch information
ereio authored Feb 4, 2021
2 parents 6727ef7 + 8be1344 commit 5a489e1
Show file tree
Hide file tree
Showing 56 changed files with 782 additions and 526 deletions.
6 changes: 6 additions & 0 deletions android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>

<!-- <item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item> -->

<item name="android:statusBarColor">@color/primary</item>
<item name="android:navigationBarColor">@color/primary</item>
</style>
<style name="NormalTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:windowBackground">@drawable/normal_background</item>

<!-- <item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item> -->

<!-- This is later overridden by the app theme, but setting to the primary color here
prevents weird flashes -->
Expand Down
8 changes: 4 additions & 4 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"title-view-create-group-public": "Create A Public Group",
"title-view-devices": "Devices",
"title-view-settings": "Settings",
"title-view-theming": "Theming",
"title-view-theming": "Appearance",
"title-view-advanced": "Advanced",
"title-view-invite": "Invite",
"title-view-preferences-chat": "Chat Preferences",
"title-view-preferences-chat": "Chats",
"title-view-privacy": "Privacy",
"title-view-homeserver-search": "Find Your Homeserve",
"title-view-profile": "Set up Your Profile",
Expand Down Expand Up @@ -53,8 +53,8 @@
"button-text-load-captcha": "Load Captcha",
"button-text-confirmed": "Confirmed",
"list-item-settings-notification": "Notifications",
"list-item-settings-chat": "Chats and Media",
"list-item-settings-privacy": "Security & Privacy",
"list-item-settings-chat": "Chats",
"list-item-settings-privacy": "Privacy",
"list-item-settings-sms": "SMS and MMS",
"list-item-settings-logout": "Logout",
"alert-restart-app-effect": "You'll need to close and restart the app for this to take affect",
Expand Down
2 changes: 1 addition & 1 deletion ios/Flutter/.last_build_id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
56aa4efd956611780ae2991db8894fd6
1174475fef3d534343e40f4cc82e834d
3 changes: 1 addition & 2 deletions lib/cache/serializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class CacheSerializer implements StateSerializer<AppState> {
state.authStore,
state.syncStore,
state.cryptoStore,
state.settingsStore,
];

// Queue up a cache saving will wait
Expand Down Expand Up @@ -186,7 +185,7 @@ class CacheSerializer implements StateSerializer<AppState> {
Map<String, Map<String, ReadReceipt>>(),
),
syncStore: syncStore ?? SyncStore(),
settingsStore: settingsStore ?? SettingsStore(),
settingsStore: preloaded['settings'] ?? settingsStore ?? SettingsStore(),
);
}
}
20 changes: 6 additions & 14 deletions lib/cache/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@ import 'package:syphon/cache/threadables.dart';
import 'package:syphon/global/print.dart';
import 'package:syphon/store/auth/state.dart';
import 'package:syphon/store/crypto/state.dart';
import 'package:syphon/store/settings/state.dart';
import 'package:syphon/store/sync/state.dart';

final List<Object> stores = [
AuthStore(),
SyncStore(),
CryptoStore(),
SettingsStore(),
];

class CacheStorage implements StorageEngine {
final Database cache;

CacheStorage({this.cache});

@override
Future<Uint8List> load() async {
final List<Object> stores = [
AuthStore(),
SyncStore(),
CryptoStore(),
];

await Future.wait(stores.map((store) async {
final type = store.runtimeType.toString();
try {
Expand Down Expand Up @@ -61,10 +59,4 @@ class CacheStorage implements StorageEngine {
Future<void> save(Uint8List data) {
return null;
}

Future<void> saveOffload(String jsonEncrypted, {String type}) async {
final table = StoreRef<String, String>.main();
final record = table.record(type);
await record.put(cache, jsonEncrypted);
}
}
11 changes: 7 additions & 4 deletions lib/global/libs/matrix/rooms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,21 @@ abstract class Rooms {
String accessToken,
String roomId,
}) async {
String url = '$protocol$homeserver/_matrix/client/r0/rooms/$roomId/join';
final parts = roomId.split(':');
final serverName = parts.length > 0 ? parts[1] : homeserver;
final roomIdFormatted = Uri.encodeComponent(roomId);

final String url =
'$protocol$homeserver/_matrix/client/r0/join/$roomIdFormatted?server_name=$serverName';

Map<String, String> headers = {
'Authorization': 'Bearer $accessToken',
};

Map body = {};

final response = await http.post(
url,
headers: headers,
body: json.encode(body),
body: json.encode({}),
);

return await json.decode(
Expand Down
2 changes: 2 additions & 0 deletions lib/global/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ class Strings {
static const placeholderHomeserverSearch = 'Search for homeservers...';

// Labels
static const labelSyncing = 'syncing chats...';
static const labelSearchForHomeservers = "Search for homeservers...";
static const labelSearchForUsers = 'Search for a user...';
static const labelSearchedUsers = 'Matched Users';
static const labelUsersSection = 'Users';
static const labelRecentUsers = 'Recent Users';
static const labelRoomNameDefault = 'New Chat';
static const labelNoMessages = 'no messages found';
static const labelNoGroups = 'no groups found';
static const labelDeletedMessage = 'This message was deleted';

// Buttons
Expand Down
37 changes: 37 additions & 0 deletions lib/global/themes.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Flutter imports:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'colours.dart';

Expand All @@ -10,6 +11,42 @@ enum ThemeType {
NIGHT,
}

///
/// Init System Theme
///
/// Written by TR_SLimey
///
void initSystemTheme(ThemeType themeType, {bool statusTransparent}) {
var themeNavbarColour;
var themeNavbarIconBrightness;

switch (themeType) {
case (ThemeType.LIGHT):
// TODO: transparent setting
// themeNavbarColour = Colors.transparent.value;
// themeNavbarIconBrightness = Brightness.light;

themeNavbarColour = Colours.whiteDefault;
themeNavbarIconBrightness = Brightness.dark;
break;
case (ThemeType.NIGHT):
themeNavbarColour = Colours.blackFull;
themeNavbarIconBrightness = Brightness.light;
break;
default:
themeNavbarColour = Colours.blackDefault;
themeNavbarIconBrightness = Brightness.light;
}

SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: statusTransparent ? Colors.transparent : null,
systemNavigationBarColor: Color(themeNavbarColour),
systemNavigationBarIconBrightness: themeNavbarIconBrightness,
),
);
}

class Themes {
static Color backgroundBrightness(ThemeType type) {
switch (type) {
Expand Down
6 changes: 6 additions & 0 deletions lib/global/values.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,10 @@ class Values {
'Default',
"Large",
];

static const messageSizes = [
'Small',
'Default',
"Large",
];
}
38 changes: 10 additions & 28 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,28 +151,7 @@ class SyphonState extends State<Syphon> with WidgetsBindingObserver {
// sadly the navbar doesn't play nicely with just being transparent
// so will also be updated on theme change
final currentTheme = store.state.settingsStore.theme;
var themeNavbarColour;
var themeNavbarIconBrightness;
switch (currentTheme) {
case (ThemeType.LIGHT):
themeNavbarColour = Colours.whiteDefault;
themeNavbarIconBrightness = Brightness.dark;
break;
case (ThemeType.NIGHT):
themeNavbarColour = Colours.blackFull;
themeNavbarIconBrightness = Brightness.light;
break;
default:
themeNavbarColour = Colours.blackDefault;
themeNavbarIconBrightness = Brightness.light;
}
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
systemNavigationBarColor: Color(themeNavbarColour),
systemNavigationBarIconBrightness: themeNavbarIconBrightness,
),
);
initSystemTheme(currentTheme, statusTransparent: false);

store.dispatch(initDeepLinks());
store.dispatch(initClientSecret());
Expand All @@ -187,16 +166,13 @@ class SyphonState extends State<Syphon> with WidgetsBindingObserver {
}
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
onMounted();
}

@override
void didChangeAppLifecycleState(AppLifecycleState state) async {
switch (state) {
case AppLifecycleState.resumed:
final currentTheme = store.state.settingsStore.theme;
initSystemTheme(currentTheme, statusTransparent: false);
break;
case AppLifecycleState.inactive:
break;
break;
Expand All @@ -209,6 +185,12 @@ class SyphonState extends State<Syphon> with WidgetsBindingObserver {
}
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
onMounted();
}

@protected
void onMounted() {
// init auth listener
Expand Down
7 changes: 7 additions & 0 deletions lib/storage/constants.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
///
/// Storage Keys
///
/// Keys to the castle or
/// just keys to reference data
/// from cold storage
class StorageKeys {
static const String AUTH = 'auth';
static const String ROOMS = 'rooms';
static const String USERS = 'users';
static const String MEDIA = 'MEDIA';
static const String CRYPTO = 'crypto';
static const String SETTINGS = 'settings';
static const String EVENTS = 'events';
static const String MESSAGES = 'messages';
static const String RECEIPTS = 'receipts';
Expand Down
6 changes: 6 additions & 0 deletions lib/storage/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'package:syphon/store/events/storage.dart';
import 'package:syphon/store/media/storage.dart';
import 'package:syphon/store/rooms/room/model.dart';
import 'package:syphon/store/rooms/storage.dart';
import 'package:syphon/store/settings/storage.dart';
import 'package:syphon/store/user/storage.dart';

class Storage {
Expand Down Expand Up @@ -136,6 +137,10 @@ Future<Map<String, dynamic>> loadStorage(Database storage) async {
storage: storage,
);

final settings = await loadSettings(
storage: storage,
);

final redactions = await loadRedactions(
storage: storage,
);
Expand Down Expand Up @@ -171,6 +176,7 @@ Future<Map<String, dynamic>> loadStorage(Database storage) async {
'reactions': reactions,
'redactions': redactions,
'receipts': receipts,
'settings': settings,
};
} catch (error) {
printError('[loadStorage] ${error.toString()}');
Expand Down
46 changes: 34 additions & 12 deletions lib/storage/middleware.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import 'package:syphon/store/index.dart';
import 'package:syphon/store/media/actions.dart';
import 'package:syphon/store/rooms/actions.dart';
import 'package:syphon/store/rooms/storage.dart';
import 'package:syphon/store/settings/actions.dart';
import 'package:syphon/store/settings/storage.dart';

///
/// Storage Middleware
///
/// Save to storage based on which redux actions are fired
/// Saves store data to cold storage based
/// on which redux actions are fired.
///
dynamic storageMiddleware<State>(
Store<AppState> store,
Expand All @@ -25,9 +28,9 @@ dynamic storageMiddleware<State>(
switch (action.runtimeType) {
// auth store
case SetUser:
printInfo(
'[storageMiddleware] saving auth ${action.runtimeType.toString()}',
);
// printInfo(
// '[storageMiddleware] saving auth ${action.runtimeType.toString()}',
// );
saveAuth(store.state.authStore, storage: Storage.main);
break;
// media store
Expand All @@ -40,27 +43,46 @@ 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()}',
);
// printInfo(
// '[storageMiddleware] saving room ${action.runtimeType.toString()}',
// );
final room = store.state.roomStore.rooms[action.id];
saveRoom(room, storage: Storage.main);
}
break;
// crypto store - CUD ops
case SetTheme:
case SetPrimaryColor:
case SetAvatarShape:
case SetAccentColor:
case SetAppBarColor:
case SetFontName:
case SetFontSize:
case SetMessageSize:
case SetRoomPrimaryColor:
case SetDevices:
case SetLanguage:
case SetEnterSend:
case ToggleRoomTypeBadges:
case ToggleMembershipEvents:
case ToggleNotifications:
case ToggleTypingIndicators:
case ToggleTimeFormat:
case ToggleReadReceipts:
case LogAppAgreement:
saveSettings(store.state.settingsStore, storage: Storage.main);
break;
case SetOlmAccountBackup:
case SetDeviceKeysOwned:
case ToggleDeviceKeysExist:
case SetDeviceKeys:
case SetOneTimeKeysClaimed:
case SetOneTimeKeysCounts:
case SetOneTimeKeysClaimed:
case AddInboundKeySession:
case AddInboundMessageSession:
case AddOutboundKeySession:
case AddOutboundMessageSession:
case UpdateMessageSessionOutbound:
case ResetCrypto:
printInfo(
'[storageMiddleware] saving crypto ${action.runtimeType.toString()}',
);
saveCrypto(store.state.cryptoStore, storage: Storage.main);
break;

Expand Down
Loading

0 comments on commit 5a489e1

Please sign in to comment.