Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

解析嵌套合并转发消息只会返回第一条 #265

Closed
Zy-developer opened this issue Dec 9, 2021 · 3 comments
Closed

解析嵌套合并转发消息只会返回第一条 #265

Zy-developer opened this issue Dec 9, 2021 · 3 comments

Comments

@Zy-developer
Copy link

Zy-developer commented Dec 9, 2021

Node.js Version

node v14.18.2

Package Version

v2.1.8

Login Protocol

Android

Bug Description

通过 getForwardMsg(resid) API 解析带有多条合并消息的合并消息,只会返回合并消息内的第一条合并消息内容
消息情况如下:
外层合并消息: [ [ { 合并消息1 } ], [ { 合并消息2 } ], [ { 合并消息3 } ] ]
然后只会返回 合并消息1 的内容,没有其他消息的内容。
具体 xml 消息内容如下:

Log Details

{
    "post_type":"message", "message_id":"EjccDwTEtAAAAIwQYbHRkWGxj7wB",
    "user_id":80000000, "time":1639026620, "seq":35856, "rand":1639043473, "font":"宋体",
    "message":[
        {
            "type":"xml",
            "data":"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<msg brief=\"[聊天记录]\" m_fileName=\"E7BD5463-E80B-4054-ADB3-8028143BE5F9\" action=\"viewMultiMsg\" tSum=\"74\" flag=\"3\" m_resid=\"5v+MD4YHwCCFjOyWMGMHAvY9EGCob7QJE0D/Ti4v9Wtfv0n+6TGFDcEJ+gUn2Qwl\" serviceID=\"35\" m_fileSize=\"15110\"><item layout=\"1\"><title color=\"#000000\" size=\"34\">群聊的聊天记录</title><title color=\"#777777\" size=\"26\">月: [聊天记录]</title><title color=\"#777777\" size=\"26\">月: [聊天记录]</title><title color=\"#777777\" size=\"26\">月: [动画表情]</title><hr></hr><summary color=\"#808080\" size=\"26\">查看3条转发消息</summary></item><source name=\"聊天记录\"></source></msg>\n"
        }
    ],
    "raw_message":"[xml消息]",
    "sender":{"user_id":80000000,"nickname":"匿名消息","card":"匿名消息","sex":"unknown","age":0,"area":"","level":0,"role":"member","title":""},
    "message_type":"group", "group_id":987654321, "group_name":"F25", "block":false, "sub_type":"anonymous",
    "anonymous":{"id":1000007,"id2":1000007,"name":"孙朗","color":"#b5a798","expire_time":1639071700,"flag":"孙朗@2sHkHfn48v2NNu22kdiN3zzcYZ7KDzEGuD+DKjBCkPlR0bK4khVb/g==","enable":true},
    "atme":false,"atall":false,"group":{},"member":{},"self_id":123456789
}
@Zy-developer
Copy link
Author

Zy-developer commented Dec 12, 2021

通过调试定位到了 解析合并消息 的方法源码处,发现方法内是写死了直接获取第0条数据,目前通过个人修改已解决问题,解决方法如下:
修改 lib/internal/contactable.js 脚本内的 getForwardMsg 方法实现

    /** 下载并解析合并转发 */
    async getForwardMsg(resid) {
        let ret = [], msgs = [];
        const buf = await this._downloadMultiMsg(String(resid), 2);
        let a = core_1.pb.decode(buf)[2];
        if (!Array.isArray(a))
            a = [a];
        for (let aa of a) {
            msgs = [];
            aa = aa[2][1];
            if (!Array.isArray(aa))
                aa = [aa];
            for (let proto of aa) {
                try {
                    msgs.push(new message_1.ForwardMessage(proto));
                }
                catch { }
            }
            ret.push(msgs);
        }
        return ret;
    }

这样,会将解析到的所有数据都返回,会是一个二维数组,所以返回值类型也需要做一个修改。
目前只是在我电脑本地修改,望作者有空同步修改一下;当然,这只是我目前遇到的问题的解决方案,可能实现上不是那么完美,如果有更好的方案,欢迎指出修改,谢谢!

@takayama-lily
Copy link
Owner

能否提供一下最外层的resid

@Zy-developer
Copy link
Author

上面的 Log Details 就是完整的消息数据
m_resid="5v+MD4YHwCCFjOyWMGMHAvY9EGCob7QJE0D/Ti4v9Wtfv0n+6TGFDcEJ+gUn2Qwl"

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

No branches or pull requests

2 participants