@@ -44,34 +44,25 @@ INSERT INTO Contacts (UserId, ContactId, Status)
4444 }
4545 }
4646
47- public bool AddMutedContact ( int mutedByUserId , int mutedContactId , DateTime ? expirationDate = null , DateTime muteDate = default )
47+ public bool MuteContact ( int userId , int contactId , DateTime ? mutedUntil = null )
4848 {
49- if ( muteDate == default )
50- {
51- muteDate = DateTime . Now ;
52- }
53-
5449 const string query = @"
55- INSERT INTO MutedContacts (MutedByUserId, MutedContactId, MuteDate, ExpirationDate)
56- VALUES (@mutedByUserId, @mutedContactId, @muteDate, @expirationDate)
57- ON CONFLICT(MutedByUserId, MutedContactId)
58- DO UPDATE SET
59- MuteDate = @muteDate,
60- ExpirationDate = @expirationDate,
61- IsActive = 1" ;
50+ UPDATE Contacts
51+ SET MutedUntil = @mutedUntil
52+ WHERE UserId = @userId AND ContactId = @contactId" ;
6253
6354 using ( var connection = new SqliteConnection ( _connectionString ) )
6455 {
6556 try
6657 {
67- connection . Execute ( query , new
58+ string ? mutedUntilStr = mutedUntil ? . ToUniversalTime ( ) . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
59+ int affected = connection . Execute ( query , new
6860 {
69- mutedByUserId ,
70- mutedContactId ,
71- muteDate ,
72- expirationDate
61+ userId ,
62+ contactId ,
63+ mutedUntil = mutedUntilStr
7364 } ) ;
74- return true ;
65+ return affected > 0 ;
7566 }
7667 catch ( Exception ex )
7768 {
@@ -86,22 +77,24 @@ public class SqliteContactRemover(string connectionString) : IContactRemover
8677{
8778 private readonly string _connectionString = connectionString ;
8879
89- public void RemoveMutedContact ( int userId , int contactId )
80+ public bool UnmuteContact ( int userId , int contactId )
9081 {
9182 const string query = @"
92- UPDATE MutedContacts
93- SET IsActive = 0
94- WHERE MutedByUserId = @userId AND MutedContactId = @contactId" ;
83+ UPDATE Contacts
84+ SET MutedUntil = NULL
85+ WHERE UserId = @userId AND ContactId = @contactId" ;
9586
9687 using ( var connection = new SqliteConnection ( _connectionString ) )
9788 {
9889 try
9990 {
100- connection . Execute ( query , new { userId , contactId } ) ;
91+ int affected = connection . Execute ( query , new { userId , contactId } ) ;
92+ return affected > 0 ;
10193 }
10294 catch ( Exception ex )
10395 {
104- Log . Error ( ex , "An error occurred in the method {MethodName}" , nameof ( RemoveMutedContact ) ) ;
96+ Log . Error ( ex , "An error occurred in the method {MethodName}" , nameof ( UnmuteContact ) ) ;
97+ return false ;
10598 }
10699 }
107100 }
@@ -385,26 +378,28 @@ FROM Contacts
385378 }
386379 }
387380
388- public string GetActiveMuteTimeByContactID ( int contactID )
381+ public DateTime ? GetMutedUntil ( int userId , int contactId )
389382 {
390383 try
391384 {
392385 using var connection = new SqliteConnection ( _connectionString ) ;
393-
394- var expirationDate = connection . QueryFirstOrDefault < DateTime ? > (
395- @"SELECT ExpirationDate
396- FROM MutedContacts
397- WHERE MutedContactId = @contactID
398- AND IsActive = 1" ,
399- new { contactID } ) ;
400-
401- return expirationDate ? . ToString ( "yyyy-MM-dd HH:mm:ss" )
402- ?? Config . GetResourceString ( "NoActiveMute" ) ;
386+
387+ var mutedUntilStr = connection . QueryFirstOrDefault < string ? > (
388+ @"SELECT MutedUntil
389+ FROM Contacts
390+ WHERE UserId = @userId AND ContactId = @contactId" ,
391+ new { userId , contactId } ) ;
392+
393+ if ( mutedUntilStr != null && DateTime . TryParse ( mutedUntilStr , out var result ) )
394+ {
395+ return result ;
396+ }
397+ return null ;
403398 }
404399 catch ( Exception ex )
405400 {
406- Log . Error ( ex , "An error occurred in the method {MethodName}" , nameof ( GetActiveMuteTimeByContactID ) ) ;
407- return "" ;
401+ Log . Error ( ex , "An error occurred in the method {MethodName}" , nameof ( GetMutedUntil ) ) ;
402+ return null ;
408403 }
409404 }
410405
0 commit comments