forked from MixinNetwork/flutter-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support scam warning (MixinNetwork#364)
* Support scam warning. * format * improve scam warning
- Loading branch information
Showing
14 changed files
with
156 additions
and
11 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:rxdart/rxdart.dart'; | ||
|
||
import '../utils/hive_key_values.dart'; | ||
|
||
class ScamWarningKeyValue extends HiveKeyValue<DateTime?> { | ||
ScamWarningKeyValue._() : super(_hiveName); | ||
static const _hiveName = 'scam_warning_key_value'; | ||
|
||
static ScamWarningKeyValue? _instance; | ||
|
||
static ScamWarningKeyValue get instance => | ||
_instance ??= ScamWarningKeyValue._(); | ||
|
||
bool _isShow(String userId) => box.get(userId, defaultValue: null).isShow; | ||
|
||
Future<void> dismiss(String userId) => | ||
box.put(userId, DateTime.now().add(const Duration(days: 1))); | ||
|
||
Stream<bool> watch(String userId) => box | ||
.watch(key: userId) | ||
.map((event) => event.value) | ||
.where((event) => event is DateTime?) | ||
.cast<DateTime?>() | ||
.map((dateTime) => dateTime.isShow) | ||
.startWith(_isShow(userId)); | ||
} | ||
|
||
extension _IsShowScamWarningExtension on DateTime? { | ||
bool get isShow { | ||
if (this == null) return true; | ||
return DateTime.now().isAfter(this!); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters