uni-app中鸿蒙和iOS合并转发会丢消息的问题!我们这边鸿蒙是有解决丢消息的问题,但是ios中data文件没有上传上去,希望研发人员帮忙看一下,比较急,这两天要上线,麻烦你们呢!-Uniapp-野火IM

  1. Uniapp
  2. uni-app中鸿蒙和iOS合并转发会丢消息的问题!我们这边鸿蒙是有解决丢消息的问题,但是ios中data文件没有上传上去,希望研发人员帮忙看一下,比较急,这两天要上线,麻烦你们呢!

uni-app中鸿蒙和iOS合并转发会丢消息的问题!我们这边鸿蒙是有解决丢消息的问题,但是ios中data文件没有上传上去,希望研发人员帮忙看一下,比较急,这两天要上线,麻烦你们呢!

谢维瑶 17天前 91

1.更新完你们的wfc下message中compositeMessageContent.js这个文件,鸿蒙合并转发会丢消息,ios也会丢消息,鸿蒙端我们改的方式是这样的,像下面改鸿蒙不会丢消息,但是ios会丢消息 这个是解决鸿蒙端合并转发丢消息,但是ios不行 import MessageContentType from "../messages/messageContentType"; import wfc from "../client/wfc"; import MediaMessageContent from "../messages/mediaMessageContent"; import { stringValue } from "../util/longUtil"; import Message from "../messages/message"; import Conversation from "../model/conversation"; import Long from "long"; import { compare } from "../util/longUtil"; import MessagePayload from "../messages/messagePayload"; import ArticlesMessageContent from "./articlesMessageContent"; import MessageContentMediaType from "./messageContentMediaType"; import commonNative from "../../utils/commonNative";

