You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			53 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			TypeScript
		
	
| 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 });
 | |
|     // const tempUrl = window.URL.createObjectURL(avatar);
 | |
| 
 | |
|     // Get file onto public chat server
 | |
|     const fileObj = await API.serverAPI.putAttachment(avatarAttachment.data);
 | |
|     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
 | |
|   }
 | |
| }
 |