feat: Pass through a custom image
resize function to the client This allows the use of the native imaging package in a more easy way.
This commit is contained in:
		
							parent
							
								
									ac24da4963
								
							
						
					
					
						commit
						6a57f99c00
					
				|  | @ -518,6 +518,10 @@ class Event extends MatrixEvent { | ||||||
|     if (![EventTypes.Message, EventTypes.Sticker].contains(type)) { |     if (![EventTypes.Message, EventTypes.Sticker].contains(type)) { | ||||||
|       throw ("This event has the type '$type' and so it can't contain an attachment."); |       throw ("This event has the type '$type' and so it can't contain an attachment."); | ||||||
|     } |     } | ||||||
|  |     if (status.isSending) { | ||||||
|  |       final localFile = room.sendingFilePlaceholders[eventId]; | ||||||
|  |       if (localFile != null) return localFile; | ||||||
|  |     } | ||||||
|     final database = room.client.database; |     final database = room.client.database; | ||||||
|     final mxcUrl = attachmentOrThumbnailMxcUrl(getThumbnail: getThumbnail); |     final mxcUrl = attachmentOrThumbnailMxcUrl(getThumbnail: getThumbnail); | ||||||
|     if (mxcUrl == null) { |     if (mxcUrl == null) { | ||||||
|  |  | ||||||
|  | @ -682,6 +682,8 @@ class Room { | ||||||
|     return sendEvent(event, txid: txid); |     return sendEvent(event, txid: txid); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   final Map<String, MatrixFile> sendingFilePlaceholders = {}; | ||||||
|  | 
 | ||||||
|   /// Sends a [file] to this room after uploading it. Returns the mxc uri of |   /// Sends a [file] to this room after uploading it. Returns the mxc uri of | ||||||
|   /// the uploaded file. If [waitUntilSent] is true, the future will wait until |   /// the uploaded file. If [waitUntilSent] is true, the future will wait until | ||||||
|   /// the message event has received the server. Otherwise the future will only |   /// the message event has received the server. Otherwise the future will only | ||||||
|  | @ -698,12 +700,12 @@ class Room { | ||||||
|     String? txid, |     String? txid, | ||||||
|     Event? inReplyTo, |     Event? inReplyTo, | ||||||
|     String? editEventId, |     String? editEventId, | ||||||
|     bool waitUntilSent = false, |  | ||||||
|     int? shrinkImageMaxDimension, |     int? shrinkImageMaxDimension, | ||||||
|     MatrixImageFile? thumbnail, |     MatrixImageFile? thumbnail, | ||||||
|     Map<String, dynamic>? extraContent, |     Map<String, dynamic>? extraContent, | ||||||
|   }) async { |   }) async { | ||||||
|     txid ??= client.generateUniqueTransactionId(); |     txid ??= client.generateUniqueTransactionId(); | ||||||
|  |     sendingFilePlaceholders[txid] = file; | ||||||
| 
 | 
 | ||||||
|     // Create a fake Event object as a placeholder for the uploading file: |     // Create a fake Event object as a placeholder for the uploading file: | ||||||
|     final syncUpdate = SyncUpdate( |     final syncUpdate = SyncUpdate( | ||||||
|  | @ -798,12 +800,14 @@ class Room { | ||||||
|         syncUpdate.rooms!.join!.values.first.timeline!.events!.first |         syncUpdate.rooms!.join!.values.first.timeline!.events!.first | ||||||
|             .unsigned![messageSendingStatusKey] = EventStatus.error.intValue; |             .unsigned![messageSendingStatusKey] = EventStatus.error.intValue; | ||||||
|         await _handleFakeSync(syncUpdate); |         await _handleFakeSync(syncUpdate); | ||||||
|  |         sendingFilePlaceholders.remove(txid); | ||||||
|         rethrow; |         rethrow; | ||||||
|       } catch (_) { |       } catch (_) { | ||||||
|         if (DateTime.now().isAfter(timeoutDate)) { |         if (DateTime.now().isAfter(timeoutDate)) { | ||||||
|           syncUpdate.rooms!.join!.values.first.timeline!.events!.first |           syncUpdate.rooms!.join!.values.first.timeline!.events!.first | ||||||
|               .unsigned![messageSendingStatusKey] = EventStatus.error.intValue; |               .unsigned![messageSendingStatusKey] = EventStatus.error.intValue; | ||||||
|           await _handleFakeSync(syncUpdate); |           await _handleFakeSync(syncUpdate); | ||||||
|  |           sendingFilePlaceholders.remove(txid); | ||||||
|           rethrow; |           rethrow; | ||||||
|         } |         } | ||||||
|         Logs().v('Send File into room failed. Try again...'); |         Logs().v('Send File into room failed. Try again...'); | ||||||
|  | @ -855,15 +859,13 @@ class Room { | ||||||
|       }, |       }, | ||||||
|       if (extraContent != null) ...extraContent, |       if (extraContent != null) ...extraContent, | ||||||
|     }; |     }; | ||||||
|     final sendResponse = sendEvent( |     await sendEvent( | ||||||
|       content, |       content, | ||||||
|       txid: txid, |       txid: txid, | ||||||
|       inReplyTo: inReplyTo, |       inReplyTo: inReplyTo, | ||||||
|       editEventId: editEventId, |       editEventId: editEventId, | ||||||
|     ); |     ); | ||||||
|     if (waitUntilSent) { |     sendingFilePlaceholders.remove(txid); | ||||||
|       await sendResponse; |  | ||||||
|     } |  | ||||||
|     return uploadResp; |     return uploadResp; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue