add userblocking opengroupv2 and quoting back of messages
parent
5916ce5cbe
commit
98b69c17f0
@ -0,0 +1,83 @@
|
||||
import { ApiV2 } from '.';
|
||||
import { getV2OpenGroupRoom } from '../../data/opengroups';
|
||||
import { ConversationModel } from '../../models/conversation';
|
||||
import { downloadAttachmentOpenGroupV2 } from '../../receiver/attachments';
|
||||
import { arrayBufferFromFile } from '../../types/Attachment';
|
||||
import { AttachmentUtil } from '../../util';
|
||||
|
||||
export async function updateOpenGroupV2(convo: ConversationModel, groupName: string, avatar: any) {
|
||||
if (avatar) {
|
||||
// I hate duplicating this...
|
||||
const readFile = async (attachment: any) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const fileReader = new FileReader();
|
||||
fileReader.onload = (e: any) => {
|
||||
const data = e.target.result;
|
||||
resolve({
|
||||
...attachment,
|
||||
data,
|
||||
size: data.byteLength,
|
||||
});
|
||||
};
|
||||
fileReader.onerror = reject;
|
||||
fileReader.onabort = reject;
|
||||
fileReader.readAsArrayBuffer(attachment.file);
|
||||
});
|
||||
const avatarAttachment: any = await readFile({ file: avatar });
|
||||
|
||||
// We want a square
|
||||
const withBlob = await AttachmentUtil.autoScale(
|
||||
{
|
||||
contentType: avatar.type,
|
||||
file: new Blob([avatarAttachment.data], {
|
||||
type: avatar.contentType,
|
||||
}),
|
||||
},
|
||||
{
|
||||
maxSide: 640,
|
||||
maxSize: 1000 * 1024,
|
||||
}
|
||||
);
|
||||
const dataResized = await arrayBufferFromFile(withBlob.file);
|
||||
const roomInfos = await getV2OpenGroupRoom(convo.id);
|
||||
if (!roomInfos || !dataResized.byteLength) {
|
||||
return false;
|
||||
}
|
||||
const uploadedFileDetails = await ApiV2.uploadImageForRoomOpenGroupV2(
|
||||
new Uint8Array(dataResized),
|
||||
roomInfos
|
||||
);
|
||||
|
||||
if (!uploadedFileDetails || !uploadedFileDetails.fileUrl) {
|
||||
window.log.warn('File opengroupv2 upload failed');
|
||||
return;
|
||||
}
|
||||
let url: URL;
|
||||
try {
|
||||
url = new URL(uploadedFileDetails.fileUrl);
|
||||
|
||||
const pathname = url.pathname;
|
||||
const downloaded = await downloadAttachmentOpenGroupV2(pathname, roomInfos);
|
||||
if (!(downloaded instanceof Uint8Array)) {
|
||||
const typeFound = typeof downloaded;
|
||||
throw new Error(`Expected a plain Uint8Array but got ${typeFound}`);
|
||||
}
|
||||
|
||||
const upgraded = await window.Signal.Migrations.processNewAttachment({
|
||||
data: downloaded.buffer,
|
||||
isRaw: true,
|
||||
url: pathname,
|
||||
});
|
||||
// TODO on our opengroupv2 we don't have a way to know when the file changed on the server.
|
||||
// maybe we should download it once in a while even if we don't know if the file changed?
|
||||
convo.set('avatarPointer', pathname);
|
||||
|
||||
window.log.warn('TODO update of roomName');
|
||||
await convo.setGroupNameAndAvatar(convo.get('name') || 'Unknown', upgraded.path);
|
||||
} catch (e) {
|
||||
window.log.error(`Could not decrypt profile image: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
export async function updateOpenGroup(convo: any, groupName: string, avatar: any) {
|
||||
const API = await convo.getPublicSendData();
|
||||
|
||||
if (avatar) {
|
||||
// I hate duplicating this...
|
||||
const readFile = async (attachment: any) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const fileReader = new FileReader();
|
||||
fileReader.onload = (e: any) => {
|
||||
const data = e.target.result;
|
||||
resolve({
|
||||
...attachment,
|
||||
data,
|
||||
size: data.byteLength,
|
||||
});
|
||||
};
|
||||
fileReader.onerror = reject;
|
||||
fileReader.onabort = reject;
|
||||
fileReader.readAsArrayBuffer(attachment.file);
|
||||
});
|
||||
const avatarAttachment: any = await readFile({ file: avatar });
|
||||
|
||||
// We want a square for iOS
|
||||
const withBlob = await window.Signal.Util.AttachmentUtil.autoScale(
|
||||
{
|
||||
contentType: avatar.type,
|
||||
file: new Blob([avatarAttachment.data], {
|
||||
type: avatar.contentType,
|
||||
}),
|
||||
},
|
||||
{
|
||||
maxSide: 640,
|
||||
maxSize: 1000 * 1024,
|
||||
}
|
||||
);
|
||||
const dataResized = await window.Signal.Types.Attachment.arrayBufferFromFile(withBlob.file);
|
||||
// const tempUrl = window.URL.createObjectURL(avatar);
|
||||
|
||||
// Get file onto public chat server
|
||||
const fileObj = await API.serverAPI.putAttachment(dataResized);
|
||||
if (fileObj === null) {
|
||||
// problem
|
||||
window.log.warn('File upload failed');
|
||||
return;
|
||||
}
|
||||
|
||||
// lets not allow ANY URLs, lets force it to be local to public chat server
|
||||
const url = new URL(fileObj.url);
|
||||
|
||||
// write it to the channel
|
||||
await API.setChannelAvatar(url.pathname);
|
||||
}
|
||||
|
||||
if (await API.setChannelName(groupName)) {
|
||||
// queue update from server
|
||||
// and let that set the conversation
|
||||
API.pollForChannelOnce();
|
||||
// or we could just directly call
|
||||
// convo.setGroupName(groupName);
|
||||
// but gut is saying let the server be the definitive storage of the state
|
||||
// and trickle down from there
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue