@statsd_increment('user_presence')
def do_update_user_presence(user_profile: UserProfile, client: Client, log_time: datetime.datetime, status: int) -> None:
    client = consolidate_client(client)
    defaults = dict(timestamp=log_time, status=status, realm_id=user_profile.realm_id)
    (presence, created) = UserPresence.objects.get_or_create(user_profile=user_profile, client=client, defaults=defaults)
    stale_status = ((log_time - presence.timestamp) > datetime.timedelta(minutes=1, seconds=10))
    was_idle = (presence.status == UserPresence.IDLE)
    became_online = ((status == UserPresence.ACTIVE) and (stale_status or was_idle))
    if (((not created) and stale_status) or was_idle or (status == presence.status)):
        presence.timestamp = log_time
        update_fields = ['timestamp']
        if (presence.status != status):
            presence.status = status
            update_fields.append('status')
        presence.save(update_fields=update_fields)
    if ((not user_profile.realm.presence_disabled) and (created or became_online)):
        send_presence_changed(user_profile, presence)
@statsd_increment('user_presence')
def do_update_user_presence(user_profile: UserProfile, client: Client, log_time: datetime.datetime, status: int) -> None:
    client = consolidate_client(client)
    defaults = dict(timestamp=log_time, status=status, realm_id=user_profile.realm_id)
    (presence, created) = UserPresence.objects.get_or_create(user_profile=user_profile, client=client, defaults=defaults)
    stale_status = ((log_time - presence.timestamp) > datetime.timedelta(minutes=1, seconds=10))
    was_idle = (presence.status == UserPresence.IDLE)
    became_online = ((status == UserPresence.ACTIVE) and (stale_status or was_idle))
    if (((not created) and stale_status) or was_idle or (status == presence.status)):
        presence.timestamp = log_time
        update_fields = ['timestamp']
        if (presence.status != status):
            presence.status = status
            update_fields.append('status')
        presence.save(update_fields=update_fields)
    if ((not user_profile.realm.presence_disabled) and (created or became_online)):
        send_presence_changed(user_profile, presence)