export default class CompositeMessageContent extends MediaMessageContent { title = ''; messages = []; // web 端有效,仅仅是用来标识 mediaCompositeMessage 是否已加载 loaded = false;

constructor() {
 super(MessageContentType.Composite_Message, MessageContentMediaType.General, '')
}
setMessages(msgs) {
 this.messages = [];
 msgs.forEach(m => {
 if (m.messageContent instanceof ArticlesMessageContent) {
 let linkMessageContents = m.messageContent.toLinkMessageContent();
 linkMessageContents.forEach(lm => {
 let msg = Object.assign(new Message(), m);
 msg.messageContent = lm;
 this.messages.push(msg);
 })
 } else {
 this.messages.push(m)
 }
 })
 this.messages = this.messages.sort((m1, m2) => {
 return compare(m1.messageUid, m2.messageUid);
 })
}
digest(message) {
 return '[聊天记录]' + this.title;
}
async encode() {
 let payload = super.encode();
 payload.content = this.title;
 let arr = [];
 let binArr;
 let size = 0;
 this.messages.forEach(msg => {
 let msgPayload = msg.messageContent.encode();
 let o = {
 uid: stringValue(msg.messageUid),
 type: msg.conversation.type,
 target: msg.conversation.target,
 line: msg.conversation.line,
 from: msg.from,
 tos: msg.to,
 direction: msg.direction,
 status: msg.status,
 serverTime: stringValue(msg.timestamp),
 ctype: msgPayload.type,
 csc: msgPayload.searchableContent,
 cpc: msgPayload.pushContent,
 cpd: msgPayload.pushData,
 cc: msgPayload.content,
 cmt: msgPayload.mentionedType,
 cmts: msgPayload.mentionedTargets,
 ce: msgPayload.extra,
 };
 if (msgPayload.searchableContent) {
 payload.searchableContent = payload.searchableContent + msgPayload.searchableContent + ' ';
 }
 if (msgPayload.binaryContent) {
 o.cbc = msgPayload.binaryContent;
 }
 if (msg.messageContent instanceof MediaMessageContent) {
 o.mt = msg.messageContent.mediaType;
 o.mru = msg.messageContent.remotePath;
 }
 if (!binArr) {
 size += JSON.stringify(o).length;
 if (size > 20480 && arr.length > 0) {
 binArr = arr.map((value) => value);
 }
 }
 arr.push(o);
 });
 let obj;
 if (binArr && !this.file) {
 obj = {
 ms: arr,
 }
 let str = JSON.stringify(obj);
 str = str.replace(/"uid":"([0-9]+)"/, "\"uid\":1ドル");
 str = str.replace(/"serverTime":"([0-9]+)"/, "\"serverTime\":1ドル");
 let fileName = 'wcf-' + new Date().getTime() + '.data';
 const _localPath = await commonNative.createTextFile(fileName, str)
 this.localPath = _localPath
 payload.localMediaPath = _localPath
 obj = {
 ms: binArr,
 }
 } else {
 if (binArr) {
 obj = {
 ms: binArr,
 }
 } else {
 obj = {
 ms: arr,
 }
 }
 }
 let str = JSON.stringify(obj);
 str = str.replace(/"uid":"([0-9]+)"/, "\"uid\":1ドル");
 str = str.replace(/"serverTime":"([0-9]+)"/, "\"serverTime\":1ドル");
 payload.binaryContent = wfc.utf8_to_b64(str)
 // console.log("CompositeMessageContent:payload:", payload)
 return payload;
}
decode(payload) {
 if (payload.searchableContent.startsWith("AofRKInZd")) {
 return
 }
 super.decode(payload);
 this.title = payload.content;
 let str;
 if (this.file) {
 // web
 let fileReader = new FileReader();
 fileReader.onload(ev => {
 this._decodeMessages(ev.target.result);
 });
 fileReader.readAsBinaryString(this.file);
 } else if (this.localPath) {
 // console.log("this.localPath:", this.localPath)
 // console.log("this.localPath:mm:", this.localMediaPath)
 commonNative.readFileAsText(this.localPath).then(str => {
 this._decodeMessages(str);
 }).catch(err => {
 console.log("err:", err)
 })
 // console.log("this.localPath:str:", str)
 }
 // console.log("this.localPath:payload:", payload)
 if (!str) {
 try {
 str = wfc.b64_to_utf8(payload.binaryContent);
 // console.log('obj----合并32',str);
 this._decodeMessages(str);
 } catch (err) {
 console.log('err', err);
 }
 }
}
_decodeMessages(str) {
 if (str) {
 if (this.loaded) {
 return;
 }
 this.messages = [];
 // FIXME node 环境,decodeURIComponent 方法,有时候会在最后添加上@字符,目前尚未找到原因,先规避
 str = str.substring(0, str.lastIndexOf('}') + 1);
 str = str.replace(/"uid":([0-9]+)/g, "\"uid\":\"1ドル\"");
 str = str.replace(/"serverTime":([0-9]+)/g, "\"serverTime\":\"1ドル\"");
 let obj = JSON.parse(str);
 // console.log('obj----合并转发',obj);
 obj.ms.forEach(o => {
 let conv = new Conversation(o.type, o.target, o.line);
 let msg = new Message()
 msg.messageUid = Long.fromValue(o.uid);
 msg.conversation = conv;
 msg.from = o.from;
 msg.to = o.tos;
 msg.direction = o.direction;
 msg.status = o.status;
 msg.timestamp = Long.fromValue(o.serverTime);
 let payload = new MessagePayload();
 payload.type = o.ctype;
 payload.searchableContent = o.csc;
 payload.pushContent = o.cpc;
 payload.pushData = o.cpd;
 payload.content = o.cc;
 payload.mentionedType = o.cmt;
 payload.mentionedTargets = o.cmts;
 payload.extra = o.ce;
 payload.binaryContent = o.cbc;
 payload.mediaType = o.mt;
 payload.remoteMediaUrl = o.mru;
 msg.messageContent = Message.messageContentFromMessagePayload(payload, msg.from);
 this.messages.push(msg);
 });
 }
 console.log('cp ms', this.messages)
}

}

