uploadMessageSticker: Compare against previous sticker, not cache
This commit is contained in:
		
					parent
					
						
							
								bedd2c8a15
							
						
					
				
			
			
				commit
				
					
						07bad13fa1
					
				
			
		
					 1 changed files with 13 additions and 10 deletions
				
			
		| 
						 | 
					@ -791,38 +791,41 @@ async function uploadMessageSticker(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // See uploadMessageQuote for comment on how we do caching for these
 | 
					  // See uploadMessageQuote for comment on how we do caching for these
 | 
				
			||||||
  // attachments.
 | 
					  // attachments.
 | 
				
			||||||
  const sticker =
 | 
					  const startingSticker = message.get('sticker');
 | 
				
			||||||
 | 
					  const stickerWithData =
 | 
				
			||||||
    message.cachedOutgoingStickerData ||
 | 
					    message.cachedOutgoingStickerData ||
 | 
				
			||||||
    (await loadStickerData(message.get('sticker')));
 | 
					    (await loadStickerData(startingSticker));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!sticker) {
 | 
					  if (!stickerWithData) {
 | 
				
			||||||
    return undefined;
 | 
					    return undefined;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const uploaded = await uploadQueue.add(() => uploadAttachment(sticker.data));
 | 
					  const uploaded = await uploadQueue.add(() =>
 | 
				
			||||||
 | 
					    uploadAttachment(stickerWithData.data)
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Add digest to the attachment
 | 
					  // Add digest to the attachment
 | 
				
			||||||
  const logId = `uploadMessageSticker(${message.idForLogging()}`;
 | 
					  const logId = `uploadMessageSticker(${message.idForLogging()}`;
 | 
				
			||||||
  const oldSticker = message.get('sticker');
 | 
					  const existingSticker = message.get('sticker');
 | 
				
			||||||
  strictAssert(
 | 
					  strictAssert(
 | 
				
			||||||
    oldSticker?.data !== undefined,
 | 
					    existingSticker?.data !== undefined,
 | 
				
			||||||
    `${logId}: Sticker was uploaded, but message doesn't ` +
 | 
					    `${logId}: Sticker was uploaded, but message doesn't ` +
 | 
				
			||||||
      'have a sticker anymore'
 | 
					      'have a sticker anymore'
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
  strictAssert(
 | 
					  strictAssert(
 | 
				
			||||||
    oldSticker.data.path === sticker.data?.path,
 | 
					    existingSticker.data.path === startingSticker?.data?.path,
 | 
				
			||||||
    `${logId}: Sticker was uploaded, but message has a different sticker`
 | 
					    `${logId}: Sticker was uploaded, but message has a different sticker`
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
  message.set('sticker', {
 | 
					  message.set('sticker', {
 | 
				
			||||||
    ...oldSticker,
 | 
					    ...existingSticker,
 | 
				
			||||||
    data: {
 | 
					    data: {
 | 
				
			||||||
      ...oldSticker.data,
 | 
					      ...existingSticker.data,
 | 
				
			||||||
      digest: Bytes.toBase64(uploaded.digest),
 | 
					      digest: Bytes.toBase64(uploaded.digest),
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return {
 | 
					  return {
 | 
				
			||||||
    ...sticker,
 | 
					    ...stickerWithData,
 | 
				
			||||||
    data: uploaded,
 | 
					    data: uploaded,
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue