When a friend , then tap Your Photos Only.
Note: Photos and videos you don’t save from a Messages conversation are deleted in Shared with You and your library if the conversation in Messages is deleted.
To turn off Shared with You, go to Settings > Messages > Shared with You, then turn off Photos (green is on).