summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2016-10-24 17:04:11 -0700
committerenahum <nahumhbl@gmail.com>2016-10-24 21:04:11 -0300
commit9071553165cfc9f073f57aab96a3e6a7c771c8f3 (patch)
tree0dabe6e35b0121997051e54d0823a4499d0cae70 /store
parent4d9f5173bc81fcaad8040b46b0d9950458412747 (diff)
downloadchat-9071553165cfc9f073f57aab96a3e6a7c771c8f3.tar.gz
chat-9071553165cfc9f073f57aab96a3e6a7c771c8f3.tar.bz2
chat-9071553165cfc9f073f57aab96a3e6a7c771c8f3.zip
PLT-4359 fixing push notification for more than 1 device (#4318)
* PLT-4359 fixing push notification for more than 1 device * Addressing feedback
Diffstat (limited to 'store')
-rw-r--r--store/sql_session_store.go22
-rw-r--r--store/sql_session_store_test.go28
-rw-r--r--store/store.go1
3 files changed, 51 insertions, 0 deletions
diff --git a/store/sql_session_store.go b/store/sql_session_store.go
index 4e1bea3cf..5892dab01 100644
--- a/store/sql_session_store.go
+++ b/store/sql_session_store.go
@@ -168,6 +168,28 @@ func (me SqlSessionStore) GetSessions(userId string) StoreChannel {
return storeChannel
}
+func (me SqlSessionStore) GetSessionsWithActiveDeviceIds(userId string) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+
+ result := StoreResult{}
+ var sessions []*model.Session
+
+ if _, err := me.GetReplica().Select(&sessions, "SELECT * FROM Sessions WHERE UserId = :UserId AND ExpiresAt != 0 AND :ExpiresAt <= ExpiresAt AND DeviceId != ''", map[string]interface{}{"UserId": userId, "ExpiresAt": model.GetMillis()}); err != nil {
+ result.Err = model.NewLocAppError("SqlSessionStore.GetActiveSessionsWithDeviceIds", "store.sql_session.get_sessions.app_error", nil, err.Error())
+ } else {
+
+ result.Data = sessions
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
func (me SqlSessionStore) Remove(sessionIdOrToken string) StoreChannel {
storeChannel := make(StoreChannel, 1)
diff --git a/store/sql_session_store_test.go b/store/sql_session_store_test.go
index e64a350ba..24526a4a9 100644
--- a/store/sql_session_store_test.go
+++ b/store/sql_session_store_test.go
@@ -50,7 +50,35 @@ func TestSessionGet(t *testing.T) {
t.Fatal("should match len")
}
}
+}
+
+func TestSessionGetWithDeviceId(t *testing.T) {
+ Setup()
+
+ s1 := model.Session{}
+ s1.UserId = model.NewId()
+ s1.ExpiresAt = model.GetMillis() + 10000
+ Must(store.Session().Save(&s1))
+
+ s2 := model.Session{}
+ s2.UserId = s1.UserId
+ s2.DeviceId = model.NewId()
+ s2.ExpiresAt = model.GetMillis() + 10000
+ Must(store.Session().Save(&s2))
+ s3 := model.Session{}
+ s3.UserId = s1.UserId
+ s3.ExpiresAt = 1
+ s3.DeviceId = model.NewId()
+ Must(store.Session().Save(&s3))
+
+ if rs1 := (<-store.Session().GetSessionsWithActiveDeviceIds(s1.UserId)); rs1.Err != nil {
+ t.Fatal(rs1.Err)
+ } else {
+ if len(rs1.Data.([]*model.Session)) != 1 {
+ t.Fatal("should match len")
+ }
+ }
}
func TestSessionRemove(t *testing.T) {
diff --git a/store/store.go b/store/store.go
index 900709f16..51aada920 100644
--- a/store/store.go
+++ b/store/store.go
@@ -172,6 +172,7 @@ type SessionStore interface {
Save(session *model.Session) StoreChannel
Get(sessionIdOrToken string) StoreChannel
GetSessions(userId string) StoreChannel
+ GetSessionsWithActiveDeviceIds(userId string) StoreChannel
Remove(sessionIdOrToken string) StoreChannel
RemoveAllSessions() StoreChannel
PermanentDeleteSessionsByUser(teamId string) StoreChannel