Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

未知消息类型疑问? #348

Closed
hyl87 opened this issue May 20, 2020 · 11 comments
Closed

未知消息类型疑问? #348

hyl87 opened this issue May 20, 2020 · 11 comments

Comments

@hyl87
Copy link

hyl87 commented May 20, 2020

在线收消息时能看到 UnknownMessageContent;
重新调用getmessage方法 为啥拉取不出来这种消息类型;

我们有个功能是需要提醒用户当前版本不支持此消息,想用这个类型

@imndx
Copy link
Contributor

imndx commented May 20, 2020

UnknownMessageContent 是因为本地没有注册相关的消息类型或者消息decode的时候失败了,请看下clientService里面的日志

@hyl87
Copy link
Author

hyl87 commented May 20, 2020

clientService 注册了的
image
就getmessage方法拉取不出来这种类型的消息,聊天过程中能看到 但是退出页面之后 就拉取不出来

@hyl87
Copy link
Author

hyl87 commented May 20, 2020

clientService 注册了的
image
就getmessage方法拉取不出来这种类型的消息,聊天过程中能看到 但是退出页面之后 就拉取不出来

忘了说,是接收方显示不出来

@imndx
Copy link
Contributor

imndx commented May 20, 2020

没有注册messageViewHolder?

@hyl87
Copy link
Author

hyl87 commented May 20, 2020

没有注册messageViewHolder?

注册了的,正在聊天的时候 可以看到显示出来的, 退出聊天页面,在进入就没了,只有接收方有这个问题,发送方没有

@imndx
Copy link
Contributor

imndx commented May 21, 2020

消息的PersisitFlag是什么?
要Persist 和 Persist_And_Count 才会保存。

@hyl87
Copy link
Author

hyl87 commented May 21, 2020

image
就自带的这个

@imndx
Copy link
Contributor

imndx commented May 21, 2020

UnkownMessageContent是当收到的消息,不能找到对应的消息类型,或者decode失败时,自动转的。

需要看你原始发送的那条消息的PersisitFlag。

至于,getmessage的问题,你可以在marsservice进程ClientService#getMessages处打断点确认消息是否收到,并存储?

@AFAP
Copy link

AFAP commented May 24, 2020

UnkownMessageContent是当收到的消息,不能找到对应的消息类型,或者decode失败时,自动转的。

需要看你原始发送的那条消息的PersisitFlag。

至于,getmessage的问题,你可以在marsservice进程ClientService#getMessages处打断点确认消息是否收到,并存储?

/**

  • 用户名片
    */
    @ContentTag(type = ContentType_CONTACTS_CARD, flag = PersistFlag.Persist_And_Count)
    public class ContactsCardMessageContent extends MessageContent {
    private final String KEY_ACCOUNT = "account";
    private final String KEY_NICK = "nick";
    private final String KEY_AVATAR = "avatar";

    public String account;
    public String nick;
    public String imageUrl;

    public ContactsCardMessageContent(UserInfo userInfo) {
    this.account = userInfo.uid;
    this.nick = userInfo.displayName;
    this.imageUrl = userInfo.portrait;
    }

    @OverRide
    public MessagePayload encode() {
    MessagePayload payload = new MessagePayload();
    payload.searchableContent = "[名片]";

     JSONObject objWrite = new JSONObject();
     try {
         objWrite.put(KEY_ACCOUNT, account);
         objWrite.put(KEY_NICK, nick);
         objWrite.put(KEY_AVATAR, imageUrl);
     } catch (JSONException e) {
         e.printStackTrace();
     }
     payload.content = objWrite.toString();
     return payload;
    

    }

    @OverRide
    public void decode(MessagePayload payload) {
    if (payload.content != null) {
    JSONObject jsonObject = null;
    try {
    jsonObject = new JSONObject(payload.content);
    account = jsonObject.optString(KEY_ACCOUNT);
    nick = jsonObject.optString(KEY_NICK);
    imageUrl = jsonObject.optString(KEY_AVATAR);
    } catch (JSONException e) {
    e.printStackTrace();
    }
    }
    }

    @OverRide
    public String digest(Message message) {
    return "[名片]";
    }

    @OverRide
    public int describeContents() {
    return 0;
    }

    @OverRide
    public void writeToParcel(Parcel dest, int flags) {
    super.writeToParcel(dest, flags);
    dest.writeString(this.account);
    dest.writeString(this.nick);
    dest.writeString(this.imageUrl);
    }

    protected ContactsCardMessageContent(Parcel in) {
    super(in);
    this.account = in.readString();
    this.nick = in.readString();
    this.imageUrl = in.readString();
    }

    public static final Creator CREATOR = new Creator() {
    @OverRide
    public ContactsCardMessageContent createFromParcel(Parcel source) {
    return new ContactsCardMessageContent(source);
    }

     @Override
     public ContactsCardMessageContent[] newArray(int size) {
         return new ContactsCardMessageContent[size];
     }
    

    };
    }

ContentType_CONTACTS_CARD是1001

这个停在聊天界面上能正确显示发出,退出再进来就是未知了…………

@imndx
Copy link
Contributor

imndx commented May 26, 2020

MessageContent的子类,必须要要有一个无参构造函数。

@imndx imndx closed this as completed May 26, 2020
@imndx imndx pinned this issue May 26, 2020
@AFAP
Copy link

AFAP commented May 27, 2020

确实,在改造图片消息时,我把未用到的无参构造器删了,也成了未知,后来我就知道原因了。建议文档里加一下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants