def access_message(user_profile, message_id):
 try:
  message = Message.objects.select_related().get(id=message_id)
 except Message.DoesNotExist:
  raise JsonableError(_('Invalid message(s)'))
 try:
  user_message = UserMessage.objects.select_related().get(user_profile=user_profile, message=message)
 except UserMessage.DoesNotExist:
  user_message = None
 if (user_message is None):
  if (message.recipient.type != Recipient.STREAM):
   raise JsonableError(_('Invalid message(s)'))
  stream = Stream.objects.get(id=message.recipient.type_id)
  if (not stream.is_public()):
   raise JsonableError(_('Invalid message(s)'))
  if (stream.realm != user_profile.realm):
   raise JsonableError(_('Invalid message(s)'))
 return (message, user_message)

def access_message ( user_profile , message_id ) : try : message = Message . objects . select_related ( ) . get ( id = message_id ) except Message . DoesNotExist : raise JsonableError ( _ ( 'Invalid message(s)' ) ) try : user_message = UserMessage . objects . select_related ( ) . get ( user_profile = user_profile , message = message ) except UserMessage . DoesNotExist : user_message = None if ( user_message is None ) : if ( message . recipient . type != Recipient . STREAM ) : raise JsonableError ( _ ( 'Invalid message(s)' ) ) stream = Stream . objects . get ( id = message . recipient . type_id ) if ( not stream . is_public ( ) ) : raise JsonableError ( _ ( 'Invalid message(s)' ) ) if ( stream . realm != user_profile . realm ) : raise JsonableError ( _ ( 'Invalid message(s)' ) ) return ( message , user_message )
you can access a message by id in our apis that either: (1) you received or have previously accessed via starring .