Skip to content

Commit 233425a

Browse files
KenChoiKenChoi
authored andcommitted
group add avatarThumbPath, modify demo
1 parent 5e9dd53 commit 233425a

File tree

4 files changed

+165
-166
lines changed

4 files changed

+165
-166
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ public void enterConversation(ReadableMap map, final Callback success, final Cal
11521152
String username = map.getString(Constant.USERNAME);
11531153
String appKey = map.hasKey(Constant.APP_KEY) ? map.getString(Constant.APP_KEY) : "";
11541154
JMessageClient.enterSingleConversation(username, appKey);
1155-
} else {
1155+
} else if (type.equals(Constant.TYPE_GROUP)) {
11561156
long groupId = Long.parseLong(map.getString(Constant.GROUP_ID));
11571157
JMessageClient.enterGroupConversation(groupId);
11581158
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import android.text.TextUtils;
88

99
import com.facebook.react.bridge.Arguments;
10-
import com.facebook.react.bridge.Callback;
1110
import com.facebook.react.bridge.ReadableMap;
1211
import com.facebook.react.bridge.ReadableMapKeySetIterator;
1312
import com.facebook.react.bridge.WritableArray;
@@ -20,16 +19,13 @@
2019
import org.json.JSONObject;
2120

2221
import java.io.File;
23-
import java.io.FileInputStream;
24-
import java.io.FileNotFoundException;
2522
import java.io.FileOutputStream;
2623
import java.util.HashMap;
2724
import java.util.Iterator;
2825
import java.util.List;
2926
import java.util.Map;
3027

3128
import cn.jpush.im.android.api.JMessageClient;
32-
import cn.jpush.im.android.api.callback.GetUserInfoCallback;
3329
import cn.jpush.im.android.api.content.CustomContent;
3430
import cn.jpush.im.android.api.content.EventNotificationContent;
3531
import cn.jpush.im.android.api.content.FileContent;
@@ -117,6 +113,7 @@ public static WritableMap toJSObject(GroupInfo groupInfo) {
117113
result.putString(Constant.DESC, groupInfo.getGroupDescription());
118114
result.putInt(Constant.LEVEL, groupInfo.getGroupLevel());
119115
result.putString(Constant.OWNER, groupInfo.getGroupOwner());
116+
result.putString(Constant.AVATAR_THUMB_PATH, groupInfo.getAvatarFile().getAbsolutePath());
120117
result.putString(Constant.OWNER_APP_KEY, groupInfo.getOwnerAppkey());
121118
result.putInt(Constant.MAX_MEMBER_COUNT, groupInfo.getMaxMemberCount());
122119
result.putBoolean(Constant.IS_NO_DISTURB, groupInfo.getNoDisturb() == 1);

example/app/routes/Chat/index.js

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,16 @@ export default class Chat extends Component {
130130
}
131131

132132
getNormalMessage() {
133-
var message = {}
134-
135-
if (this.conversation.conversationType === 'single') {
136-
message.type = 'single'
137-
message.username = this.conversation.key
133+
var msg = {}
134+
if (this.conversation.type === 'single') {
135+
msg.username = this.conversation.username
136+
} else if (this.conversation.type === "group") {
137+
msg.groupId = this.conversation.groupId
138138
} else {
139-
message.type = 'group'
140-
message.groupId = this.conversation.key
139+
msg.roomId = this.conversation.roomId
141140
}
142-
return message
141+
msg.type = this.conversation.type
142+
return msg
143143
}
144144

145145
sendCustomMessage = () => {
@@ -171,23 +171,17 @@ export default class Chat extends Component {
171171

172172
componentDidMount() {
173173
this.resetMenu()
174-
var parames = {
175-
176-
'from': 0, // 开始的消息下标。
177-
'limit': 10 // 要获取的消息数。比如当 from = 0, limit = 10 时,是获取第 0 - 9 条历史消息。
178-
}
179174
this.setState({
180175
messageListLayout: { flex: 1, margin: 0, width: window.width }
181176
})
182-
if (this.conversation.conversationType === 'single') {
183-
parames.type = 'single'
184-
parames.username = this.conversation.key
185-
} else if (this.conversation.conversationType === 'group') {
186-
parames.type = 'group'
187-
parames.groupId = this.conversation.key
188-
} else {
189-
parames.type = 'chatroom'
190-
parames.roomId = this.conversation.key
177+
var parames = {
178+
179+
from: 0, // 开始的消息下标。
180+
limit: 10, // 要获取的消息数。比如当 from = 0, limit = 10 时,是获取第 0 - 9 条历史消息。
181+
type: this.conversation.type,
182+
username: this.conversation.username,
183+
groupId: this.conversation.groupId,
184+
roomId: this.conversation.roomId
191185
}
192186
this.messageListDidLoadCallback = () => {
193187

@@ -206,25 +200,24 @@ export default class Chat extends Component {
206200

207201
this.receiveMessageCallBack = (message) => {
208202

209-
if (this.conversation.conversationType === 'single') {
203+
if (this.conversation.type === 'single') {
210204
if (message.target.type === 'user') {
211-
if (message.from.username === this.conversation.key) {
205+
if (message.from.username === this.conversation.username) {
212206
var msg = this.convertJMessageToAuroraMsg(message)
213207
AuroraIController.appendMessages([msg])
214208
}
215209
Alert.alert('message.target.username', message.target.username)
216-
Alert.alert('this.conversation.key', this.conversation.key)
217210
}
218-
} else if (this.conversation.conversationType === 'group') {
211+
} else if (this.conversation.type === 'group') {
219212
if (message.target.type === 'group') {
220-
if (message.from.id === this.conversation.key) {
213+
if (message.from.id === this.conversation.groupId) {
221214
var msg = this.convertJMessageToAuroraMsg(message)
222215
AuroraIController.appendMessages([msg])
223216
}
224217
}
225218
} else {
226219
if (message.target.type === 'chatroom') {
227-
if (message.target.roomId === this.conversation.key) {
220+
if (message.target.roomId === this.conversation.roomId) {
228221
var msg = this.convertJMessageToAuroraMsg(message)
229222
AuroraIController.appendMessages([msg])
230223
}
@@ -255,7 +248,16 @@ export default class Chat extends Component {
255248
JMessage.removeReceiveMessageListener(this.receiveMessageCallBack)
256249
AuroraIController.removeMessageListDidLoadListener(this.messageListDidLoadCallback)
257250
this.timer && clearTimeout(this.timer);
258-
251+
if (this.conversation.type === "chatroom") {
252+
JMessage.leaveChatRoom({roomId: this.conversation.roomId}, (code) => {
253+
console.log("Leave chat room succeed")
254+
}, (error) => {
255+
alert("error: " + JSON.stringify(error))
256+
})
257+
} else {
258+
JMessage.exitConversation()
259+
}
260+
259261
}
260262

261263
resetMenu() {
@@ -346,13 +348,14 @@ export default class Chat extends Component {
346348
AuroraIController.appendMessages([auroraMsg])
347349
AuroraIController.scrollToBottom(true)
348350

349-
if (this.conversation.conversationType === 'single') {
350-
msg.type = 'single'
351-
msg.username = this.conversation.key
351+
if (this.conversation.type === 'single') {
352+
msg.username = this.conversation.username
353+
} else if (this.conversation.type === "group") {
354+
msg.groupId = this.conversation.groupId
352355
} else {
353-
msg.type = 'group'
354-
msg.groupId = this.conversation.key
356+
msg.roomId = this.conversation.roomId
355357
}
358+
msg.type = this.conversation.type
356359

357360
JMessage.sendMessage(msg, (jmessage) => {
358361

@@ -375,13 +378,14 @@ export default class Chat extends Component {
375378
AuroraIController.appendMessages([auroraMsg])
376379
AuroraIController.scrollToBottom(true)
377380

378-
if (this.conversation.conversationType === 'single') {
379-
msg.type = 'single'
380-
msg.username = this.conversation.key
381+
if (this.conversation.type === 'single') {
382+
msg.username = this.conversation.username
383+
} else if (this.conversation.type === "group") {
384+
msg.groupId = this.conversation.groupId
381385
} else {
382-
msg.type = 'group'
383-
msg.groupId = this.conversation.key
386+
msg.roomId = this.conversation.roomId
384387
}
388+
msg.type = this.conversation.type
385389

386390
JMessage.sendMessage(msg, (jmessage) => {
387391
var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)
@@ -408,13 +412,14 @@ export default class Chat extends Component {
408412
AuroraIController.appendMessages([auroraMsg])
409413
AuroraIController.scrollToBottom(true)
410414

411-
if (this.conversation.conversationType === 'single') {
412-
msg.type = 'single'
413-
msg.username = this.conversation.key
415+
if (this.conversation.type === 'single') {
416+
msg.username = this.conversation.username
417+
} else if (this.conversation.type === "group") {
418+
msg.groupId = this.conversation.groupId
414419
} else {
415-
msg.type = 'group'
416-
msg.groupId = this.conversation.key
420+
msg.roomId = this.conversation.roomId
417421
}
422+
msg.type = this.conversation.type
418423

419424
JMessage.sendMessage(msg, (jmessage) => {
420425
var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)
@@ -444,13 +449,14 @@ export default class Chat extends Component {
444449
AuroraIController.appendMessages([auroraMsg])
445450
AuroraIController.scrollToBottom(true)
446451

447-
if (this.conversation.conversationType === 'single') {
448-
msg.type = 'single'
449-
msg.username = this.conversation.key
452+
if (this.conversation.type === 'single') {
453+
msg.username = this.conversation.username
454+
} else if (this.conversation.type === "group") {
455+
msg.groupId = this.conversation.groupId
450456
} else {
451-
msg.type = 'group'
452-
msg.groupId = this.conversation.key
457+
msg.roomId = this.conversation.roomId
453458
}
459+
msg.type = this.conversation.type
454460

455461
JMessage.sendMessage(msg, (jmessage) => {
456462
var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)
@@ -473,13 +479,14 @@ export default class Chat extends Component {
473479
AuroraIController.appendMessages([auroraMsg])
474480
AuroraIController.scrollToBottom(true)
475481

476-
if (this.conversation.conversationType === 'single') {
477-
msg.type = 'single'
478-
msg.username = this.conversation.key
482+
if (this.conversation.type === 'single') {
483+
msg.username = this.conversation.username
484+
} else if (this.conversation.type === "group") {
485+
msg.groupId = this.conversation.groupId
479486
} else {
480-
msg.type = 'group'
481-
msg.groupId = this.conversation.key
487+
msg.roomId = this.conversation.roomId
482488
}
489+
msg.type = this.conversation.type
483490

484491
JMessage.sendMessage(msg, (jmessage) => {
485492
var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)

0 commit comments

Comments
 (0)