mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
presence: Eliminate unused mobile-related code.
We had a plan at some point to use this to display a phone icon or something for users who would receive push notifications if you messaged them. IT's not clear that feature was a good idea in any case, but it certainly shouldn't be synced as presence data; it would change >100x less often than the rest of presence and so should likely be synced differently, maybe as a property on user. So it's best to delete this prototype.
This commit is contained in:
@@ -806,7 +806,7 @@ run_test('update_presence_info', () => {
|
||||
activity.update_presence_info(alice.user_id, info, server_time);
|
||||
assert(inserted);
|
||||
|
||||
const expected = { status: 'active', mobile: false, last_active: 500 };
|
||||
const expected = { status: 'active', last_active: 500 };
|
||||
assert.deepEqual(presence.presence_info[alice.user_id], expected);
|
||||
});
|
||||
|
||||
|
||||
@@ -53,8 +53,7 @@ run_test('my user', () => {
|
||||
assert.equal(presence.get_status(me.user_id), 'active');
|
||||
});
|
||||
|
||||
run_test('on_mobile_property', () => {
|
||||
// TODO: move this test to a new test module directly testing presence.js
|
||||
run_test('status_from_timestamp', () => {
|
||||
const status_from_timestamp = presence._status_from_timestamp;
|
||||
|
||||
const base_time = 500;
|
||||
@@ -66,69 +65,59 @@ run_test('on_mobile_property', () => {
|
||||
};
|
||||
let status = status_from_timestamp(
|
||||
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
||||
assert.equal(status.mobile, false);
|
||||
|
||||
info.Android = {
|
||||
info.random_client = {
|
||||
status: "active",
|
||||
timestamp: base_time + OFFLINE_THRESHOLD_SECS / 2,
|
||||
pushable: false,
|
||||
};
|
||||
status = status_from_timestamp(
|
||||
base_time + OFFLINE_THRESHOLD_SECS, info);
|
||||
assert.equal(status.mobile, true);
|
||||
assert.equal(status.status, "active");
|
||||
|
||||
status = status_from_timestamp(
|
||||
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
||||
assert.equal(status.mobile, false);
|
||||
assert.equal(status.status, "active");
|
||||
|
||||
status = status_from_timestamp(
|
||||
base_time + OFFLINE_THRESHOLD_SECS * 2, info);
|
||||
assert.equal(status.mobile, false);
|
||||
assert.equal(status.status, "offline");
|
||||
|
||||
info.Android = {
|
||||
info.random_client = {
|
||||
status: "idle",
|
||||
timestamp: base_time + OFFLINE_THRESHOLD_SECS / 2,
|
||||
pushable: true,
|
||||
};
|
||||
status = status_from_timestamp(
|
||||
base_time + OFFLINE_THRESHOLD_SECS, info);
|
||||
assert.equal(status.mobile, true);
|
||||
assert.equal(status.status, "idle");
|
||||
|
||||
status = status_from_timestamp(
|
||||
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
||||
assert.equal(status.mobile, false);
|
||||
assert.equal(status.status, "active");
|
||||
|
||||
status = status_from_timestamp(
|
||||
base_time + OFFLINE_THRESHOLD_SECS * 2, info);
|
||||
assert.equal(status.mobile, true);
|
||||
assert.equal(status.status, "offline");
|
||||
|
||||
info.Android = {
|
||||
info.random_client = {
|
||||
status: "offline",
|
||||
timestamp: base_time + OFFLINE_THRESHOLD_SECS / 2,
|
||||
pushable: true,
|
||||
};
|
||||
status = status_from_timestamp(
|
||||
base_time + OFFLINE_THRESHOLD_SECS, info);
|
||||
assert.equal(status.mobile, true);
|
||||
assert.equal(status.status, "offline");
|
||||
|
||||
status = status_from_timestamp(
|
||||
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
||||
assert.equal(status.mobile, false);
|
||||
assert.equal(status.status, "active"); // website
|
||||
|
||||
status = status_from_timestamp(
|
||||
base_time + OFFLINE_THRESHOLD_SECS * 2, info);
|
||||
assert.equal(status.mobile, true);
|
||||
assert.equal(status.status, "offline");
|
||||
|
||||
info.Android = {
|
||||
info.random_client = {
|
||||
status: "unknown",
|
||||
timestamp: base_time + OFFLINE_THRESHOLD_SECS / 2,
|
||||
pushable: true,
|
||||
@@ -136,13 +125,12 @@ run_test('on_mobile_property', () => {
|
||||
let called = false;
|
||||
blueslip.error = function () {
|
||||
assert.equal(arguments[0], 'Unexpected status');
|
||||
assert.deepEqual(arguments[1].presence_object, info.Android);
|
||||
assert.deepEqual(arguments[1].presence_object, info.random_client);
|
||||
assert.equal(arguments[2], undefined);
|
||||
called = true;
|
||||
};
|
||||
status = status_from_timestamp(
|
||||
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
||||
assert.equal(status.mobile, false);
|
||||
assert.equal(status.status, "active"); // website
|
||||
assert(called);
|
||||
});
|
||||
@@ -175,19 +163,19 @@ run_test('set_presence_info', () => {
|
||||
presence.set_info(presences, base_time);
|
||||
|
||||
assert.deepEqual(presence.presence_info[alice.user_id],
|
||||
{ status: 'active', mobile: false, last_active: 500}
|
||||
{ status: 'active', last_active: 500}
|
||||
);
|
||||
|
||||
assert.deepEqual(presence.presence_info[fred.user_id],
|
||||
{ status: 'idle', mobile: false, last_active: 500}
|
||||
{ status: 'idle', last_active: 500}
|
||||
);
|
||||
|
||||
assert.deepEqual(presence.presence_info[me.user_id],
|
||||
{ status: 'active', mobile: false, last_active: 500}
|
||||
{ status: 'active', last_active: 500}
|
||||
);
|
||||
|
||||
assert.deepEqual(presence.presence_info[zoe.user_id],
|
||||
{ status: 'offline', mobile: false, last_active: undefined}
|
||||
{ status: 'offline', last_active: undefined}
|
||||
);
|
||||
|
||||
assert(!presence.presence_info[bot.user_id]);
|
||||
@@ -224,6 +212,6 @@ run_test('set_info_for_user', () => {
|
||||
presence.presence_info[alice.user_id] = undefined;
|
||||
presence.set_info_for_user(alice.user_id, info, server_time);
|
||||
|
||||
const expected = { status: 'active', mobile: false, last_active: 500 };
|
||||
const expected = { status: 'active', last_active: 500 };
|
||||
assert.deepEqual(presence.presence_info[alice.user_id], expected);
|
||||
});
|
||||
|
||||
@@ -14,12 +14,6 @@ const OFFLINE_THRESHOLD_SECS = 140;
|
||||
|
||||
const BIG_REALM_COUNT = 250;
|
||||
|
||||
const MOBILE_DEVICES = ["Android", "ZulipiOS", "ios"];
|
||||
|
||||
function is_mobile(device) {
|
||||
return MOBILE_DEVICES.indexOf(device) !== -1;
|
||||
}
|
||||
|
||||
exports.is_active = function (user_id) {
|
||||
if (exports.presence_info[user_id]) {
|
||||
const status = exports.presence_info[user_id].status;
|
||||
@@ -49,24 +43,15 @@ exports.get_user_ids = function () {
|
||||
function status_from_timestamp(baseline_time, info) {
|
||||
let status = 'offline';
|
||||
let last_active = 0;
|
||||
let mobileAvailable = false;
|
||||
let nonmobileAvailable = false;
|
||||
|
||||
_.each(info, function (device_presence, device) {
|
||||
const age = baseline_time - device_presence.timestamp;
|
||||
if (last_active < device_presence.timestamp) {
|
||||
last_active = device_presence.timestamp;
|
||||
}
|
||||
if (is_mobile(device)) {
|
||||
mobileAvailable = device_presence.pushable || mobileAvailable;
|
||||
}
|
||||
if (age < OFFLINE_THRESHOLD_SECS) {
|
||||
switch (device_presence.status) {
|
||||
case 'active':
|
||||
if (is_mobile(device)) {
|
||||
mobileAvailable = true;
|
||||
} else {
|
||||
nonmobileAvailable = true;
|
||||
}
|
||||
status = device_presence.status;
|
||||
break;
|
||||
case 'idle':
|
||||
@@ -85,7 +70,6 @@ function status_from_timestamp(baseline_time, info) {
|
||||
}
|
||||
});
|
||||
return {status: status,
|
||||
mobile: !nonmobileAvailable && mobileAvailable,
|
||||
last_active: last_active };
|
||||
}
|
||||
|
||||
@@ -153,7 +137,6 @@ exports.update_info_for_small_realm = function () {
|
||||
|
||||
exports.presence_info[user_id] = {
|
||||
status: status,
|
||||
mobile: false,
|
||||
last_active: undefined,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user