frontend: Implement 'invisible mode' feature.

Transitions the frontend of the web app to no longer use the
user status `away` field for setting a user's activity status
to be 'unavailable' (which is now a deprecated way to access
a user's `presence_enabled` setting).

Instead we now directly use and update the user's `presence_enabled`
setting for this feature.

Renames frontend code related to the feature to `invisible_mode`
vs `away`.

We lose node test coverage in `user_status.js` because we are now
using `channel.patch` to send these user setting updates to the
server.

Removes the temporary updates to `server_events_dispatch.py` (and
related tests) made in a previous commit, since we no longer have
or need the `away_user_ids` set.
This commit is contained in:
Lauryn Menard
2022-09-21 15:49:36 +02:00
committed by Tim Abbott
parent b2e0b5187d
commit d5b7551f09
18 changed files with 68 additions and 228 deletions

View File

@@ -1,17 +1,14 @@
import * as blueslip from "./blueslip";
import * as channel from "./channel";
import * as emoji from "./emoji";
import {user_settings} from "./user_settings";
const away_user_ids = new Set();
const user_info = new Map();
const user_status_emoji_info = new Map();
export function server_update(opts) {
export function server_update_status(opts) {
channel.post({
url: "/json/users/me/status",
data: {
away: opts.away,
status_text: opts.status_text,
emoji_name: opts.emoji_name,
emoji_code: opts.emoji_code,
@@ -25,30 +22,22 @@ export function server_update(opts) {
});
}
export function server_set_away() {
server_update({away: true});
export function server_invisible_mode_on() {
channel.patch({
url: "/json/settings",
data: {
presence_enabled: false,
},
});
}
export function server_revoke_away() {
server_update({away: false});
}
export function set_away(user_id) {
if (typeof user_id !== "number") {
blueslip.error("need ints for user_id");
}
away_user_ids.add(user_id);
}
export function revoke_away(user_id) {
if (typeof user_id !== "number") {
blueslip.error("need ints for user_id");
}
away_user_ids.delete(user_id);
}
export function is_away(user_id) {
return away_user_ids.has(user_id);
export function server_invisible_mode_off() {
channel.patch({
url: "/json/settings",
data: {
presence_enabled: true,
},
});
}
export function get_status_text(user_id) {
@@ -85,7 +74,6 @@ export function set_status_emoji(opts) {
}
export function initialize(params) {
away_user_ids.clear();
user_info.clear();
for (const [str_user_id, dct] of Object.entries(params.user_status)) {
@@ -93,10 +81,6 @@ export function initialize(params) {
// convert them here.
const user_id = Number.parseInt(str_user_id, 10);
if (dct.away) {
away_user_ids.add(user_id);
}
if (dct.status_text) {
user_info.set(user_id, dct.status_text);
}