[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))) (messages/delete-by-chat-id id)))
(defn delete-messages! (defn delete-messages!
[{:keys [current-chat-id]} [_ chat-id]] [{:keys [current-chat-id chats]} [_ chat-id]]
(let [id (or chat-id current-chat-id)] (let [id (or chat-id current-chat-id)
(messages/delete-by-chat-id id))) {:keys [group-chat]} (chats/get-by-id chat-id)]
(when group-chat
(messages/delete-by-chat-id id))))
(defn delete-chat! (defn delete-chat!
[_ [_ chat-id]] [_ [_ chat-id]]
(let [{:keys [debug? group-chat]} (chats/get-by-id chat-id)] (let [{:keys [debug?]} (chats/get-by-id chat-id)]
(if (and (not debug?) group-chat) (if debug?
(chats/set-inactive chat-id) (chats/delete chat-id)
(chats/delete chat-id)))) (chats/set-inactive chat-id))))
(defn remove-pending-messages! (defn remove-pending-messages!
[_ [_ chat-id]] [_ [_ chat-id]]

View File

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

View File

@ -42,13 +42,15 @@
:or {clock-value 0}}] :or {clock-value 0}}]
(let [{:keys [access-scope->commands-responses] :contacts/keys [contacts]} db (let [{:keys [access-scope->commands-responses] :contacts/keys [contacts]} db
{:keys [public-key] :as current-account} (get-current-account 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, ;; 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 ;; 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)) (when (and (not (message-exists? message-id))
(not= from public-key) (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]) (let [fx (if (get-in db [:chats chat-identifier])
(chat-model/upsert-chat cofx {:chat-id chat-identifier (chat-model/upsert-chat cofx {:chat-id chat-identifier
:group-chat (boolean group-id)}) :group-chat (boolean group-id)})