Skip to content

Commit 1f7f213

Browse files
authored
Merge pull request #12 from TRPGEngine/master
v0.1.3
2 parents bd7b427 + 6edeefc commit 1f7f213

30 files changed

+354
-69
lines changed

.circleci/config.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
version: 2.1
2+
# orbs:
3+
# node: circleci/[email protected]
4+
jobs:
5+
"Build Electron App":
6+
docker:
7+
- image: circleci/node
8+
steps:
9+
- checkout
10+
- run:
11+
name: update-npm
12+
command: 'sudo npm install -g npm@latest'
13+
- restore_cache:
14+
key: dependency-cache-{{ checksum "package.json" }}
15+
- run:
16+
name: install-npm-wee
17+
command: npm install
18+
- save_cache: # special step to save the dependency cache
19+
key: dependency-cache-{{ checksum "package.json" }}
20+
paths:
21+
- ./node_modules
22+
- ~/.cache/electron
23+
- run:
24+
name: prepare-env
25+
command: chmod +x ./.circleci/prepare_env.sh && ./.circleci/prepare_env.sh
26+
- run:
27+
name: build
28+
command: npm run package-all
29+
- store_artifacts:
30+
path: ./dist
31+
workflows:
32+
version: 2
33+
build:
34+
jobs:
35+
# - Build Electron App
36+
- Build Electron App:
37+
filters:
38+
branches:
39+
only:
40+
- release

.circleci/prepare_env.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash -xe
2+
# -*- coding: utf-8 -*-
3+
# for circle ci
4+
5+
case "$OSTYPE" in
6+
"linux-gnu")
7+
# Not using Trusty containers because it can't install wine1.6(-i386),
8+
# see: https://github.com/travis-ci/travis-ci/issues/6460
9+
sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
10+
echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
11+
sudo dpkg --add-architecture i386
12+
sudo apt-get update
13+
sudo apt-get install -y wine yarn
14+
;;
15+
esac

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ dist/
33
package-lock.json
44
yarn.lock
55
config/local.js
6+
.sentryclirc
67

78

89
# Logs

build/ci/before_install.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ case "$TRAVIS_OS_NAME" in
3636
;;
3737
esac
3838

39-
# Force [email protected] if Node 8 (NPM ~5.0.0, ~5.3.0 have issues)
40-
if test "$TRAVIS_NODE_VERSION" = "8"; then
41-
npm install -g [email protected]
42-
fi
43-
npm install -g cnpm
39+
# # Force [email protected] if Node 8 (NPM ~5.0.0, ~5.3.0 have issues)
40+
# if test "$TRAVIS_NODE_VERSION" = "8"; then
41+
# npm install -g [email protected]
42+
# fi
43+
# npm install -g cnpm

