only keep id references to messages needing a pending file,

make sure the in-memory map of messages gets updated too
this prevents an infinite loop
make sure we only ever try to upload a file once
fix bug that prevented messages from getting sent after file upload