From 9d9720c74ccf0aebb35a51e018ced676dbc7970a Mon Sep 17 00:00:00 2001 From: Boris Yankov Date: Thu, 15 Dec 2016 12:00:09 +0200 Subject: [PATCH] Send userAgent string with api requests --- src/api/apiFetch.js | 3 ++- src/events/eventActions.js | 3 --- src/main/MainScreen.js | 7 +------ src/message-list/InfiniteScrollView.js | 1 - src/utils/userAgent.js | 6 ++++++ 5 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 src/utils/userAgent.js diff --git a/src/api/apiFetch.js b/src/api/apiFetch.js index 291ccc3c497..9b02828265c 100644 --- a/src/api/apiFetch.js +++ b/src/api/apiFetch.js @@ -1,5 +1,6 @@ import { Auth } from '../types'; import { getAuthHeader, encodeAsURI } from '../utils/url'; +import userAgent from '../utils/userAgent'; const apiVersion = 'api/v1'; @@ -13,7 +14,7 @@ export const apiFetch = async ( const allParams = { headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', - 'User-Agent': 'ZulipReactNative', + 'User-Agent': userAgent, 'Authorization': getAuthHeader(auth.email, auth.apiKey), }, ...params, diff --git a/src/events/eventActions.js b/src/events/eventActions.js index bc62e0d8e8c..80a1513a3be 100644 --- a/src/events/eventActions.js +++ b/src/events/eventActions.js @@ -12,9 +12,6 @@ import { } from '../constants'; const processEvent = (dispatch, event, getState) => { - if (!getState().account) { - console.log('WTF WTF WTF', getState()); - } const isInNarrow = isMessageInNarrow( event.message, getState().chat.narrow, diff --git a/src/main/MainScreen.js b/src/main/MainScreen.js index 539d7380a18..eae6ce40582 100644 --- a/src/main/MainScreen.js +++ b/src/main/MainScreen.js @@ -4,8 +4,6 @@ import { } from 'react-native'; import Drawer from 'react-native-drawer'; -import DeviceInfo from 'react-native-device-info'; - import Chat from '../chat/Chat'; import MainNavBar from '../nav/MainNavBar'; import StreamSidebar from '../nav/StreamSidebar'; @@ -15,10 +13,7 @@ export default class MainScreen extends React.Component { render() { const { streamlistOpened, doNarrow } = this.props; - console.log('getModel', DeviceInfo.getModel()); - console.log('getSystemVersion', DeviceInfo.getSystemVersion()); - console.log('getVersion', DeviceInfo.getVersion()); - console.log('getUserAgent', DeviceInfo.getUserAgent()); + return ( {this.props.children} diff --git a/src/utils/userAgent.js b/src/utils/userAgent.js new file mode 100644 index 00000000000..2f159307596 --- /dev/null +++ b/src/utils/userAgent.js @@ -0,0 +1,6 @@ +import { NativeModules } from 'react-native'; +import DeviceInfo from 'react-native-device-info'; + +const userAgent = NativeModules.RNDeviceInfo ? `ZulipMobile ${DeviceInfo.getVersion()} (${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()})` : ''; + +export default userAgent;