summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2016-02-01 14:44:17 -0800
committer=Corey Hulen <corey@hulen.com>2016-02-01 14:44:17 -0800
commitb4ec6900510077253290e361d1a706e5368a45de (patch)
tree6fc7c131fa7aa5f32e3aba8102416aa23c65963d /model
parentea71731f838fc010cfc7511c09875184d1b2396b (diff)
parentf28486c4553f7f4bccf7bf69153c2f12699705f9 (diff)
downloadchat-b4ec6900510077253290e361d1a706e5368a45de.tar.gz
chat-b4ec6900510077253290e361d1a706e5368a45de.tar.bz2
chat-b4ec6900510077253290e361d1a706e5368a45de.zip
Fixing merge
Diffstat (limited to 'model')
-rw-r--r--model/client.go11
-rw-r--r--model/search_params.go18
-rw-r--r--model/search_params_test.go10
-rw-r--r--model/utils.go20
-rw-r--r--model/utils_test.go43
-rw-r--r--model/version.go69
-rw-r--r--model/version_test.go52
7 files changed, 155 insertions, 68 deletions
diff --git a/model/client.go b/model/client.go
index 21b8d8f7a..a271e6162 100644
--- a/model/client.go
+++ b/model/client.go
@@ -820,6 +820,17 @@ func (c *Client) UpdateUserRoles(data map[string]string) (*Result, *AppError) {
}
}
+func (c *Client) AttachDeviceId(deviceId string) (*Result, *AppError) {
+ data := make(map[string]string)
+ data["device_id"] = deviceId
+ if r, err := c.DoApiPost("/users/attach_device", MapToJson(data)); err != nil {
+ return nil, err
+ } else {
+ return &Result{r.Header.Get(HEADER_REQUEST_ID),
+ r.Header.Get(HEADER_ETAG_SERVER), UserFromJson(r.Body)}, nil
+ }
+}
+
func (c *Client) UpdateActive(userId string, active bool) (*Result, *AppError) {
data := make(map[string]string)
data["user_id"] = userId
diff --git a/model/search_params.go b/model/search_params.go
index 17a64d980..9a7406a07 100644
--- a/model/search_params.go
+++ b/model/search_params.go
@@ -20,12 +20,7 @@ func splitWordsNoQuotes(text string) []string {
words := []string{}
for _, word := range strings.Fields(text) {
- word = puncStart.ReplaceAllString(word, "")
- word = puncEnd.ReplaceAllString(word, "")
-
- if len(word) != 0 {
- words = append(words, word)
- }
+ words = append(words, word)
}
return words
@@ -94,7 +89,16 @@ func parseSearchFlags(input []string) ([]string, [][2]string) {
}
if !isFlag {
- words = append(words, word)
+ // trim off surrounding punctuation
+ word = puncStart.ReplaceAllString(word, "")
+ word = puncEnd.ReplaceAllString(word, "")
+
+ // and remove extra pound #s
+ word = hashtagStart.ReplaceAllString(word, "#")
+
+ if len(word) != 0 {
+ words = append(words, word)
+ }
}
}
diff --git a/model/search_params_test.go b/model/search_params_test.go
index af4cbe595..59eb0a113 100644
--- a/model/search_params_test.go
+++ b/model/search_params_test.go
@@ -118,19 +118,19 @@ func TestParseSearchFlags(t *testing.T) {
t.Fatalf("got incorrect flags %v", flags)
}
- if words, flags := parseSearchFlags(splitWords("fruit: cherry")); len(words) != 2 || words[0] != "fruit:" || words[1] != "cherry" {
+ if words, flags := parseSearchFlags(splitWords("fruit: cherry")); len(words) != 2 || words[0] != "fruit" || words[1] != "cherry" {
t.Fatalf("got incorrect words %v", words)
} else if len(flags) != 0 {
t.Fatalf("got incorrect flags %v", flags)
}
- if words, flags := parseSearchFlags(splitWords("channel:")); len(words) != 1 || words[0] != "channel:" {
+ if words, flags := parseSearchFlags(splitWords("channel:")); len(words) != 1 || words[0] != "channel" {
t.Fatalf("got incorrect words %v", words)
} else if len(flags) != 0 {
t.Fatalf("got incorrect flags %v", flags)
}
- if words, flags := parseSearchFlags(splitWords("channel: first in: second from:")); len(words) != 1 || words[0] != "from:" {
+ if words, flags := parseSearchFlags(splitWords("channel: first in: second from:")); len(words) != 1 || words[0] != "from" {
t.Fatalf("got incorrect words %v", words)
} else if len(flags) != 2 || flags[0][0] != "channel" || flags[0][1] != "first" || flags[1][0] != "in" || flags[1][1] != "second" {
t.Fatalf("got incorrect flags %v", flags)
@@ -212,4 +212,8 @@ func TestParseSearchParams(t *testing.T) {
if sp := ParseSearchParams("testing in:channel from:someone"); len(sp) != 1 || sp[0].Terms != "testing" || len(sp[0].InChannels) != 1 || sp[0].InChannels[0] != "channel" || len(sp[0].FromUsers) != 1 || sp[0].FromUsers[0] != "someone" {
t.Fatalf("Incorrect output from parse search params: %v", sp[0])
}
+
+ if sp := ParseSearchParams("##hashtag +#plus+"); len(sp) != 1 || sp[0].Terms != "#hashtag #plus" || sp[0].IsHashtag != true || len(sp[0].InChannels) != 0 || len(sp[0].FromUsers) != 0 {
+ t.Fatalf("Incorrect output from parse search params: %v", sp[0])
+ }
}
diff --git a/model/utils.go b/model/utils.go
index 70b7e3bbd..695d4a0cb 100644
--- a/model/utils.go
+++ b/model/utils.go
@@ -71,16 +71,6 @@ func AppErrorFromJson(data io.Reader) *AppError {
}
}
-func NewAppError(where string, message string, details string) *AppError {
- ap := &AppError{}
- ap.Message = message
- ap.Where = where
- ap.DetailedError = details
- ap.StatusCode = 500
- ap.IsOAuth = false
- return ap
-}
-
func NewLocAppError(where string, id string, params map[string]interface{}, details string) *AppError {
ap := &AppError{}
ap.Id = id
@@ -298,8 +288,9 @@ func Etag(parts ...interface{}) string {
}
var validHashtag = regexp.MustCompile(`^(#[A-Za-zäöüÄÖÜß]+[A-Za-z0-9äöüÄÖÜß_\-]*[A-Za-z0-9äöüÄÖÜß])$`)
-var puncStart = regexp.MustCompile(`^[.,()&$!\?\[\]{}':;\\]+`)
-var puncEnd = regexp.MustCompile(`[.,()&$#!\?\[\]{}';\\]+$`)
+var puncStart = regexp.MustCompile(`^[.,()&$!\?\[\]{}':;\\<>\-+=%^*|]+`)
+var hashtagStart = regexp.MustCompile(`^#{2,}`)
+var puncEnd = regexp.MustCompile(`[.,()&$#!\?\[\]{}':;\\<>\-+=%^*|]+$`)
func ParseHashtags(text string) (string, string) {
words := strings.Fields(text)
@@ -307,8 +298,13 @@ func ParseHashtags(text string) (string, string) {
hashtagString := ""
plainString := ""
for _, word := range words {
+ // trim off surrounding punctuation
word = puncStart.ReplaceAllString(word, "")
word = puncEnd.ReplaceAllString(word, "")
+
+ // and remove extra pound #s
+ word = hashtagStart.ReplaceAllString(word, "#")
+
if validHashtag.MatchString(word) {
hashtagString += " " + word
} else {
diff --git a/model/utils_test.go b/model/utils_test.go
index 24ee4b7a6..02a08d113 100644
--- a/model/utils_test.go
+++ b/model/utils_test.go
@@ -27,7 +27,7 @@ func TestRandomString(t *testing.T) {
}
func TestAppError(t *testing.T) {
- err := NewAppError("TestAppError", "message", "")
+ err := NewLocAppError("TestAppError", "message", nil, "")
json := err.ToJson()
rerr := AppErrorFromJson(strings.NewReader(json))
if err.Message != rerr.Message {
@@ -83,19 +83,34 @@ func TestEtag(t *testing.T) {
}
var hashtags map[string]string = map[string]string{
- "#test": "#test",
- "test": "",
- "#test123": "#test123",
- "#123test123": "",
- "#test-test": "#test-test",
- "#test?": "#test",
- "hi #there": "#there",
- "#bug #idea": "#bug #idea",
- "#bug or #gif!": "#bug #gif",
- "#hüllo": "#hüllo",
- "#?test": "",
- "#-test": "",
- "#yo_yo": "#yo_yo",
+ "#test": "#test",
+ "test": "",
+ "#test123": "#test123",
+ "#123test123": "",
+ "#test-test": "#test-test",
+ "#test?": "#test",
+ "hi #there": "#there",
+ "#bug #idea": "#bug #idea",
+ "#bug or #gif!": "#bug #gif",
+ "#hüllo": "#hüllo",
+ "#?test": "",
+ "#-test": "",
+ "#yo_yo": "#yo_yo",
+ "(#brakets)": "#brakets",
+ ")#stekarb(": "#stekarb",
+ "<#less_than<": "#less_than",
+ ">#greater_than>": "#greater_than",
+ "-#minus-": "#minus",
+ "+#plus+": "#plus",
+ "=#equals=": "#equals",
+ "%#pct%": "#pct",
+ "&#and&": "#and",
+ "^#hat^": "#hat",
+ "##brown#": "#brown",
+ "*#star*": "#star",
+ "|#pipe|": "#pipe",
+ ":#colon:": "#colon",
+ ";#semi;": "#semi",
}
func TestParseHashtags(t *testing.T) {
diff --git a/model/version.go b/model/version.go
index 4a642d017..a5227f328 100644
--- a/model/version.go
+++ b/model/version.go
@@ -4,6 +4,7 @@
package model
import (
+ "fmt"
"strconv"
"strings"
)
@@ -25,10 +26,27 @@ var versions = []string{
}
var CurrentVersion string = versions[0]
-var BuildNumber = "dev"
-var BuildDate = "Fri Jan 8 14:19:26 UTC 2016"
-var BuildHash = "001a4448ca5fb0018eeb442915b473b121c04bf3"
-var BuildEnterpriseReady = "false"
+
+var BuildNumber = "_BUILD_NUMBER_"
+var BuildDate = "_BUILD_DATE_"
+var BuildHash = "_BUILD_HASH_"
+var BuildEnterpriseReady = "_BUILD_ENTERPRISE_READY_"
+var versionsWithoutHotFixes []string
+
+func init() {
+ versionsWithoutHotFixes = make([]string, 0, len(versions))
+ seen := make(map[string]string)
+
+ for _, version := range versions {
+ maj, min, _ := SplitVersion(version)
+ verStr := fmt.Sprintf("%v.%v.0", maj, min)
+
+ if seen[verStr] == "" {
+ versionsWithoutHotFixes = append(versionsWithoutHotFixes, verStr)
+ seen[verStr] = verStr
+ }
+ }
+}
func SplitVersion(version string) (int64, int64, int64) {
parts := strings.Split(version, ".")
@@ -52,25 +70,17 @@ func SplitVersion(version string) (int64, int64, int64) {
return major, minor, patch
}
-func GetPreviousVersion(currentVersion string) (int64, int64) {
- currentIndex := -1
- currentMajor, currentMinor, _ := SplitVersion(currentVersion)
-
- for index, version := range versions {
- major, minor, _ := SplitVersion(version)
-
- if currentMajor == major && currentMinor == minor {
- currentIndex = index
- }
+func GetPreviousVersion(version string) string {
+ verMajor, verMinor, _ := SplitVersion(version)
+ verStr := fmt.Sprintf("%v.%v.0", verMajor, verMinor)
- if currentIndex >= 0 {
- if currentMajor != major || currentMinor != minor {
- return major, minor
- }
+ for index, v := range versionsWithoutHotFixes {
+ if v == verStr && len(versionsWithoutHotFixes) > index+1 {
+ return versionsWithoutHotFixes[index+1]
}
}
- return 0, 0
+ return ""
}
func IsOfficalBuild() bool {
@@ -88,13 +98,24 @@ func IsCurrentVersion(versionToCheck string) bool {
}
}
-func IsPreviousVersion(versionToCheck string) bool {
+func IsPreviousVersionsSupported(versionToCheck string) bool {
toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck)
- prevMajor, prevMinor := GetPreviousVersion(CurrentVersion)
+ versionToCheckStr := fmt.Sprintf("%v.%v.0", toCheckMajor, toCheckMinor)
- if toCheckMajor == prevMajor && toCheckMinor == prevMinor {
+ // Current Supported
+ if versionsWithoutHotFixes[0] == versionToCheckStr {
+ return true
+ }
+
+ // Current - 1 Supported
+ if versionsWithoutHotFixes[1] == versionToCheckStr {
return true
- } else {
- return false
}
+
+ // Current - 2 Supported
+ if versionsWithoutHotFixes[2] == versionToCheckStr {
+ return true
+ }
+
+ return false
}
diff --git a/model/version_test.go b/model/version_test.go
index 33e8dc93e..d73273ce5 100644
--- a/model/version_test.go
+++ b/model/version_test.go
@@ -36,20 +36,28 @@ func TestSplitVersion(t *testing.T) {
}
func TestGetPreviousVersion(t *testing.T) {
- if major, minor := GetPreviousVersion("1.0.0"); major != 0 || minor != 7 {
- t.Fatal(major, minor)
+ if GetPreviousVersion("1.3.0") != "1.2.0" {
+ t.Fatal()
+ }
+
+ if GetPreviousVersion("1.2.1") != "1.1.0" {
+ t.Fatal()
+ }
+
+ if GetPreviousVersion("1.1.0") != "1.0.0" {
+ t.Fatal()
}
- if major, minor := GetPreviousVersion("0.7.0"); major != 0 || minor != 6 {
- t.Fatal(major, minor)
+ if GetPreviousVersion("1.0.0") != "0.7.0" {
+ t.Fatal()
}
- if major, minor := GetPreviousVersion("0.7.1"); major != 0 || minor != 6 {
- t.Fatal(major, minor)
+ if GetPreviousVersion("0.7.1") != "0.6.0" {
+ t.Fatal()
}
- if major, minor := GetPreviousVersion("0.7111.1"); major != 0 || minor != 0 {
- t.Fatal(major, minor)
+ if GetPreviousVersion("0.5.0") != "" {
+ t.Fatal()
}
}
@@ -72,3 +80,31 @@ func TestIsCurrentVersion(t *testing.T) {
t.Fatal()
}
}
+
+func TestIsPreviousVersionsSupported(t *testing.T) {
+
+ // 1.4.0 CURRENT RELEASED VERSION
+ if !IsPreviousVersionsSupported(versions[0]) {
+ t.Fatal()
+ }
+
+ // 1.3.0
+ if !IsPreviousVersionsSupported(versions[1]) {
+ t.Fatal()
+ }
+
+ // 1.2.1
+ if !IsPreviousVersionsSupported(versions[2]) {
+ t.Fatal()
+ }
+
+ // 1.2.0
+ if !IsPreviousVersionsSupported(versions[3]) {
+ t.Fatal()
+ }
+
+ // 1.1.0 NOT SUPPORTED
+ if IsPreviousVersionsSupported(versions[4]) {
+ t.Fatal()
+ }
+}