'Clear history', 'Leave chat' handlers

Former-commit-id: 1fe23fe57c
This commit is contained in:
virvar 2016-05-16 15:19:13 +03:00
parent 8919410735
commit 435d11eb2a
4 changed files with 34 additions and 7 deletions

View File

@ -113,14 +113,12 @@
:icon-style {:width 12
:height 12}
:title "Clear history"
:subtitle "!not implemented"
:handler nil}
:handler #(dispatch [:clear-history])}
{:icon :bin
:icon-style {:width 12
:height 18}
:title "Delete and leave"
:subtitle "!not implemented"
:handler nil}]]
:handler #(dispatch [:leave-group-chat])}]]
[view st/settings-container
(for [setting settings]
^{:key setting} [setting-view setting])]))

View File

@ -14,7 +14,8 @@
[syng-im.models.messages :refer [save-message
update-message!
message-by-id
get-messages]]
get-messages
clear-history]]
[syng-im.models.commands :as commands :refer [set-chat-command
set-response-chat-command
set-chat-command-content
@ -41,6 +42,7 @@
chat-add-participants
chat-remove-participants
set-chat-active
delete-chat
re-join-group-chat
chat-by-id2] :as chats]
[syng-im.models.chat :refer [signal-chat-updated
@ -395,6 +397,13 @@
((after save-commands-to-realm!))
((after handle-commands))))
(register-handler :clear-history
(fn [db [action]]
(log/debug action)
(let [chat-id (current-chat-id db)]
(clear-history chat-id)
(signal-chat-updated db chat-id))))
(register-handler :leave-group-chat
(fn [db [action]]
(log/debug action)
@ -402,6 +411,8 @@
(api/leave-group-chat chat-id)
(set-chat-active chat-id false)
(left-chat-msg chat-id)
(delete-chat chat-id)
(dispatch [:navigate-back])
(signal-chat-updated db chat-id))))
(register-handler :send-group-chat-msg

View File

@ -186,3 +186,12 @@
(-> (r/get-by-field :chats :chat-id chat-id)
(r/single)
(aset "is-active" active?)))))
(defn delete-chat [chat-id]
(r/write
(fn []
(-> (r/get-by-field :chats :chat-id chat-id)
(r/single)
(r/delete))))
;; TODO temp. Update chat in db atom
(dispatch [:initialize-chats]))

View File

@ -1,5 +1,6 @@
(ns syng-im.models.messages
(:require [syng-im.persistence.realm :as r]
[re-frame.core :refer [dispatch]]
[cljs.reader :refer [read-string]]
[syng-im.utils.random :refer [timestamp]]
[syng-im.db :as db]
@ -41,8 +42,9 @@
:outgoing outgoing
:timestamp (timestamp)
:delivery-status nil
:same-author same-author
:same-direction same-direction} true))))))
;; TODO 'some?' is temp
:same-author (some? same-author)
:same-direction (some? same-direction)} true))))))
(defn get-messages [chat-id]
(->> (-> (r/get-by-field :msgs :chat-id chat-id)
@ -64,3 +66,10 @@
(fn []
(when (r/exists? :msgs :msg-id msg-id)
(r/create :msgs msg true)))))
(defn clear-history [chat-id]
(r/write
(fn []
(r/delete (r/get-by-field :msgs :chat-id chat-id))))
;; TODO temp. Update chat in db atom
(dispatch [:initialize-chats]))