MM-54182 - add correct information to session table from mobile devices (#24353)

* MM-54182 - add correct information to session table from mobile devices

* improve comments around helper function

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Pablo Andrés Vélez Vidal
2023-09-01 14:25:07 +02:00
коммит произвёл GitHub
родитель 8c2fc88471
Коммит 4f0f3845e4
5 изменённых файлов: 67 добавлений и 4 удалений

Просмотреть файл

@@ -84,6 +84,11 @@ func getOSName(ua *uasurfer.UserAgent) string {
}
func getBrowserVersion(ua *uasurfer.UserAgent, userAgentString string) string {
if index := strings.Index(userAgentString, "Mattermost Mobile/"); index != -1 {
afterVersion := userAgentString[index+len("Mattermost Mobile/"):]
return strings.Fields(afterVersion)[0]
}
if index := strings.Index(userAgentString, "Mattermost/"); index != -1 {
afterVersion := userAgentString[index+len("Mattermost/"):]
return strings.Fields(afterVersion)[0]
@@ -123,10 +128,15 @@ var browserNames = map[uasurfer.BrowserName]string{
func getBrowserName(ua *uasurfer.UserAgent, userAgentString string) string {
browser := ua.Browser.Name
if strings.Contains(userAgentString, "Mattermost") {
if strings.Contains(userAgentString, "Electron") ||
(strings.Contains(userAgentString, "Mattermost") && !strings.Contains(userAgentString, "Mattermost Mobile")) {
return "Desktop App"
}
if strings.Contains(userAgentString, "Mattermost Mobile") {
return "Mobile App"
}
if strings.Contains(userAgentString, "mmctl") {
return "mmctl"
}

Просмотреть файл

@@ -33,6 +33,7 @@ var testUserAgents = []testUserAgent{
{"Safari 9", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Safari/604.1.38"},
{"Safari 8", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7 Safari/600.7.12"},
{"Safari Mobile", "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B137 Safari/601.1"},
{"Mobile App", "Mattermost Mobile/2.7.0+482 (Android; 13; sdk_gphone64_arm64)"},
}
func TestGetPlatformName(t *testing.T) {
@@ -53,6 +54,7 @@ func TestGetPlatformName(t *testing.T) {
"Macintosh",
"Macintosh",
"iPhone",
"Linux",
}
for i, userAgent := range testUserAgents {
@@ -83,6 +85,7 @@ func TestGetOSName(t *testing.T) {
"Mac OS",
"Mac OS",
"iOS",
"Android",
}
for i, userAgent := range testUserAgents {
@@ -103,7 +106,7 @@ func TestGetBrowserName(t *testing.T) {
"Chrome",
"mmctl",
"Desktop App",
"Chrome",
"Desktop App",
"Edge",
"Internet Explorer",
"Internet Explorer",
@@ -113,6 +116,7 @@ func TestGetBrowserName(t *testing.T) {
"Safari",
"Safari",
"Safari",
"Mobile App",
}
for i, userAgent := range testUserAgents {
@@ -143,6 +147,7 @@ func TestGetBrowserVersion(t *testing.T) {
"11.0",
"8.0.7",
"9.0",
"2.7.0+482",
}
for i, userAgent := range testUserAgents {