已调用conversation.fetchInfoInBackground
我调用conversation.getAttribute("members") 获取不到值
会话中


这到底是怎么回事啊?????
11-21 05:27:57.200 8744-13165/kaurihealth.mobile.andirod D/===AVOS Cloud===: LogUtil$avlog->d->33: {"results":[{"updatedAt":"2016-11-21T06:00:00.285Z","name":"\u738b\u52a0\u53cb\u3001\u738b\u52a0\u53cb...","objectId":"58328619d2030900671f06a5","m":["f95cdb102bd2497796f1fd7969142304","f44b91eba63f49e186b80bd7975ab35a","d4e74cb0114d4b6b90fa970e1dd25c73"],"tr":false,"createdAt":"2016-11-21T05:28:57.115Z","lm":{"__type":"Date","iso":"2016-11-21T06:00:00.245Z"},"c":"f44b91eba63f49e186b80bd7975ab35a","mu":[],"attr":{"members":[{"avatar":"","clientId":"f95cdb102bd2497796f1fd7969142304","fullName":"\u5b8b\u6c5f"},{"avatar":"http:\/\/kaurihealthrecordimagetest.kaurihealth.com\/d4e74cb0114d4b6b90fa970e1dd25c73\/Icon\/3d33a5b87b594063b4cdfbe41520a816.png","clientId":"d4e74cb0114d4b6b90fa970e1dd25c73","fullName":"\u738b\u52a0\u53cb"},{"avatar":"","clientId":"f44b91eba63f49e186b80bd7975ab35a","fullName":"\u738b\u52a0\u53cb"}],"type":1}}]}
log--也有值

我看了下源码里
· public void fetchInfoInBackground(final AVIMConversationCallback callback) {·里面
· HashMap attributes = new HashMap();
if(object.get("attr") != null) {
JSONObject attr = object.getJSONObject("attr");
if(attr != null) {
Iterator iterator = attr.keys();

                            while(iterator.hasNext()) {
                                String key = (String)iterator.next();

                                try {
                                    attributes.put(key, attr.get(key));
                                } catch (JSONException var8) {
                                    ;
                                }
                            }
                        }
                    }·

attributes后面没调用过啊 ????

继续看源码,attrs 最终放进了会话:AVIMConversation.this.attributes.putAll(attributes);

还是贴 App ID、conversatinoId 和复现代码,我来定位你的问题。

public static final String APP_ID_DEBUG = "gEtvkdqzdAS0sAvjVswOoYFx-gzGzoHsz";

:AVIMConversation.this.attributes.putAll(attributes); 这句代码在哪里????

源码: HashMap attributes = new HashMap();
if(object.get("attr") != null) {
JSONObject attr = object.getJSONObject("attr");
if(attr != null) {
Iterator iterator = attr.keys();

                            while(iterator.hasNext()) {
                                String key = (String)iterator.next();

                                try {
                                    attributes.put(key, attr.get(key));
                                } catch (JSONException var8) {
                                    ;
                                }
                            }
                        }
                    }

                    AVIMConversation.this.processInstanceData(object);
                    if(callback != null) {
                        callback.internalDone((Object)null, (AVException)null);
                    }

                    AVIMConversation.this.client.conversationCache.put(AVIMConversation.this.conversationId, AVIMConversation.this);
                    AVIMConversation.this.storage.insertConversations(Arrays.asList(new AVIMConversation[]{AVIMConversation.this}));
                } else if(e == null && object == null && callback != null) {
                    callback.internalDone((Object)null, new AVException(104, "Object not found"));
                }

            }

我只看到
processInstanceData(AVObject object) 方法里
this.attributes.putAll(this.attributes);

、 .map(new Func1() {
@Override
public AVIMConversation call(String conversationId) {
return client != null ? client.getConversation(conversationId) : null;
}
})
生成Conversation对象

我每次获取Conversation后,都会
private Observable getConversationObservable(final AVIMConversation conversation) {
return Observable.create(new Observable.OnSubscribe() {
@Override
public void call(Subscriber<? super AVIMConversation> subscriber) {
if (conversation.getCreatedAt() == null) {
conversation.fetchInfoInBackground(new AVIMConversationCallback() {
@Override
public void done(AVIMException e) {
if (e != null) subscriber.onError(e);
subscriber.onNext(conversation);
subscriber.onCompleted();
}
});
} else {
try {
subscriber.onNext(conversation);
subscriber.onCompleted();
} catch (Exception e) {
subscriber.onError(e);
}
}
}
});
}

你说的AVIMConversation.this.attributes.putAll(attributes);是在创建对话时传的吧~
protected AVIMConversation(AVIMClient client, List members, Map attributes, boolean isTransient) {
this.instanceData = new HashMap();
this.pendingInstanceData = new HashMap();
this.FETCH_TIME_INTERVEL = 3600000;
this.latestConversationFetch = 0L;
this.members = new HashSet();
if(members != null) {
this.members.addAll(members);
}

    this.attributes = new HashMap();
    if(attributes != null) {
        this.attributes.putAll(attributes);
    }

    this.client = client;
    this.pendingAttributes = new HashMap();
    this.isTransient = isTransient;
    this.storage = AVIMMessageStorage.getInstance(client.clientId);
}

那接收对话的那端
public void fetchInfoInBackground(final AVIMConversationCallback callback) {
里面并没有保存attributes

你看看,能否尽快回复我啊~~大神

我这边用 conversation.getAttribute(); 可以正常取值。没有复现你的问题。

可否发一个复现问题的小 Demo 私信给我?点我头像发私信。

同求不到。3.16版本!
conversation.set()成功
日志有数据
conversation.get()方法却获取不到。
建议开发的朋友好好看源码,哪里漏掉了!
3.16版本getAttribute已经被你们废弃了好吧。

getAttribute 方法确实 deprecated 了。但是还可以继续正常使用的,这是为了保证对旧版 SDK 用户的兼容。

现在推荐的做法是,在 _Conversation 表里,新建一个字段来保存 attribute,字段类型都是由你们自行选择。用 put/ get 方法来进行存取数据就好。

AVIMConversation.set()成功了 AVIMConversation.get() 为null 请问是什么原因?

AVIMConversation.get("attr") 是获取不到的。需要继续使用 getAttribute 方法。如我上面回复的,这个方法尽管废弃,不推荐使用了,但我们在较长的一段时间里都会继续保留。