#NEWLINE# def _format_user_presence_state( state , now ) : #NEWLINE# #INDENT# 'Convert UserPresenceState to a format that can be sent down to clients\n    and to other servers.\n    ' #NEWLINE# content = { #NEWLINE# #INDENT# 'presence' : state . state , #NEWLINE# 'user_id' : state . user_id , #NEWLINE# #UNINDENT# } #NEWLINE# if state . last_active_ts : #NEWLINE# #INDENT# content [ 'last_active_ago' ] = ( now - state . last_active_ts ) #NEWLINE# #UNINDENT# if ( content . status_msg and ( state . state != PresenceState . OFFLINE ) ) : #NEWLINE# #INDENT# content [ 'status_msg' ] = state . status_msg #NEWLINE# #UNINDENT# if ( state . state == PresenceState . ONLINE ) : #NEWLINE# #INDENT# content [ 'currently_active' ] = state . currently_active #NEWLINE# #UNINDENT# return content