PLT-5506 Record user agent/device type in the active sessions list (#342)

* Add user info and userAgent

* notice
This commit is contained in:
enahum 2017-03-13 13:39:35 -03:00 committed by GitHub
parent a684c0f45b
commit 31d89c37fe
8 changed files with 58 additions and 1 deletions

View file

@ -801,3 +801,34 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
---
## react-native-device-info
This product contains 'react-native-device-info', library to provide a device information to react native on both iOS and Android.
* HOMEPAGE
* https://github.com/rebeccahughes/react-native-device-info
* LICENSE:
The MIT License (MIT)
Copyright (c) 2015 Rebecca Hughes
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -147,6 +147,7 @@ dependencies {
compile ('com.google.android.gms:play-services-gcm:9.0.0') {
force = true;
}
compile project(':react-native-device-info')
compile project(':react-native-cookies')
compile project(':react-native-vector-icons')
compile project(':react-native-svg')

View file

@ -4,6 +4,7 @@ import android.app.Application;
import android.util.Log;
import com.facebook.react.ReactApplication;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import com.psykar.cookiemanager.CookieManagerPackage;
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
import com.oblador.vectoricons.VectorIconsPackage;
@ -29,6 +30,7 @@ public class MainApplication extends Application implements ReactApplication {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNDeviceInfo(),
new CookieManagerPackage(),
new ReactNativePushNotificationPackage(),
new VectorIconsPackage(),

View file

@ -1,4 +1,6 @@
rootProject.name = 'Mattermost'
include ':react-native-device-info'
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')
include ':react-native-cookies'
project(':react-native-cookies').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cookies/android')
include ':react-native-push-notification'

View file

@ -4,8 +4,11 @@
import React, {PropTypes, PureComponent} from 'react';
import {AppState, View} from 'react-native';
import {IntlProvider} from 'react-intl';
import DeviceInfo from 'react-native-device-info';
import PushNotification from 'app/components/push_notification';
import Client from 'service/client';
import {Constants} from 'service/constants';
import {getTranslations} from 'service/i18n';
import EventEmitter from 'service/utils/event_emitter';
@ -34,6 +37,7 @@ export default class Root extends PureComponent {
componentDidMount() {
AppState.addEventListener('change', this.handleAppStateChange);
EventEmitter.on(Constants.CONFIG_CHANGED, this.handleConfigChanged);
Client.setUserAgent(DeviceInfo.getUserAgent());
}
componentWillUnmount() {

View file

@ -5,7 +5,6 @@
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; };
00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; };
@ -39,6 +38,7 @@
C035DB50ED2045F09923FFAE /* MaterialCommunityIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 04AA5E8EF3B54735A11E3B95 /* MaterialCommunityIcons.ttf */; };
C337E8708D2845C6A8DBB47E /* Ionicons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 2DCFD31D3F4A4154822AB532 /* Ionicons.ttf */; };
F006936FC2884C24A1321FC0 /* MaterialIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 356C9186FA374641A00EB2EA /* MaterialIcons.ttf */; };
10CD747CE4304BD6AB38B4CD /* libRNDeviceInfo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EE671DF7637347CD8C069819 /* libRNDeviceInfo.a */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -308,6 +308,8 @@
EDC04CBCF81642219D199CBB /* Octicons.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = Octicons.ttf; path = "../node_modules/react-native-vector-icons/Fonts/Octicons.ttf"; sourceTree = "<group>"; };
F1F071EE85494E269A50AE88 /* SimpleLineIcons.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = SimpleLineIcons.ttf; path = "../node_modules/react-native-vector-icons/Fonts/SimpleLineIcons.ttf"; sourceTree = "<group>"; };
F81F6DC42D394831B4549928 /* libRNSearchBar.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNSearchBar.a; sourceTree = "<group>"; };
B97AA6F961BB47D3A3297E8E /* RNDeviceInfo.xcodeproj */ = {isa = PBXFileReference; name = "RNDeviceInfo.xcodeproj"; path = "../node_modules/react-native-device-info/RNDeviceInfo.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
EE671DF7637347CD8C069819 /* libRNDeviceInfo.a */ = {isa = PBXFileReference; name = "libRNDeviceInfo.a"; path = "libRNDeviceInfo.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -339,6 +341,7 @@
7F63D2841E6C9585001FAE12 /* libRCTPushNotification.a in Frameworks */,
B50561A109B4442299F82327 /* libRNSearchBar.a in Frameworks */,
9906AC672C594EEB9D5EE503 /* libRNCookieManagerIOS.a in Frameworks */,
10CD747CE4304BD6AB38B4CD /* libRNDeviceInfo.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -546,6 +549,7 @@
2B25899FDAC149EB96ED3305 /* RNVectorIcons.xcodeproj */,
59954D479A89488091EB588F /* RNSearchBar.xcodeproj */,
31A0780E2F224AC8AF8E6930 /* RNCookieManagerIOS.xcodeproj */,
B97AA6F961BB47D3A3297E8E /* RNDeviceInfo.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
@ -1050,6 +1054,7 @@
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
@ -1068,6 +1073,7 @@
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";

View file

@ -13,6 +13,7 @@
"react-native": "0.40.0",
"react-native-button": "1.7.1",
"react-native-cookies": "2.0.0",
"react-native-device-info": "0.10.1",
"react-native-drawer": "2.3.0",
"react-native-keyboard-aware-scroll-view": "0.2.7",
"react-native-keyboard-spacer": "0.3.1",

View file

@ -11,6 +11,7 @@ const HEADER_BEARER = 'BEARER';
const HEADER_REQUESTED_WITH = 'X-Requested-With';
const HEADER_TOKEN = 'Token';
const HEADER_X_VERSION_ID = 'X-Version-Id';
const HEADER_USER_AGENT = 'User-Agent';
export default class Client {
constructor() {
@ -19,6 +20,7 @@ export default class Client {
this.url = '';
this.urlVersion = '/api/v3';
this.serverVersion = '';
this.userAgent = null;
this.translations = {
connectionError: 'There appears to be a problem with your internet connection.',
@ -34,6 +36,10 @@ export default class Client {
this.url = url;
}
setUserAgent(userAgent) {
this.userAgent = userAgent;
}
getToken() {
return this.token;
}
@ -135,6 +141,10 @@ export default class Client {
headers[HEADER_AUTH] = `${HEADER_BEARER} ${this.token}`;
}
if (this.userAgent) {
headers[HEADER_USER_AGENT] = this.userAgent;
}
if (options.headers) {
Object.assign(headers, options.headers);
}