Skip to content

Commit 0b67e81

Browse files
authored
Merge pull request #137 from jpush/dev
Dev
2 parents dcbe36f + ba2cfa3 commit 0b67e81

File tree

13 files changed

+1015
-39
lines changed

13 files changed

+1015
-39
lines changed

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ repositories {
3737
dependencies {
3838
api fileTree(include: ['*.jar'], dir: 'libs')
3939
implementation 'com.facebook.react:react-native:+'
40+
implementation 'com.google.code.gson:gson:2.8.5'
4041
}

android/src/io/jchat/android/Constant.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,16 @@ public class Constant {
121121
public static final String EVENTS = "events";
122122
public static final String APPLY_EVENT_ID = "applyEventId";
123123

124+
/**
125+
* GroupMemberInfo
126+
*/
127+
public static final String USER = "user";
128+
public static final String GROUP_NICKNAME = "groupNickname";
129+
public static final String MEMBER_TYPE = "memberType";
130+
public static final String MEMBER_TYPE_OWNER = "owner";
131+
public static final String MEMBER_TYPE_ADMIN = "admin";
132+
public static final String MEMBER_TYPE_ORDINARY = "ordinary";
133+
public static final String JOIN_GROUP_TIME = "joinGroupTime";
134+
public static final String IS_SILENCE = "isSilence";
135+
124136
}

android/src/io/jchat/android/JMessageModule.java

Lines changed: 161 additions & 26 deletions
Large diffs are not rendered by default.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package io.jchat.android.utils;
2+
3+
import android.content.Context;
4+
5+
import com.google.gson.Gson;
6+
7+
import java.io.File;
8+
import java.io.FileInputStream;
9+
import java.io.FileOutputStream;
10+
import java.util.HashMap;
11+
import java.util.List;
12+
13+
import cn.jpush.im.android.api.event.GroupApprovalEvent;
14+
15+
16+
public class EventUtils {
17+
18+
private static final String TAG = EventUtils.class.getSimpleName();
19+
20+
private static Gson gson = new Gson();
21+
22+
private static final String GROUP_APPROVAL_EVENT_NAME = "/jpush_event/group_approval/";
23+
private static HashMap<String, GroupApprovalEvent> events = new HashMap<>();
24+
25+
26+
public static void saveGroupApprovalEvent(Context context, GroupApprovalEvent event) {
27+
events.put(event.getEventId() + "", event);
28+
String s = gson.toJson(event);
29+
Logger.i(TAG, "Save group approval event:" + s);
30+
FileOutputStream outputStream;
31+
try {
32+
// outputStream = context.openFileOutput(GROUP_APPROVAL_EVENT_NAME+event.getEventId(), Context.MODE_PRIVATE);
33+
File file = new File(context.getFilesDir() + GROUP_APPROVAL_EVENT_NAME, event.getEventId() + "");
34+
if (!file.exists()) {
35+
file.getParentFile().getParentFile().mkdir();
36+
file.getParentFile().mkdir();
37+
file.createNewFile();
38+
}
39+
outputStream = new FileOutputStream(file);
40+
outputStream.write(s.getBytes());
41+
outputStream.close();
42+
} catch (Exception e) {
43+
e.printStackTrace();
44+
}
45+
46+
}
47+
48+
public static GroupApprovalEvent getGroupApprovalEvent(Context context, String eventId) {
49+
GroupApprovalEvent groupApprovalEvent = events.get(eventId);
50+
if (groupApprovalEvent != null) {
51+
return groupApprovalEvent;
52+
}
53+
54+
55+
FileInputStream inputStream;
56+
GroupApprovalEvent event = null;
57+
try {
58+
// inputStream = context.openFileInput(GROUP_APPROVAL_EVENT_NAME+eventId);
59+
File file = new File(context.getFilesDir() + GROUP_APPROVAL_EVENT_NAME, eventId);
60+
inputStream = new FileInputStream(file);
61+
byte[] bytes = new byte[inputStream.available()];
62+
StringBuffer sb = new StringBuffer();
63+
int len = -1;
64+
while ((len = inputStream.read(bytes)) != -1) {
65+
sb.append(new String(bytes, 0, len));
66+
}
67+
Logger.i(TAG, "Get group approval event:" + sb.toString());
68+
inputStream.close();
69+
event = gson.fromJson(sb.toString(), GroupApprovalEvent.class);
70+
71+
} catch (Exception e) {
72+
e.printStackTrace();
73+
}
74+
return event;
75+
}
76+
77+
public static void removeGroupApprovalEvent(Context context, String eventId) {
78+
events.remove(eventId);
79+
File file = new File(context.getFilesDir() + GROUP_APPROVAL_EVENT_NAME, eventId);
80+
if (file.exists()) {
81+
Boolean isSucc = file.delete();
82+
Logger.i(TAG, "Delete group approval event " + eventId + ": " + isSucc);
83+
}
84+
}
85+
86+
public static void removeGroupApprovalEvents(Context context, List<GroupApprovalEvent> groupApprovalEventList) {
87+
for (int i = 0; i < groupApprovalEventList.size(); i++) {
88+
GroupApprovalEvent groupApprovalEvent = groupApprovalEventList.get(i);
89+
removeGroupApprovalEvent(context, groupApprovalEvent.getEventId() + "");
90+
}
91+
}
92+
93+
94+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.jchat.android.utils;
2+
3+
import android.content.Context;
4+
import android.util.Log;
5+
import android.widget.Toast;
6+
7+
public class Logger {
8+
9+
public static boolean SHUTDOWNLOG;
10+
public static boolean SHUTDOWNTOAST;
11+
12+
public static void i(String tag, String msg) {
13+
if (!SHUTDOWNLOG) {
14+
Log.i(tag, msg);
15+
}
16+
}
17+
18+
public static void d(String tag, String msg) {
19+
if (!SHUTDOWNLOG) {
20+
Log.d(tag, msg);
21+
}
22+
}
23+
24+
public static void w(String tag, String msg) {
25+
if (!SHUTDOWNLOG) {
26+
Log.w(tag, msg);
27+
}
28+
}
29+
30+
public static void toast(Context context, String msg) {
31+
if (!SHUTDOWNTOAST) {
32+
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
33+
}
34+
}
35+
}

android/src/io/jchat/android/utils/ResultUtils.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import cn.jpush.im.android.api.model.Conversation;
3737
import cn.jpush.im.android.api.model.GroupBasicInfo;
3838
import cn.jpush.im.android.api.model.GroupInfo;
39+
import cn.jpush.im.android.api.model.GroupMemberInfo;
3940
import cn.jpush.im.android.api.model.Message;
4041
import cn.jpush.im.android.api.model.UserInfo;
4142
import io.jchat.android.Constant;
@@ -312,6 +313,25 @@ public static WritableMap toJSObject(ChatRoomInfo chatRoomInfo) {
312313
return map;
313314
}
314315

316+
public static WritableMap toJSObject(GroupMemberInfo groupMemberInfo) {
317+
final WritableMap map = Arguments.createMap();
318+
try {
319+
map.putMap(Constant.USER, toJSObject(groupMemberInfo.getUserInfo()));
320+
map.putString(Constant.GROUP_NICKNAME, groupMemberInfo.getNickName());
321+
if (groupMemberInfo.getType() == GroupMemberInfo.Type.group_owner) {
322+
map.putString(Constant.MEMBER_TYPE, Constant.MEMBER_TYPE_OWNER);
323+
} else if (groupMemberInfo.getType() == GroupMemberInfo.Type.group_keeper) {
324+
map.putString(Constant.MEMBER_TYPE, Constant.MEMBER_TYPE_ADMIN);
325+
} else {
326+
map.putString(Constant.MEMBER_TYPE, Constant.MEMBER_TYPE_ORDINARY);
327+
}
328+
map.putDouble(Constant.JOIN_GROUP_TIME,groupMemberInfo.getJoinGroupTime());
329+
} catch (Exception e) {
330+
e.printStackTrace();
331+
}
332+
return map;
333+
}
334+
315335
public static WritableArray toJSArray(List list) {
316336
WritableArray array = Arguments.createArray();
317337
if (list != null) {
@@ -328,6 +348,8 @@ public static WritableArray toJSArray(List list) {
328348
array.pushMap(toJSObject((Conversation) object));
329349
} else if (object instanceof ChatRoomInfo) {
330350
array.pushMap(toJSObject((ChatRoomInfo) object));
351+
} else if (object instanceof GroupMemberInfo) {
352+
array.pushMap(toJSObject((GroupMemberInfo) object));
331353
} else {
332354
array.pushString(object.toString());
333355
}

0 commit comments

Comments
 (0)