MySQL / MyISAM: Queries sometimes very slow, no waiting for lock time
If you are looking for the latest 100, you have not quite gotten it.  You need LIMIT 100 in the inner queries, too.  (OK, that will slow down the query a little, but it might be 'correct'.)

Back to performance...

Short answer:  Switch to InnoDB; it is likely to help, especially in avoiding strange locks.  (Instead, you will other strange locks, but usually not for as long.)

Which table is date in?  Hard to analyze the query without having all columns qualified and SHOW CREATE TABLE.  EXPLAIN SELECT ... would also help.  But I will try...

Indexes needed:

table4: INDEX(userId1, userId2)  -- in this order
table1: INDEX(userId)
table3: INDEX(groupId)
table2: INDEX(userId, class)  -- in this order