最新回复 (4)
  • HeavyRain 17天前
    2
    用我们最新的demo测试,demo上有这个问题吗?
  • 谢维瑶 17天前
    3
    用了你们最新代码跑了的,鸿蒙上和ios都会丢消息
  • 谢维瑶 17天前
    4
    HeavyRain 用我们最新的demo测试,demo上有这个问题吗?
    上面那个代码,那个处理文件,我昨天少烤了代码,class CommonNative {
    compressImageToBase64(path, targetWidth = 200, quality = 80) {
    //#ifdef APP-HARMONY
    return compressImageToBase64(path, targetWidth, quality)
    // #else
    return new Promise((resolve, reject) => {
    compressImageToBase64(path, targetWidth, quality / 100, (err, data) => {
    // console.log("compressImageToBase64:", data)
    if (err) {
    reject(err)
    } else {
    resolve(data)
    }

    })
    })
    // #endif
    }
    getVideoThumbnailToBase64(path) {
    //#ifdef APP-HARMONY
    return getVideoThumbnailToBase64(path)
    // #else
    return new Promise((resolve, reject) => {
    getVideoThumbnailToBase64(path, (err, data) => {
    // console.log("compressImageToBase64:", data)
    if (err) {
    reject(err)
    } else {
    resolve(data)
    }

    })
    })
    // #endif
    }
    readFileAsText(savedPath) {
    console.log("readFileAsText:", savedPath)
    return new Promise((resolve, reject) => {
    let ret = ''
    let fileBase64
    //#ifdef APP-HARMONY
    try {
    fileBase64 = uni.getFileSystemManager().readFileSync(savedPath, "utf-8");
    ret = fileBase64
    resolve(ret)
    } catch (error) {
    reject(error)
    }
    //#else
    const platPath = plus.io.convertAbsoluteFileSystem(savedPath)
    console.log("platPath:", platPath)
    // 1. 通过路径解析获取 FileEntry 对象
    plus.io.resolveLocalFileSystemURL(platPath, function(entry) {

    // 2. 获取文件对象 (File Object)
    entry.file(function(file) {
    // 3. 创建文件读取器
    var fileReader = new plus.io.FileReader();

    // 读取完成的回调
    fileReader.onloadend = function(evt) {
    // evt.target.result 就是读取到的内容
    console.log("读取成功");
    resolve(evt.target.result);
    };

    // 读取错误的回调
    fileReader.onerror = function(e) {
    console.error("读取错误", e);
    reject({
    code: 500,
    msg: '读取文件失败',
    error: e
    });
    };

    // 4. 开始以文本格式读取 (默认 UTF-8)
    fileReader.readAsText(file, 'utf-8');

    }, function(e) {
    reject({
    code: 501,
    msg: '获取File对象失败',
    error: e
    });
    });

    }, function(e) {
    reject({
    code: 502,
    msg: '文件路径解析失败(文件可能不存在)',
    error: e
    });
    });
    //#endif
    })

    }
    createTextFile(fileName, data) {

    return new Promise((resolve, reject) => {
    //#ifdef APP-HARMONY
    const dir = getFilesDir()
    const fs = uni.getFileSystemManager()
    const filePath = `${dir}/composite_data_${fileName}`
    // console.log("filePath:", filePath)
    fs.writeFile({
    filePath: filePath,
    encoding: "utf-8",
    data: data,
    success: (res) => {
    resolve(filePath)
    },
    fail: (err) => {
    console.log("err:", err)
    reject(err)
    }
    })
    //#else
    // 1. 请求文件系统 (PRIVATE_DOC 为应用私有文档目录,卸载App会被清除)
    plus.io.requestFileSystem(plus.io.PRIVATE_DOC, function(fs) {

    // 2. 获取或创建文件 (create: true 表示不存在则创建)
    fs.root.getFile(fileName, {
    create: true
    }, function(fileEntry) {

    // 3. 创建写入器
    fileEntry.createWriter(function(writer) {

    // 写入完成的回调
    writer.onwrite = function(e) {
    resolve(fileEntry.fullPath);
    };

    // 写入错误的回调
    writer.onerror = function(e) {
    reject({
    code: 500,
    msg: '写入失败: ' + e.message
    });
    };

    // 4. 执行写入
    // 默认 writer 指针在文件开头,write 方法会自动以 UTF-8 编码写入字符串
    // 如果需要确保覆盖原有内容,建议先 seek(0)
    writer.seek(0);
    writer.write(data);

    }, function(e) {
    reject({
    code: 501,
    msg: '创建Writer失败: ' + e.message
    });
    });

    }, function(e) {
    reject({
    code: 502,
    msg: '获取文件失败: ' + e.message
    });
    });

    }, function(e) {
    reject({
    code: 503,
    msg: '请求文件系统失败: ' + e.message
    });
    });
    //#endif
    })
    }
    initSSL() {
    // #ifdef APP-HARMONY
    initNativeSSL()
    // #endif

    }
    requestSync(opt) {
    requestSSLSync(opt)
    }
    request(options) {
    //#ifdef APP-HARMONY
    if (options.method.toLocaleLowerCase() == "get" && options.data) {
    options.url = stringifyQuery(options.url, options.data)
    delete options.data
    }
    return request(options)
    //#else
    return uni.request(options)
    //#endif
    }
    async readFilePartToBase64Async(...args) {
    return readFilePartToBase64(...args)
    }
    showDocumentPicker() {
    //#ifdef APP-PLUS
    fileNative.showDocumentPicker()
    //#endif
    }
    } 这个处理再鸿蒙中不会丢消息,但是ios中.data会传不上去
  • x86 16天前
    5
    已解决,请更新到最新测试
主题数
17 帖子数
16 精华数
0 注册排名
1812

AltStyle によって変換されたページ (->オリジナル) /