[fix #2870] Mark 1-1 chat as inactive when user removes it

This commit is contained in:
Dmitry Novotochinov 2018-01-08 12:52:48 +03:00
parent b76095e599
commit 350fc7aa03
No known key found for this signature in database
GPG Key ID: 267674DCC86628D9
3 changed files with 17 additions and 12 deletions

View File

@ -28,16 +28,18 @@
(messages/delete-by-chat-id id)))
(defn delete-messages!
[{:keys [current-chat-id]} [_ chat-id]]
(let [id (or chat-id current-chat-id)]
(messages/delete-by-chat-id id)))
[{:keys [current-chat-id chats]} [_ chat-id]]
(let [id (or chat-id current-chat-id)
{:keys [group-chat]} (chats/get-by-id chat-id)]
(when group-chat
(messages/delete-by-chat-id id))))
(defn delete-chat!
[_ [_ chat-id]]
(let [{:keys [debug? group-chat]} (chats/get-by-id chat-id)]
(if (and (not debug?) group-chat)
(chats/set-inactive chat-id)
(chats/delete chat-id))))
(let [{:keys [debug?]} (chats/get-by-id chat-id)]
(if debug?
(chats/delete chat-id)
(chats/set-inactive chat-id))))
(defn remove-pending-messages!
[_ [_ chat-id]]

View File

@ -44,7 +44,8 @@
(let [chat (merge (or (get-stored-chat chat-id)
(create-new-chat cofx chat-id {}))
chat)]
{:db (update-in db [:chats chat-id] merge chat)
{:db (cond-> db
(:is-active chat) (update-in [:chats chat-id] merge chat))
:save-chat chat}))
;; TODO (yenda): an upsert is suppose to add the entry if it doesn't

View File

@ -42,13 +42,15 @@
:or {clock-value 0}}]
(let [{:keys [access-scope->commands-responses] :contacts/keys [contacts]} db
{:keys [public-key] :as current-account} (get-current-account db)
chat-identifier (or group-id chat-id from)]
chat-identifier (or group-id chat-id from)
direct-message? (nil? group-id)]
;; proceed with adding message if message is not already stored in realm,
;; it's not from current user (outgoing message) and it's for relevant chat
;; (either current active chat or new chat not existing yet)
;; (either current active chat or new chat not existing yet or it's a direct message)
(when (and (not (message-exists? message-id))
(not= from public-key)
(pop-up-chat? chat-identifier))
(or (pop-up-chat? chat-identifier)
direct-message?))
(let [fx (if (get-in db [:chats chat-identifier])
(chat-model/upsert-chat cofx {:chat-id chat-identifier
:group-chat (boolean group-id)})