我试着创建一个有封面照片的团体频道
this.sendBirdInstance.GroupChannel.createChannelWithUserIds(userIds, true, this.groupName, this.groupPhotoFile, '', function (createdChannel, error) {
...
}根据文档,我可以添加一个url或文件。
coverUrl :封面图像的文件或URL,您可以获取该文件或URL以呈现到UI中。
但是当添加一个文件时,我总是得到:"SendBirdException", code: 800110, message: "Invalid arguments."
有没有一种方法可以用文件而不是url创建一个组(因为我希望用户上传该文件)?
谢谢,
发布于 2017-09-12 19:57:25
正如您已经体验过的(我看到您几天前已经创建了一个GitHub中的问题 ),SendBird的支持是不可靠的。
事实上,他们提供了他们的只是一个缩小的版本的JavaScript SDK (我个人认为这是非常糟糕的),这也是有帮助的。
无论如何,我可以隔离createChannelWithUserIds函数:
! function (e, n) {
// ...
}(this, function () {
// ...
var h = function (e) {
for (var n in e) if (e.hasOwnProperty(n)) return !1;
return Array.isArray(e) ? JSON.stringify(e) === JSON.stringify([]) : JSON.stringify(e) === JSON.stringify({})
},
// ...
A = function () { // it returns SendBird function
// ...
var w = function (e) { // w is this.GroupChannel
// ...
w.createChannelWithUserIds = function () {
// ...
// here comes the param validation (I've added spaces for a better lecture):
if (!Array.isArray(e) || "boolean" != typeof n || "string" != typeof t && null !== t && void 0 !== t || "string" != typeof r && h(r) && null !== r && void 0 !== r || "string" != typeof a && null !== a && void 0 !== a || "string" != typeof i && null !== i && void 0 !== i) return void U(null, new p("Invalid arguments.", J.INVALID_PARAMETER), s);
// It will return "Invalid arguments." if any of the conditions evaluates to true
// ...
}
}
}
return function () {
// ...
}().SendBird
});您使用的函数如下:
createChannelWithUserIds(o, n, t, r, a, s); 因此,第四个参数(r)是coverURL:带有封面图片(this.groupPhotoFile)的文件;
它的验证基本上是说:
"string" != typeof r // if `r` is not a string (a URL)
&& h(r) // and the returned value of function h(r) is true
&& null !== r // and it is not null
&& void 0 !== r // and it is not undefined该参数无效。
您的文件不是字符串,不是null,也不是未定义的,因此所有内容都归结为h()函数:
var h = function (e) {
for (var n in e) if (e.hasOwnProperty(n)) return !1;
return Array.isArray(e) ? JSON.stringify(e) === JSON.stringify([]) : JSON.stringify(e) === JSON.stringify({})
}上面的函数首先签入对象是否具有任何属性--对象本身的成员(即不属于原型链的属性)。然后,如果它没有任何自己的属性,它将检查stringify对象/数组是否等于空的对象/数组。
我不能说开发人员在通过这个函数验证文件时的意图是什么,而是一个标准的文件对象:
true。true。正如我们前面看到的,我们需要h()来返回false:如果它返回true,验证就会失败。
要修复此行为,可以将h()函数更改为如下所示:
var h = function( e ){
return !(e instanceof File);
// or return e.constructor != File;
// or return Object.getPrototypeOf( e ) != File.prototype );
// or return e.__proto__ != File.prototype )
// or return e.constructor.prototype != File.prototype )
}但我不会搞砸的。它可用于具有不同用途的未来版本。
因此,最好的选择是将createChannelWithUserIds()函数更改为:
h()函数的调用。为此,您可以重写SendBird实例中的函数:
var sb = new SendBird( { appId: ... } );
sb.GroupChannel.createChannelWithUserIds = function(){ ... };但是它不能保证工作,而且可能会在以后的版本中中断,所以我只编辑SendBird.min.js文件。换言之,将:
if(!Array.isArray(e)||"boolean"!=typeof n||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof r&&h(r)&&null!==r&&void 0!==r||"string"!=typeof a&&null!==a&&void 0!==a||"string"!=typeof i&&null!==i&&void 0!==i)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),s);通过以下方式:
if(!Array.isArray(e)||"boolean"!=typeof n||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof a&&null!==a&&void 0!==a||"string"!=typeof i&&null!==i&&void 0!==i)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),s);在当前版本(v3.0.41)中,您将发现上面代码的两个巧合:一个用于createChannel,另一个用于createChannelWithUserIds,您可以替换两者。
当然,编辑.js文件很烦人,因为每次升级SendGrid时都需要小心替换代码。你可以在你的CI管道中创建一个自动任务来为你做这件事。
希望SendGrid开发人员能够认识到您的问题,并在以后的发行版中解决它。
https://stackoverflow.com/questions/46036724
复制相似问题