Fix MSG_DATA index variables' types and handling

This fixes size disparity between MSG_DATA's
n and istart/iend fields, and related MESSAGES' fields.
Now they all are of new unified type MSG_IDX.

Dirty bit inversion hacks are replaced with explicit
MSG_IDX_MAX constant, used to indicate when an index
variable doesn't contain a sensible value.

All index calculations are now using the new type,
fixing some signedness warnings.
Move friend/group-related stuff to friend.h
Fix types to avoid signedness errors in friend.c
Fix types to avoid signedness errors in ui.c
Fix types to avoid signedness errors in list.c
Fix types to avoid signedness errors in scrollable.c
Fix types to avoid signedness errors in messages.c
Fix types to avoid signedness errors in dns.c