Files
bluebubbles-app/lib/helpers/ui/reaction_helpers.dart
zlshames ec81edfd45 renamed models folder to database
- fix: startup issue
2024-08-15 09:49:31 -04:00

86 lines
2.6 KiB
Dart

import 'package:bluebubbles/database/models.dart' hide Entity;
import 'package:emojis/emojis.dart';
import 'package:flutter/foundation.dart';
class ReactionTypes {
// ignore: non_constant_identifier_names
static const String LOVE = "love";
// ignore: non_constant_identifier_names
static const String LIKE = "like";
// ignore: non_constant_identifier_names
static const String DISLIKE = "dislike";
// ignore: non_constant_identifier_names
static const String LAUGH = "laugh";
// ignore: non_constant_identifier_names
static const String EMPHASIZE = "emphasize";
// ignore: non_constant_identifier_names
static const String QUESTION = "question";
static List<String> toList() {
return [
LOVE,
LIKE,
DISLIKE,
LAUGH,
EMPHASIZE,
QUESTION,
];
}
static final Map<String, String> reactionToVerb = {
LOVE: "loved",
LIKE: "liked",
DISLIKE: "disliked",
LAUGH: "laughed at",
EMPHASIZE: "emphasized",
QUESTION: "questioned",
"-$LOVE": "removed a heart from",
"-$LIKE": "removed a like from",
"-$DISLIKE": "removed a dislike from",
"-$LAUGH": "removed a laugh from",
"-$EMPHASIZE": "removed an exclamation from",
"-$QUESTION": "removed a question mark from",
};
static final Map<String, String> reactionToEmoji = {
LOVE: Emojis.redHeart,
LIKE: Emojis.thumbsUp,
DISLIKE: Emojis.thumbsDown,
LAUGH: Emojis.faceWithTearsOfJoy,
EMPHASIZE: Emojis.redExclamationMark,
QUESTION: Emojis.redQuestionMark,
};
static final Map<String, String> emojiToReaction = {
Emojis.redHeart: LOVE,
Emojis.thumbsUp: LIKE,
Emojis.thumbsDown: DISLIKE,
Emojis.faceWithTearsOfJoy: LAUGH,
Emojis.redExclamationMark: EMPHASIZE,
Emojis.redQuestionMark: QUESTION,
};
}
List<Message> getUniqueReactionMessages(List<Message> messages) {
List<int> handleCache = [];
List<Message> output = [];
// Sort the messages, putting the latest at the top
final ids = messages.map((e) => e.guid).toSet();
messages.retainWhere((element) => ids.remove(element.guid));
messages.sort(Message.sort);
// Iterate over the messages and insert the latest reaction for each user
for (Message msg in messages) {
int cache = msg.isFromMe! ? 0 : msg.handleId ?? 0;
if (!handleCache.contains(cache) && !kIsWeb) {
handleCache.add(cache);
// Only add the reaction if it's not a "negative"
if (!msg.associatedMessageType!.startsWith("-")) {
output.add(msg);
}
} else if (kIsWeb && !msg.associatedMessageType!.startsWith("-")) {
output.add(msg);
}
}
return output;
}