mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 13:08:42 +00:00
special flame for best friend
This commit is contained in:
parent
177d76998b
commit
ceb6c7b362
2 changed files with 46 additions and 18 deletions
|
|
@ -10,6 +10,7 @@ class Contact {
|
||||||
required this.displayName,
|
required this.displayName,
|
||||||
required this.accepted,
|
required this.accepted,
|
||||||
required this.flameCounter,
|
required this.flameCounter,
|
||||||
|
required this.totalMediaCounter,
|
||||||
required this.lastUpdateOfFlameCounter,
|
required this.lastUpdateOfFlameCounter,
|
||||||
required this.requested});
|
required this.requested});
|
||||||
final Int64 userId;
|
final Int64 userId;
|
||||||
|
|
@ -17,6 +18,7 @@ class Contact {
|
||||||
final bool accepted;
|
final bool accepted;
|
||||||
final bool requested;
|
final bool requested;
|
||||||
final int flameCounter;
|
final int flameCounter;
|
||||||
|
final int totalMediaCounter;
|
||||||
final DateTime lastUpdateOfFlameCounter;
|
final DateTime lastUpdateOfFlameCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,6 +43,9 @@ class DbContacts extends CvModelBase {
|
||||||
static const columnFlameCounter = "flame_counter";
|
static const columnFlameCounter = "flame_counter";
|
||||||
final flameCounter = CvField<int>(columnFlameCounter);
|
final flameCounter = CvField<int>(columnFlameCounter);
|
||||||
|
|
||||||
|
static const columnTotalMediaCounter = "total_media_counter";
|
||||||
|
final totalMediaCounter = CvField<int>(columnTotalMediaCounter);
|
||||||
|
|
||||||
static const columnLastUpdateOfFlameCounter = "last_update_flame_counter";
|
static const columnLastUpdateOfFlameCounter = "last_update_flame_counter";
|
||||||
final lastUpdateOfFlameCounter =
|
final lastUpdateOfFlameCounter =
|
||||||
CvField<DateTime>(columnLastUpdateOfFlameCounter);
|
CvField<DateTime>(columnLastUpdateOfFlameCounter);
|
||||||
|
|
@ -56,6 +61,7 @@ class DbContacts extends CvModelBase {
|
||||||
$columnAccepted INT NOT NULL DEFAULT 0,
|
$columnAccepted INT NOT NULL DEFAULT 0,
|
||||||
$columnRequested INT NOT NULL DEFAULT 0,
|
$columnRequested INT NOT NULL DEFAULT 0,
|
||||||
$columnBlocked INT NOT NULL DEFAULT 0,
|
$columnBlocked INT NOT NULL DEFAULT 0,
|
||||||
|
$columnTotalMediaCounter INT NOT NULL DEFAULT 0,
|
||||||
$columnFlameCounter INT NOT NULL DEFAULT 0,
|
$columnFlameCounter INT NOT NULL DEFAULT 0,
|
||||||
$columnLastUpdateOfFlameCounter DATETIME DEFAULT CURRENT_TIMESTAMP,
|
$columnLastUpdateOfFlameCounter DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
$columnCreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP
|
$columnCreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
|
@ -74,7 +80,11 @@ class DbContacts extends CvModelBase {
|
||||||
static Future checkAndUpdateFlames(int userId) async {
|
static Future checkAndUpdateFlames(int userId) async {
|
||||||
List<Map<String, dynamic>> result = await dbProvider.db!.query(
|
List<Map<String, dynamic>> result = await dbProvider.db!.query(
|
||||||
tableName,
|
tableName,
|
||||||
columns: [columnLastUpdateOfFlameCounter, columnFlameCounter],
|
columns: [
|
||||||
|
columnLastUpdateOfFlameCounter,
|
||||||
|
columnFlameCounter,
|
||||||
|
columnTotalMediaCounter
|
||||||
|
],
|
||||||
where: '$columnUserId = ?',
|
where: '$columnUserId = ?',
|
||||||
whereArgs: [userId],
|
whereArgs: [userId],
|
||||||
);
|
);
|
||||||
|
|
@ -84,21 +94,28 @@ class DbContacts extends CvModelBase {
|
||||||
DateTime? lastUpdate = DateTime.tryParse(lastUpdateString);
|
DateTime? lastUpdate = DateTime.tryParse(lastUpdateString);
|
||||||
|
|
||||||
int currentCount = result.first.cast()[columnFlameCounter];
|
int currentCount = result.first.cast()[columnFlameCounter];
|
||||||
|
int totalMediaCounter = result.first.cast()[columnTotalMediaCounter];
|
||||||
if (lastUpdate != null &&
|
if (lastUpdate != null &&
|
||||||
lastUpdate.isAfter(DateTime.now().subtract(Duration(hours: 24)))) {
|
lastUpdate.isAfter(DateTime.now().subtract(Duration(hours: 24)))) {
|
||||||
_updateFlameCounter(userId, currentCount); // just update the time
|
_updateFlameCounter(userId, currentCount,
|
||||||
|
totalMediaCounter: totalMediaCounter + 1); // just update the time
|
||||||
} else {
|
} else {
|
||||||
_updateFlameCounter(userId, (currentCount + 1));
|
_updateFlameCounter(userId, (currentCount + 1),
|
||||||
|
totalMediaCounter: totalMediaCounter + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
globalCallBackOnContactChange();
|
globalCallBackOnContactChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future _updateFlameCounter(int userId, int newCount) async {
|
static Future _updateFlameCounter(int userId, int newCount,
|
||||||
|
{int? totalMediaCounter}) async {
|
||||||
Map<String, dynamic> valuesToUpdate = {
|
Map<String, dynamic> valuesToUpdate = {
|
||||||
columnFlameCounter: newCount,
|
columnFlameCounter: newCount,
|
||||||
columnLastUpdateOfFlameCounter: DateTime.now().toIso8601String()
|
columnLastUpdateOfFlameCounter: DateTime.now().toIso8601String()
|
||||||
};
|
};
|
||||||
|
if (totalMediaCounter != null) {
|
||||||
|
valuesToUpdate[columnTotalMediaCounter] = totalMediaCounter;
|
||||||
|
}
|
||||||
await dbProvider.db!.update(
|
await dbProvider.db!.update(
|
||||||
tableName,
|
tableName,
|
||||||
valuesToUpdate,
|
valuesToUpdate,
|
||||||
|
|
@ -116,6 +133,7 @@ class DbContacts extends CvModelBase {
|
||||||
columnAccepted,
|
columnAccepted,
|
||||||
columnRequested,
|
columnRequested,
|
||||||
columnFlameCounter,
|
columnFlameCounter,
|
||||||
|
columnTotalMediaCounter,
|
||||||
columnLastUpdateOfFlameCounter,
|
columnLastUpdateOfFlameCounter,
|
||||||
columnCreatedAt
|
columnCreatedAt
|
||||||
],
|
],
|
||||||
|
|
@ -139,6 +157,7 @@ class DbContacts extends CvModelBase {
|
||||||
parsedUsers.add(
|
parsedUsers.add(
|
||||||
Contact(
|
Contact(
|
||||||
userId: Int64(userId),
|
userId: Int64(userId),
|
||||||
|
totalMediaCounter: users.cast()[i][columnTotalMediaCounter],
|
||||||
displayName: users.cast()[i][columnDisplayName],
|
displayName: users.cast()[i][columnDisplayName],
|
||||||
accepted: users[i][columnAccepted] == 1,
|
accepted: users[i][columnAccepted] == 1,
|
||||||
flameCounter: flameCounter,
|
flameCounter: flameCounter,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:twonly/src/components/initialsavatar.dart';
|
import 'package:twonly/src/components/initialsavatar.dart';
|
||||||
|
|
@ -61,6 +63,13 @@ class _ChatListViewState extends State<ChatListView> {
|
||||||
.compareTo(lastMessages[b.userId.toInt()]!.sendOrReceivedAt);
|
.compareTo(lastMessages[b.userId.toInt()]!.sendOrReceivedAt);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
int maxTotalMediaCounter = 0;
|
||||||
|
if (allUsers.isNotEmpty) {
|
||||||
|
maxTotalMediaCounter = allUsers
|
||||||
|
.map((x) => x.totalMediaCounter)
|
||||||
|
.reduce((a, b) => a > b ? a : b);
|
||||||
|
}
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(AppLocalizations.of(context)!.chatsTitle),
|
title: Text(AppLocalizations.of(context)!.chatsTitle),
|
||||||
|
|
@ -113,6 +122,7 @@ class _ChatListViewState extends State<ChatListView> {
|
||||||
final user = activeUsers[index];
|
final user = activeUsers[index];
|
||||||
return UserListItem(
|
return UserListItem(
|
||||||
user: user,
|
user: user,
|
||||||
|
maxTotalMediaCounter: maxTotalMediaCounter,
|
||||||
lastMessage: lastMessages[user.userId.toInt()]!,
|
lastMessage: lastMessages[user.userId.toInt()]!,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
@ -124,12 +134,13 @@ class _ChatListViewState extends State<ChatListView> {
|
||||||
class UserListItem extends StatefulWidget {
|
class UserListItem extends StatefulWidget {
|
||||||
final Contact user;
|
final Contact user;
|
||||||
final DbMessage lastMessage;
|
final DbMessage lastMessage;
|
||||||
|
final int maxTotalMediaCounter;
|
||||||
|
|
||||||
const UserListItem({
|
const UserListItem(
|
||||||
super.key,
|
{super.key,
|
||||||
required this.user,
|
required this.user,
|
||||||
required this.lastMessage,
|
required this.lastMessage,
|
||||||
});
|
required this.maxTotalMediaCounter});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<UserListItem> createState() => _UserListItem();
|
State<UserListItem> createState() => _UserListItem();
|
||||||
|
|
@ -186,15 +197,13 @@ class _UserListItem extends State<UserListItem> {
|
||||||
style: TextStyle(fontSize: 12),
|
style: TextStyle(fontSize: 12),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 3),
|
const SizedBox(width: 3),
|
||||||
Image.asset(
|
Text(
|
||||||
"assets/icons/flame.png",
|
(widget.maxTotalMediaCounter ==
|
||||||
width: 9,
|
widget.user.totalMediaCounter)
|
||||||
),
|
? "❤️🔥"
|
||||||
// FaIcon(
|
: "🔥",
|
||||||
// FontAwesomeIcons.fireFlameCurved,
|
style: TextStyle(fontSize: 10),
|
||||||
// color: const Color.fromARGB(255, 215, 131, 58),
|
)
|
||||||
// size: 10,
|
|
||||||
// ),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue