onReceive method

  1. @override
void onReceive(
  1. LocalityEvent localityEvent
)
override

React to events being thrown. Use switch case on the localityEvent.event

Implementation

@override
void onReceive(LocalityEvent localityEvent)
{
  switch ( localityEvent.event ) {
    case 'send_friend_request':

      LocalityUser sender = LocalityUser(localityEvent.payload['sender_id'], localityEvent.payload['sender_public_key']);
      LocalityUser recipient = LocalityUser(localityEvent.payload['recipient_id'], localityEvent.payload['recipient_public_key']);

      if ( localityEvent.payload['sender_id'] == owner.id ) {
        sentFriendRequests.add(FriendRequest( sender: sender, recipient: recipient ));
      } else {
        receivedFriendRequests.add(FriendRequest( sender: sender, recipient: recipient ));
      }
      notifyListeners();
      break;
  }
}