presence: Add history_limit_days param to the API.

This param allows clients to specify how much presence history they want
to fetch. Previously, the server always returned 14 days of history.
With the recent migration of the presence API to the much more efficient
system relying on incremental fetches via the last_update_id param added
in #29999, we can now afford to provide much more history to clients
that request it - as all that historical data will only be fetched once.

There are three endpoints involved:
- `/register` - this is the main useful endpoint for this, used by API
clients to fetch initial data and register an events queue. Clients can
pass the `presence_history_limit_days` param here.
- `/users/me/presence` - this endpoint is currently used by clients to
update their presence status and fetch incremental data, making the new
functionality not particularly useful here. However, we still add the
new `history_limit_days` param here, in case in the future clients
transition to using this also for the initial presence data fetch.
- `/` - used when opening the webapp. Naturally, params aren't passed
here, so the server just assumes a value from
`settings.PRESENCE_HISTORY_LIMIT_DAYS_FOR_WEB_APP` and returns
information about this default value in page_params.
This commit is contained in:
Mateusz Mandera
2024-08-30 00:55:09 +02:00
committed by Tim Abbott
parent 6ce096c0ff
commit a36f906d1a
14 changed files with 150 additions and 24 deletions

View File

@@ -1,7 +1,10 @@
import assert from "minimalistic-assert";
import * as hash_util from "./hash_util";
import {$t} from "./i18n";
import * as muted_users from "./muted_users";
import * as narrow_state from "./narrow_state";
import {page_params} from "./page_params";
import * as people from "./people";
import * as presence from "./presence";
import {realm} from "./state_data";
@@ -142,13 +145,10 @@ export function user_last_seen_time_status(user_id: number): string {
return $t({defaultMessage: "Activity unknown"});
} else if (last_active_date === undefined) {
// There are situations where the client has incomplete presence
// history on a user. This can happen when users are deactivated,
// or when they just haven't been present in a long time (and we
// may have queries on presence that go back only N weeks).
//
// We give this vague status for such users; we will get to
// delete this code when we finish rewriting the presence API.
return $t({defaultMessage: "Active more than 2 weeks ago"});
// history on a user. This can happen when users are deactivated,
// or when the user's last activity is older than what we fetch.
assert(page_params.presence_history_limit_days_for_web_app === 365);
return $t({defaultMessage: "Not active in the last year"});
}
return timerender.last_seen_status_from_date(last_active_date);
}