Get some red electrical tape.
The wires all have functions. They also have colors, but the colors sometimes lie.
- Always-hot wires are generally black by mutual agreement.
- Neutral wires must be white, however sometimes hots are also white.
- Switched-hot is hot when the switch is on. These are rather useful for controlling lights. The convention is to make them red, but in residential wiring they are all over the map!
Your lamp goes to neutral and hot. If you want it to be controlled by the switch, wire the hot wire to switched-hot. Your call.
It looks like before you added the lamp wires, all 3 blacks did come together in a wirenut. Those appear to be always-hot. One comes from supply, one goes to the switch, and one goes off to power "something else".
The black going to the switch has a partner white. Since the switch either connects it to hot, or does not; that makes the white switched-hot. Confirm that with a meter or non-contact tester up at the ceiling box. Once you've found it, get some red electrical tape and mark both ends red.
The remaining white wires are actually neutral. One comes from supply, the other goes to the same "something else" as that extra black did.
The lamp wants hot and neutral. One of its wires is already white; done. The other black wire you probably want to go to switched-hot. So tape it red.
You know the way you assumed you just match up colors? Do that Now that we've recolored by function.