-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Conversation proteus verification (#2178)
* fix: Conversation Proteus verification * Fixed test
- v4.9.1
- v4.5.1
- testservice-2024-07-16
- internal-2024-26-01-rapid-raptor
- internal-2024-17-07-tasty-tuna
- internal-2024-10-01-Unique-Unicorn
- internal-2024-09-04-tasty-tuna
- internal-2024-08-20-tasty-tuna
- internal-2024-08-13-tasty-tuna
- internal-2024-08-06-tasty-tuna
- internal-2024-08-02-tasty-tuna
- internal-2024-07-30-tasty-tuna
- internal-2024-05-08-silly-sheep
- internal-2023-11-27-quintessential-quokka
- android-v4.9.2
- android-v4.9.1
- android-v4.9.0
- android-v4.8.5
- android-v4.8.4
- android-v4.8.3
- android-v4.8.2
- android-v4.8.1
- android-v4.8.0
- android-v4.7.1
- android-v4.7.0
- android-v4.6.5
- android-v4.6.4
- android-v4.6.3
- android-v4.6.2
- android-v4.6.1
- android-v4.6.0
- android-v4.5.4
- android-v4.5.3
- android-v4.5.2
- android-v4.5.0
- android-v4.5.0-pre-release
1 parent
43857ea
commit 021f22f
Showing
5 changed files
with
123 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
DROP TRIGGER IF EXISTS updateConversationProteusVerificationStatus; | ||
DROP TRIGGER IF EXISTS addMessageAfterProteusVerificationStatusChange; | ||
|
||
CREATE TRIGGER updateConversationProteusVerificationStatus | ||
AFTER UPDATE ON Client | ||
BEGIN | ||
UPDATE Conversation SET proteus_verification_status = (CASE (new.is_verified) WHEN 1 THEN "VERIFIED" ELSE "DEGRADED" END) | ||
WHERE qualified_id IN ( | ||
SELECT id FROM (SELECT | ||
conv.qualified_id AS id, | ||
conv.proteus_verification_status AS verificationStatus, | ||
-- +1 is to not count a current client, for checking if conversation is verified | ||
(COUNT(*) = 1 + SUM(CASE WHEN client.is_verified = 1 THEN 1 ELSE 0 END)) AS isActuallyVerified | ||
FROM Conversation AS conv | ||
LEFT JOIN Member AS mem ON conv.qualified_id = mem.conversation | ||
LEFT JOIN Client AS client ON client.user_id = mem.user | ||
WHERE conv.qualified_id IN (SELECT Member.conversation FROM Member | ||
LEFT JOIN Client ON Client.user_id = Member.user | ||
WHERE Client.id = new.id) | ||
GROUP BY conv.qualified_id) | ||
WHERE (CASE (verificationStatus) WHEN "VERIFIED" THEN 1 ELSE 0 END) != isActuallyVerified | ||
); | ||
END; | ||
|
||
CREATE TRIGGER addMessageAfterProteusVerificationStatusChange | ||
AFTER UPDATE ON Conversation | ||
WHEN new.proteus_verification_status != old.proteus_verification_status | ||
AND (new.proteus_verification_status = "VERIFIED" OR old.proteus_verification_status = "VERIFIED") | ||
BEGIN | ||
INSERT OR IGNORE INTO Message(id, content_type, conversation_id, creation_date, sender_user_id, sender_client_id, status, visibility) | ||
VALUES( | ||
(SELECT lower(hex(randomblob(4)) || '-' || lower(hex(randomblob(2))) || '-4' || | ||
substr(lower(hex(randomblob(2))),2) || '-a' || substr(lower(hex(randomblob(2))),2) | ||
|| '-' || lower(hex(randomblob(6))))), | ||
(CASE (new.proteus_verification_status) | ||
WHEN "VERIFIED" THEN "CONVERSATION_VERIFIED_PROTEUS" | ||
ELSE "CONVERSATION_DEGRADED_PROTEUS" END | ||
), | ||
new.qualified_id, | ||
(SELECT CAST((julianday('now') - 2440587.5) * 86400 * 1000 AS INTEGER)), | ||
(SELECT SelfUser.id FROM SelfUser LIMIT 1), | ||
(SELECT Client.id FROM Client WHERE Client.user_id = (SELECT SelfUser.id FROM SelfUser LIMIT 1) LIMIT 1), | ||
"SENT", | ||
"VISIBLE" | ||
); | ||
END; | ||
|
||
CREATE TRIGGER updateConversationProteusVerificationStatusAfterMemeberChange | ||
AFTER INSERT ON Member | ||
BEGIN | ||
UPDATE Conversation | ||
SET proteus_verification_status = | ||
(CASE (SELECT | ||
(COUNT(*) = 1 + SUM(CASE WHEN client.is_verified = 1 THEN 1 ELSE 0 END) AND COUNT(*) > 1) | ||
FROM Member AS mem | ||
LEFT JOIN Client AS client ON client.user_id = mem.user | ||
WHERE mem.conversation = new.conversation | ||
GROUP BY mem.conversation) | ||
WHEN 1 THEN "VERIFIED" | ||
ELSE "DEGRADED" END) | ||
WHERE qualified_id = new.conversation; | ||
END; | ||
|
||
CREATE TRIGGER updateConversationProteusVerificationStatusAfterMemeberDelete | ||
AFTER DELETE ON Member | ||
BEGIN | ||
UPDATE Conversation | ||
SET proteus_verification_status = | ||
(CASE (SELECT | ||
(COUNT(*) = 1 + SUM(CASE WHEN client.is_verified = 1 THEN 1 ELSE 0 END) AND COUNT(*) > 1) | ||
FROM Member AS mem | ||
LEFT JOIN Client AS client ON client.user_id = mem.user | ||
WHERE mem.conversation = old.conversation | ||
GROUP BY mem.conversation) | ||
WHEN 1 THEN "VERIFIED" | ||
ELSE "DEGRADED" END) | ||
WHERE qualified_id = old.conversation; | ||
END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters