mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 17:48:40 +00:00
small fixes
This commit is contained in:
parent
8bffd39bc1
commit
fdaa1ff7dd
4 changed files with 34 additions and 22 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:cv/cv.dart';
|
import 'package:cv/cv.dart';
|
||||||
import 'package:fixnum/fixnum.dart';
|
import 'package:fixnum/fixnum.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:twonly/main.dart';
|
import 'package:twonly/main.dart';
|
||||||
import 'package:twonly/src/app.dart';
|
import 'package:twonly/src/app.dart';
|
||||||
|
|
@ -53,6 +54,8 @@ class DbContacts extends CvModelBase {
|
||||||
static const columnCreatedAt = "created_at";
|
static const columnCreatedAt = "created_at";
|
||||||
final createdAt = CvField<DateTime>(columnCreatedAt);
|
final createdAt = CvField<DateTime>(columnCreatedAt);
|
||||||
|
|
||||||
|
static const nextFlameCounterInSeconds = kDebugMode ? 60 : 60 * 60 * 24;
|
||||||
|
|
||||||
static String getCreateTableString() {
|
static String getCreateTableString() {
|
||||||
return """
|
return """
|
||||||
CREATE TABLE IF NOT EXISTS $tableName (
|
CREATE TABLE IF NOT EXISTS $tableName (
|
||||||
|
|
@ -77,7 +80,9 @@ class DbContacts extends CvModelBase {
|
||||||
return (await getUsers()).where((u) => u.accepted).toList();
|
return (await getUsers()).where((u) => u.accepted).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future checkAndUpdateFlames(int userId) async {
|
static Future checkAndUpdateFlames(int userId, {DateTime? timestamp}) async {
|
||||||
|
timestamp ??= DateTime.now();
|
||||||
|
|
||||||
List<Map<String, dynamic>> result = await dbProvider.db!.query(
|
List<Map<String, dynamic>> result = await dbProvider.db!.query(
|
||||||
tableName,
|
tableName,
|
||||||
columns: [
|
columns: [
|
||||||
|
|
@ -91,27 +96,31 @@ class DbContacts extends CvModelBase {
|
||||||
|
|
||||||
if (result.isNotEmpty) {
|
if (result.isNotEmpty) {
|
||||||
String lastUpdateString = result.first[columnLastUpdateOfFlameCounter];
|
String lastUpdateString = result.first[columnLastUpdateOfFlameCounter];
|
||||||
DateTime? lastUpdate = DateTime.tryParse(lastUpdateString);
|
DateTime lastUpdate = DateTime.tryParse(lastUpdateString)!;
|
||||||
|
|
||||||
int currentCount = result.first.cast()[columnFlameCounter];
|
if (timestamp.isAfter(lastUpdate)) {
|
||||||
int totalMediaCounter = result.first.cast()[columnTotalMediaCounter];
|
int currentCount = result.first.cast()[columnFlameCounter];
|
||||||
if (lastUpdate != null &&
|
int totalMediaCounter = result.first.cast()[columnTotalMediaCounter];
|
||||||
lastUpdate.isAfter(DateTime.now().subtract(Duration(hours: 24)))) {
|
if (lastUpdate.isAfter(DateTime.now()
|
||||||
_updateFlameCounter(userId, currentCount,
|
.subtract(Duration(seconds: nextFlameCounterInSeconds)))) {
|
||||||
totalMediaCounter: totalMediaCounter + 1); // just update the time
|
_updateFlameCounter(userId, currentCount,
|
||||||
} else {
|
totalMediaCounter: totalMediaCounter + 1,
|
||||||
_updateFlameCounter(userId, (currentCount + 1),
|
timestamp: timestamp); // just update the time
|
||||||
totalMediaCounter: totalMediaCounter + 1);
|
} else {
|
||||||
|
_updateFlameCounter(userId, (currentCount + 1),
|
||||||
|
totalMediaCounter: totalMediaCounter + 1, timestamp: timestamp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
globalCallBackOnContactChange();
|
globalCallBackOnContactChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future _updateFlameCounter(int userId, int newCount,
|
static Future _updateFlameCounter(int userId, int newCount,
|
||||||
{int? totalMediaCounter}) async {
|
{DateTime? timestamp, int? totalMediaCounter}) async {
|
||||||
|
timestamp ??= DateTime.now();
|
||||||
Map<String, dynamic> valuesToUpdate = {
|
Map<String, dynamic> valuesToUpdate = {
|
||||||
columnFlameCounter: newCount,
|
columnFlameCounter: newCount,
|
||||||
columnLastUpdateOfFlameCounter: DateTime.now().toIso8601String()
|
columnLastUpdateOfFlameCounter: timestamp.toIso8601String()
|
||||||
};
|
};
|
||||||
if (totalMediaCounter != null) {
|
if (totalMediaCounter != null) {
|
||||||
valuesToUpdate[columnTotalMediaCounter] = totalMediaCounter;
|
valuesToUpdate[columnTotalMediaCounter] = totalMediaCounter;
|
||||||
|
|
@ -149,10 +158,11 @@ class DbContacts extends CvModelBase {
|
||||||
|
|
||||||
int flameCounter = users.cast()[i][columnFlameCounter];
|
int flameCounter = users.cast()[i][columnFlameCounter];
|
||||||
|
|
||||||
if (lastUpdate.isBefore(DateTime.now().subtract(Duration(days: 2)))) {
|
// if (lastUpdate.isBefore(DateTime.now()
|
||||||
_updateFlameCounter(userId, 0);
|
// .subtract(Duration(seconds: nextFlameCounterInSeconds * 2)))) {
|
||||||
flameCounter = 0;
|
// _updateFlameCounter(userId, 0);
|
||||||
}
|
// flameCounter = 0;
|
||||||
|
// }
|
||||||
|
|
||||||
parsedUsers.add(
|
parsedUsers.add(
|
||||||
Contact(
|
Contact(
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
|
||||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||||
import 'package:fixnum/fixnum.dart';
|
import 'package:fixnum/fixnum.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,8 @@ Future<client.Response> handleNewMessage(
|
||||||
|
|
||||||
if (message.kind == MessageKind.video ||
|
if (message.kind == MessageKind.video ||
|
||||||
message.kind == MessageKind.image) {
|
message.kind == MessageKind.image) {
|
||||||
await DbContacts.checkAndUpdateFlames(fromUserId.toInt());
|
await DbContacts.checkAndUpdateFlames(fromUserId.toInt(),
|
||||||
|
timestamp: message.timestamp);
|
||||||
|
|
||||||
dynamic content = message.content!;
|
dynamic content = message.content!;
|
||||||
List<int> downloadToken = content.downloadToken;
|
List<int> downloadToken = content.downloadToken;
|
||||||
|
|
|
||||||
|
|
@ -94,9 +94,11 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
||||||
reverseTransitionDuration: Duration.zero,
|
reverseTransitionDuration: Duration.zero,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
setState(() {
|
if (context.mounted) {
|
||||||
sharePreviewIsShown = false;
|
setState(() {
|
||||||
});
|
sharePreviewIsShown = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
multiple: (multiple) {
|
multiple: (multiple) {
|
||||||
multiple.fileBySensor.forEach((key, value) {
|
multiple.fileBySensor.forEach((key, value) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue