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