summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2017-02-23 08:53:43 -0500
committerJoram Wilander <jwawilander@gmail.com>2017-02-23 08:53:43 -0500
commitca7d3b6e7bc2e52cf40180a462492313f298e760 (patch)
tree4401b86f65d5a31bdaf3162a43969509b1f30229
parent3b0f7163ab7e58a04c1fcadf7f615448bd4395a0 (diff)
downloadchat-ca7d3b6e7bc2e52cf40180a462492313f298e760.tar.gz
chat-ca7d3b6e7bc2e52cf40180a462492313f298e760.tar.bz2
chat-ca7d3b6e7bc2e52cf40180a462492313f298e760.zip
Adding device Id for version 2 of native apps (#5505)
* Adding device Id for version 2 * Changing ids
-rw-r--r--api/user.go5
-rw-r--r--api/user_test.go31
-rw-r--r--model/push_notification.go17
-rw-r--r--model/session.go3
-rw-r--r--store/sql_session_store_test.go20
5 files changed, 61 insertions, 15 deletions
diff --git a/api/user.go b/api/user.go
index cdb8f4f3e..a81aa85a0 100644
--- a/api/user.go
+++ b/api/user.go
@@ -206,11 +206,6 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !(strings.HasPrefix(deviceId, model.PUSH_NOTIFY_APPLE+":") || strings.HasPrefix(deviceId, model.PUSH_NOTIFY_ANDROID+":")) {
- c.SetInvalidParam("attachDevice", "deviceId")
- return
- }
-
// A special case where we logout of all other sessions with the same device id
if err := app.RevokeSessionsForDeviceId(c.Session.UserId, deviceId, c.Session.Id); err != nil {
c.Err = err
diff --git a/api/user_test.go b/api/user_test.go
index bf1059d2a..68472c6d1 100644
--- a/api/user_test.go
+++ b/api/user_test.go
@@ -1114,6 +1114,37 @@ func TestUserUpdateDeviceId(t *testing.T) {
}
}
+func TestUserUpdateDeviceId2(t *testing.T) {
+ th := Setup().InitBasic()
+ Client := th.BasicClient
+
+ team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
+ team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
+
+ user := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
+ user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
+ LinkUserToTeam(user, team)
+ store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
+
+ Client.Login(user.Email, "passwd1")
+ Client.SetTeamId(team.Id)
+ deviceId := model.PUSH_NOTIFY_APPLE_REACT_NATIVE + ":1234567890"
+
+ if _, err := Client.AttachDeviceId(deviceId); err != nil {
+ t.Fatal(err)
+ }
+
+ if result := <-app.Srv.Store.Session().GetSessions(user.Id); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ sessions := result.Data.([]*model.Session)
+
+ if sessions[0].DeviceId != deviceId {
+ t.Fatal("Missing device Id")
+ }
+ }
+}
+
func TestUserUpdateActive(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
Client := th.BasicClient
diff --git a/model/push_notification.go b/model/push_notification.go
index 3c010fb75..c426e01e5 100644
--- a/model/push_notification.go
+++ b/model/push_notification.go
@@ -10,8 +10,10 @@ import (
)
const (
- PUSH_NOTIFY_APPLE = "apple"
- PUSH_NOTIFY_ANDROID = "android"
+ PUSH_NOTIFY_APPLE = "apple"
+ PUSH_NOTIFY_ANDROID = "android"
+ PUSH_NOTIFY_APPLE_REACT_NATIVE = "apple_rn"
+ PUSH_NOTIFY_ANDROID_REACT_NATIVE = "android_rn"
PUSH_TYPE_MESSAGE = "message"
PUSH_TYPE_CLEAR = "clear"
@@ -46,12 +48,11 @@ func (me *PushNotification) ToJson() string {
}
func (me *PushNotification) SetDeviceIdAndPlatform(deviceId string) {
- if strings.HasPrefix(deviceId, PUSH_NOTIFY_APPLE+":") {
- me.Platform = PUSH_NOTIFY_APPLE
- me.DeviceId = strings.TrimPrefix(deviceId, PUSH_NOTIFY_APPLE+":")
- } else if strings.HasPrefix(deviceId, PUSH_NOTIFY_ANDROID+":") {
- me.Platform = PUSH_NOTIFY_ANDROID
- me.DeviceId = strings.TrimPrefix(deviceId, PUSH_NOTIFY_ANDROID+":")
+
+ parts := strings.Split(deviceId, ":")
+ if len(parts) == 2 {
+ me.Platform = parts[0]
+ me.DeviceId = parts[1]
}
}
diff --git a/model/session.go b/model/session.go
index d8f9d5fab..277e910f6 100644
--- a/model/session.go
+++ b/model/session.go
@@ -111,8 +111,7 @@ func (me *Session) GetTeamByTeamId(teamId string) *TeamMember {
}
func (me *Session) IsMobileApp() bool {
- return len(me.DeviceId) > 0 &&
- (strings.HasPrefix(me.DeviceId, PUSH_NOTIFY_APPLE+":") || strings.HasPrefix(me.DeviceId, PUSH_NOTIFY_ANDROID+":"))
+ return len(me.DeviceId) > 0
}
func (me *Session) GetUserRoles() []string {
diff --git a/store/sql_session_store_test.go b/store/sql_session_store_test.go
index 24526a4a9..aa088b377 100644
--- a/store/sql_session_store_test.go
+++ b/store/sql_session_store_test.go
@@ -197,6 +197,26 @@ func TestSessionUpdateDeviceId(t *testing.T) {
}
}
+func TestSessionUpdateDeviceId2(t *testing.T) {
+ Setup()
+
+ s1 := model.Session{}
+ s1.UserId = model.NewId()
+ Must(store.Session().Save(&s1))
+
+ if rs1 := (<-store.Session().UpdateDeviceId(s1.Id, model.PUSH_NOTIFY_APPLE_REACT_NATIVE+":1234567890", s1.ExpiresAt)); rs1.Err != nil {
+ t.Fatal(rs1.Err)
+ }
+
+ s2 := model.Session{}
+ s2.UserId = model.NewId()
+ Must(store.Session().Save(&s2))
+
+ if rs2 := (<-store.Session().UpdateDeviceId(s2.Id, model.PUSH_NOTIFY_APPLE_REACT_NATIVE+":1234567890", s1.ExpiresAt)); rs2.Err != nil {
+ t.Fatal(rs2.Err)
+ }
+}
+
func TestSessionStoreUpdateLastActivityAt(t *testing.T) {
Setup()