Coder Social home page Coder Social logo

Comments (12)

Swathy-Mothilal avatar Swathy-Mothilal commented on August 10, 2024

@guzman-rc , could you please provide a video demonstrating the issue you're experiencing, along with the logs, to help us better understand the problem?

from office-js.

guzman-rc avatar guzman-rc commented on August 10, 2024

I will try to create a video, in the meantime I will explain the operation of the example Addin.

The objective of this Addin is to eliminate the metadata of the attached files, for this purpose, for each file that the user attaches the following tasks will be carried out:

  1. OnMessageAttachmentsChanged event identifies when the file has finished attaching.
  2. Download the contents of the attached file.
  3. Remove metadata from the downloaded file.
  4. Remove the attached file.
  5. The file without metadata is attached.

See log output when attaching file 1.pdf

Captura

The error occurs when we attach 3 or more files at the same time.

We have detected that there is a problem with the function: removeAttachmentAsync, it does not remove the file and ends the process.

from office-js.

rkpathak avatar rkpathak commented on August 10, 2024

@guzman-rc Can you share the handler function that is getting called for the event?

from office-js.

guzman-rc avatar guzman-rc commented on August 10, 2024

You can install the Addin to test it, the manifest file is available from the url:
https://www.adarsus.com/addin/outlook_event/manifest.xml

All the code is available from the file:
https://www.adarsus.com/addin/outlook_event/commands.js

The function called for the OnMessageAttachmentsChanged event is: onMessageAttachmentsChangedHandler

from office-js.

kumarshrey-msft avatar kumarshrey-msft commented on August 10, 2024

@guzman-rc
From my understanding this is the same issue like #4646 where the handler for OnMessageAttachmentsChanged itself is not getting triggered in certain scenarios when multiple files are attached, and is not specific to removeAttachmentAsync API as such, can you please confirm the same? If yes, we can close this issue as duplicate.

from office-js.

guzman-rc avatar guzman-rc commented on August 10, 2024

from office-js.

kumarshrey-msft avatar kumarshrey-msft commented on August 10, 2024

Hi @guzman-rc, I am able to reproduce the issue with the manifest you shared, however, I don't see it as a shortcoming of the removeAttachmentAsync API in itself. Consider the below example:

const attachments = [
    {"id":"AAkALgAAAAAAHYQDEapmEc2byACqAC/EWg0AF1DUX4ZWa0KEdGEzihNfpQACYSmLqQAAARIAEACiGPuEZvAmQZTeWzmA4gqn","name":"img1.png","contentType":"image/png","size":481031,"attachmentType":"file","isInline":false},
    {"id":"AAkALgAAAAAAHYQDEapmEc2byACqAC/EWg0AF1DUX4ZWa0KEdGEzihNfpQACYSmLqQAAARIAEABINoB+ZcOKQo3CwahJs/gU","name":"img2.png","contentType":"image/png","size":587031,"attachmentType":"file","isInline":false},
    {"id":"AAkALgAAAAAAHYQDEapmEc2byACqAC/EWg0AF1DUX4ZWa0KEdGEzihNfpQACYSmLqQAAARIAEAAUYVwHLqpaSKUiQ56g4KtN","name":"img3.png","contentType":"image/png","size":998554,"attachmentType":"file","isInline":false}
]

for (const item of attachments) {
    const id = item.id;
    // Remove an attachment
    Office.context.mailbox.item.removeAttachmentAsync(
        id,
        {
            "asyncContext": { foo: 6, bar: 28 }
        },
        function (asyncResult) {
            showMessage(JSON.stringify(asyncResult));
        }
    );
}

In this case, the removeAttachmentAsync API is successfully able to remove all the 3 files (and correspondingly, three OnMessageAttachmentsChanged events are fired for the corresponding files, with attachmentStatus set to removed. I believe you are running into a race condition due to the parallel flow of execution. I would suggest you re-look the way you are handling the asynchronous operations. Maybe instead of immediately reacting to OnMessageAttachmentsChanged finishing attaching the file, add a delay, process multiple such events together, and then correspondingly trigger the removeAttachmentAsync API.

Let me know your thoughts.

from office-js.

guzman-rc avatar guzman-rc commented on August 10, 2024

Hi @kumarshrey-msft,

For each OnMessageAttachmentsChanged event of type Added the following tasks are executed:

  1. Download the contents of the attached file.
  2. Remove metadata from the downloaded file.
  3. Remove the attached file.
  4. The file without metadata is attached.

As you can see, from the moment the OnMessageAttachmentsChanged event is fired until the removeAttachmentAsync function is invoked there is already a delay in the execution of the tasks:

  1. Download the contents of the attached file and
  2. Remove metadata from the downloaded file.

You propose to add an extra delay before invoking the removeAttachmentAsync function, how long?

from office-js.

DivyaPatidar avatar DivyaPatidar commented on August 10, 2024

@guzman-rc As a workaround can you try to ensure that removeAttachmentAsync calls are made sequentially from your side and see if that solves the issue?

from office-js.

guzman-rc avatar guzman-rc commented on August 10, 2024

It is not possible to execute sequentially removeAttachmentAsync, the processes:

  • Download the contents of the attached file.
  • Remove metadata from the downloaded file.
  • Remove the attached file.
  • The file without metadata is attached.

Must run every time OnMessageAttachmentsChanged event is fired.

from office-js.

DivyaPatidar avatar DivyaPatidar commented on August 10, 2024

Yes, I understand that. By sequential I mean using promise or something similar to ensure you make only one call to removeAttachmentAsync at a time.

from office-js.

guzman-rc avatar guzman-rc commented on August 10, 2024

It should not be a problem to invoke removeAttachment simultaneously, just make sure that the file has been attached successfully before you can invoke removeAttachment.

from office-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.