config/project.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ let out = {
3636
host: currentHost,
3737
port: apiPort,
3838
},
39+
chat: {
40+
isWriting: {
41+
throttle: 1500, // 节流时间,即至少多少毫秒才会发出一个正在写的信息
42+
timeout: 3000, // 超时时间,即多少毫秒后仍未接收到正在写操作则自动视为已经停止写
43+
},
44+
},
3945
file: {
4046
protocol: isSSL ? 'https' : 'http',
4147
host: currentHost,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "trpg-game-client",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "",
55
"main": "./dist/entry.js",
66
"scripts": {
@@ -60,7 +60,7 @@
6060
"react-native-image-picker": "^0.28.0",
6161
"react-native-photo-browser": "^0.4.0",
6262
"react-native-root-toast": "^3.0.1",
63-
"react-native-storage": "^1.0.0",
63+
"react-native-storage": "^1.0.1",
6464
"react-native-style-block": "0.0.4",
6565
"react-navigation": "^3.5.1",
6666
"react-navigation-redux-helpers": "^3.0.0",

src/api/event.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as trpgApi from './trpg.api.js';
2+
const api = trpgApi.getInstance();
3+
4+
export const sendStartWriting = (type = 'user', uuid) => {
5+
return api.emit('chat::startWriting', { type, uuid });
6+
};
7+
8+
export const sendStopWriting = (type = 'user', uuid) => {
9+
return api.emit('chat::stopWriting', { type, uuid });
10+
};

src/api/rnStorage.api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Storage from 'react-native-storage/src/storage';
1+
import Storage from 'react-native-storage';
22
import config from '../../config/project.config';
33

44
let storage = new Storage({

src/api/trpg.api.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import io from 'socket.io-client';
22
import config from '../../config/project.config.js';
33
import { RESET, ADD_FRIEND_SUCCESS } from '../redux/constants';
44

5-
import { addMsg, updateMsg } from '../redux/actions/chat';
5+
import {
6+
addMsg,
7+
updateMsg,
8+
startWriting,
9+
stopWriting,
10+
} from '../redux/actions/chat';
611
import { addFriendInvite, loginWithToken } from '../redux/actions/user';
712
import { updateGroupStatus, addGroup } from '../redux/actions/group';
813

@@ -24,7 +29,7 @@ function API() {
2429
this.socket.connect();
2530
}
2631
return this.socket.emit(event, data, (res) => {
27-
cb(res);
32+
cb && cb(res);
2833
if (res.result === false) {
2934
// 如果检测到错误则汇报错误信息
3035
const info = `${res.msg}\n事件: ${event}\n发送信息: ${JSON.stringify(
@@ -71,6 +76,18 @@ export function bindEventFunc(store, { onReceiveMessage } = {}) {
7176
store.dispatch(updateMsg(converseUUID, payload));
7277
});
7378

79+
api.on('chat::startWriting', function(data) {
80+
const { type = 'user', from } = data;
81+
const uuid = from;
82+
store.dispatch(startWriting(type, uuid));
83+
});
84+
85+
api.on('chat::stopWriting', function(data) {
86+
const { type = 'user', from } = data;
87+
const uuid = from;
88+
store.dispatch(stopWriting(type, uuid));
89+
});
90+
7491
api.on('player::addFriend', function(data) {
7592
let uuid = data.uuid;
7693
getUserInfoCache(uuid);

src/redux/actions/chat.js

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,28 @@ const {
1111
CREATE_CONVERSES_SUCCESS,
1212
CREATE_CONVERSES_FAILED,
1313
REMOVE_CONVERSES_SUCCESS,
14+
REMOVE_USER_CONVERSE,
1415
UPDATE_CONVERSES_INFO_SUCCESS,
1516
UPDATE_CONVERSES_MSGLIST_SUCCESS,
1617
SWITCH_CONVERSES,
1718
SEND_MSG,
1819
SEND_MSG_COMPLETED,
1920
UPDATE_SYSTEM_CARD_CHAT_DATA,
21+
UPDATE_WRITING_STATUS,
2022
} = constants;
2123
import * as trpgApi from '../../api/trpg.api.js';
2224
const api = trpgApi.getInstance();
2325
import rnStorage from '../../api/rnStorage.api.js';
2426
import { checkUser } from '../../shared/utils/cacheHelper';
2527
import { hideProfileCard, switchMenuPannel } from './ui';
2628
import uploadHelper from '../../shared/utils/uploadHelper';
29+
import { renewableDelayTimer } from '../../shared/utils/timer';
30+
import config from '../../../config/project.config';
31+
import _without from 'lodash/without';
32+
33+
const getUserConversesHash = (userUUID) => {
34+
return `userConverses#${userUUID}`;
35+
};
2736

2837
let localIndex = 0;
2938
let getLocalUUID = function getLocalUUID() {
@@ -157,6 +166,8 @@ export let createConverse = function createConverse(
157166
});
158167
};
159168
};
169+
170+
// 移除多人会话
160171
export let removeConverse = function removeConverse(converseUUID) {
161172
return function(dispatch, getState) {
162173
return api.emit('chat::removeConverse', { converseUUID }, function(data) {
@@ -169,6 +180,24 @@ export let removeConverse = function removeConverse(converseUUID) {
169180
};
170181
};
171182

183+
export const removeUserConverse = (userConverseUUID) => {
184+
return (dispatch, getState) => {
185+
// 在当前删除
186+
dispatch({ type: REMOVE_USER_CONVERSE, converseUUID: userConverseUUID });
187+
188+
// 在localStorage删除
189+
const userUUID = getState().getIn(['user', 'info', 'uuid']);
190+
const converses = getState().getIn(['chat', 'converses']);
191+
const uuids = Object.keys(
192+
converses.filter((c) => c.get('type') === 'user').toJS()
193+
);
194+
rnStorage.set(
195+
getUserConversesHash(userUUID),
196+
_without(uuids, userConverseUUID)
197+
);
198+
};
199+
};
200+
172201
export let addUserConverse = function addUserConverse(senders) {
173202
return function(dispatch, getState) {
174203
if (typeof senders === 'string') {
@@ -183,10 +212,10 @@ export let addUserConverse = function addUserConverse(senders) {
183212

184213
// 用户会话缓存
185214
let userUUID = getState().getIn(['user', 'info', 'uuid']);
186-
rnStorage.get('userConverses#' + userUUID).then(function(converse) {
215+
rnStorage.get(getUserConversesHash(userUUID)).then(function(converse) {
187216
converse = Array.from(new Set([...converse, ...senders]));
188217
rnStorage
189-
.set('userConverses#' + userUUID, converse)
218+
.set(getUserConversesHash(userUUID), converse)
190219
.then((data) => console.log('用户会话缓存完毕:', data));
191220
});
192221

@@ -266,13 +295,15 @@ export let reloadConverseList = function reloadConverseList(cb) {
266295
let userInfo = getState().getIn(['user', 'info']);
267296
let userUUID = userInfo.get('uuid');
268297

269-
dispatch(getConverses(cb));
270-
rnStorage.get('userConverses#' + userUUID).then(function(converse) {
298+
dispatch(getConverses(cb)); // 从服务端获取多人会话列表
299+
rnStorage.get(getUserConversesHash(userUUID)).then(function(converse) {
271300
console.log('缓存中的用户会话列表:', converse);
272301
if (converse && converse.length > 0) {
302+
// 如果本地缓存有存在用户会话,则根据上次登录时间获取这段时间内新建的用户会话
273303
dispatch(addUserConverse(converse));
274304
dispatch(getOfflineUserConverse(userInfo.get('last_login')));
275305
} else {
306+
// 如果本地没有存在用户会话,则获取所有的用户会话
276307
dispatch(getAllUserConverse());
277308
}
278309
});
@@ -481,3 +512,37 @@ export let updateCardChatData = function(chatUUID, newData) {
481512
});
482513
};
483514
};
515+
516+
const getWriteHash = (type = 'user', uuid) => {
517+
return `${type}#${uuid}`;
518+
};
519+
export let startWriting = function(type = 'user', uuid) {
520+
return function(dispatch, getState) {
521+
dispatch({
522+
type: UPDATE_WRITING_STATUS,
523+
payload: {
524+
type,
525+
uuid,
526+
isWriting: true,
527+
},
528+
});
529+
530+
renewableDelayTimer(
531+
getWriteHash(type, uuid),
532+
function() {
533+
dispatch(stopWriting()); // 如果10秒后没有再次收到正在输入的信号,则视为已经停止输入了
534+
},
535+
config.chat.isWriting.timeout
536+
);
537+
};
538+
};
539+
export let stopWriting = function(type = 'user', uuid) {
540+
return {
541+
type: UPDATE_WRITING_STATUS,
542+
payload: {
543+
type,
544+
uuid,
545+
isWriting: false,
546+
},
547+
};
548+
};

0 commit comments

Comments
 (0)