Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/.project
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
</natures>
<filteredResources>
<filter>
<id>1599102953393</id>
<id>1735201140808</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
Expand Down
4 changes: 2 additions & 2 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
arguments=
arguments=--init-script /var/folders/rt/c3f7yl0n12z7rf4m160f0p2r0000gn/T/db3b08fc4a9ef609cb16b96b200fa13e563f396e9bb1ed0905fdab7bc3bc513b.gradle --init-script /var/folders/rt/c3f7yl0n12z7rf4m160f0p2r0000gn/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle --init-script /var/folders/rt/c3f7yl0n12z7rf4m160f0p2r0000gn/T/bd95fba452cd16942039615189e617a1932f63d661f1f661840274c40bc05cbb.gradle
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/home/brandon/Downloads/jdk-14.0.2+12
java.home=/usr/local/Cellar/openjdk@11/11.0.25/libexec/openjdk.jdk/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
Expand Down
112 changes: 67 additions & 45 deletions lib/database/io/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ class Chat {
_latestMessage = latestMessage;
}

@Property()
bool isWhitelisted = false;

factory Chat.fromMap(Map<String, dynamic> json) {
final message = json['lastMessage'] != null ? Message.fromMap(json['lastMessage']!.cast<String, Object>()) : null;
return Chat(
Expand Down Expand Up @@ -486,6 +489,7 @@ class Chat {
bool updateAPNTitle = false,
bool updateGuidRefs = false,
bool updateTelephonyId = false,
bool updateWhitelisted = false,
}) {
if (kIsWeb) return this;
Database.runInTransaction(TxMode.write, () {
Expand Down Expand Up @@ -561,6 +565,9 @@ class Chat {
if (!updateTelephonyId) {
telephonyId = existing?.telephonyId ?? telephonyId;
}
if (updateWhitelisted) {
existing?.isWhitelisted = isWhitelisted;
}

/// Save the chat and add the participants
for (int i = 0; i < participants.length; i++) {
Expand Down Expand Up @@ -796,56 +803,59 @@ class Chat {

/// Return whether or not the notification should be muted
bool shouldMuteNotification(Message? message) {
/// Filter unknown senders & sender doesn't have a contact, then don't notify
if (ss.settings.filterUnknownSenders.value &&
participants.length == 1 &&
participants.first.contact == null) {
return true;

/// Check if global text detection is on and notify accordingly
} else if (ss.settings.globalTextDetection.value.isNotEmpty) {
List<String> text = ss.settings.globalTextDetection.value.split(",");
for (String s in text) {
if (message?.text?.toLowerCase().contains(s.toLowerCase()) ?? false) {
return false;
}
}
return true;

/// Check if muted
} else if (muteType == "mute") {
return true;

/// Check if the sender is muted
} else if (muteType == "mute_individuals") {
List<String> individuals = muteArgs!.split(",");
return individuals.contains(message?.handle?.address ?? "");

/// Check if the chat is temporarily muted
} else if (muteType == "temporary_mute") {
DateTime time = DateTime.parse(muteArgs!);
bool shouldMute = DateTime.now().toLocal().difference(time).inSeconds.isNegative;
if (!shouldMute) {
toggleMute(false);
// Unknown sender check
if (ss.settings.filterUnknownSenders.value &&
participants.length == 1 &&
participants.first.contact == null &&
!isWhitelisted) {
return true;
}

// Global text detection check
if (ss.settings.globalTextDetection.value.isNotEmpty) {
List<String> text = ss.settings.globalTextDetection.value.split(",");
for (String s in text) {
if (message?.text?.toLowerCase().contains(s.toLowerCase()) ?? false) {
return false;
}
return shouldMute;
}
return true;
}

/// Check if the chat has specific text detection and notify accordingly
} else if (muteType == "text_detection") {
List<String> text = muteArgs!.split(",");
for (String s in text) {
if (message?.text?.toLowerCase().contains(s.toLowerCase()) ?? false) {
return false;
}
}
return true;
// Individual muting checks
if (muteType == "mute") {
return true;
}

if (muteType == "mute_individuals") {
List<String> individuals = muteArgs!.split(",");
return individuals.contains(message?.handle?.address ?? "");
}

if (muteType == "temporary_mute") {
DateTime time = DateTime.parse(muteArgs!);
bool shouldMute = DateTime.now().toLocal().difference(time).inSeconds.isNegative;
if (!shouldMute) {
toggleMute(false);
}
return shouldMute;
}

/// If reaction and notify reactions off, then don't notify, otherwise notify
return !ss.settings.notifyReactions.value &&
ReactionTypes.toList().contains(message?.associatedMessageType ?? "");
if (muteType == "text_detection") {
List<String> text = muteArgs!.split(",");
for (String s in text) {
if (message?.text?.toLowerCase().contains(s.toLowerCase()) ?? false) {
return false;
}
}
return true;
}

// Reaction notification check
return !ss.settings.notifyReactions.value &&
ReactionTypes.toList().contains(message?.associatedMessageType ?? "");
}

/// Delete a chat locally. Prefer using softDelete so the chat doesn't come back
static void deleteChat(Chat chat) async {
if (kIsWeb) return;
Expand Down Expand Up @@ -1016,14 +1026,25 @@ class Chat {
serverSyncParticipants();
}

// Once we send a message, consider them "known"
if (message.isFromMe! && participants.length == 1 && participants.first.contact == null && ss.settings.filterUnknownSenders.value) {
isWhitelisted = true;
save(updateWhitelisted: true);
}

// Return the current chat instance (with updated vals)
return this;
}

// Add whitelisting check for participant changes
void serverSyncParticipants() async {
// Send message to server to get the participants
final prevParticipants = [...participants];
final chat = await cm.fetchChat(guid);
if (chat != null) {
// Preserve whitelisted status if becoming group chat
if (isWhitelisted && prevParticipants.length == 1 && chat.participants.length > 1) {
chat.isWhitelisted = true;
}
chat.save();
}
}
Expand Down Expand Up @@ -1320,6 +1341,7 @@ class Chat {
title ??= other.title;
dateDeleted ??= other.dateDeleted;
style ??= other.style;
isWhitelisted = other.isWhitelisted || isWhitelisted;
return this;
}

Expand Down
1 change: 1 addition & 0 deletions lib/services/backend/action_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class ActionHandler extends GetxService {
}

Future<void> sendMessage(Chat c, Message m, Message? selected, String? r) async {
if (c.isArchived!) c.toggleArchived(false);
final completer = Completer<void>();
if (r == null) {
backend.sendMessage(c, m).then((newMessage) async {
Expand Down