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);
|
activity.update_presence_info(alice.user_id, info, server_time);
|
||||||
assert(inserted);
|
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);
|
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');
|
assert.equal(presence.get_status(me.user_id), 'active');
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('on_mobile_property', () => {
|
run_test('status_from_timestamp', () => {
|
||||||
// TODO: move this test to a new test module directly testing presence.js
|
|
||||||
const status_from_timestamp = presence._status_from_timestamp;
|
const status_from_timestamp = presence._status_from_timestamp;
|
||||||
|
|
||||||
const base_time = 500;
|
const base_time = 500;
|
||||||
@@ -66,69 +65,59 @@ run_test('on_mobile_property', () => {
|
|||||||
};
|
};
|
||||||
let status = status_from_timestamp(
|
let status = status_from_timestamp(
|
||||||
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
||||||
assert.equal(status.mobile, false);
|
|
||||||
|
|
||||||
info.Android = {
|
info.random_client = {
|
||||||
status: "active",
|
status: "active",
|
||||||
timestamp: base_time + OFFLINE_THRESHOLD_SECS / 2,
|
timestamp: base_time + OFFLINE_THRESHOLD_SECS / 2,
|
||||||
pushable: false,
|
pushable: false,
|
||||||
};
|
};
|
||||||
status = status_from_timestamp(
|
status = status_from_timestamp(
|
||||||
base_time + OFFLINE_THRESHOLD_SECS, info);
|
base_time + OFFLINE_THRESHOLD_SECS, info);
|
||||||
assert.equal(status.mobile, true);
|
|
||||||
assert.equal(status.status, "active");
|
assert.equal(status.status, "active");
|
||||||
|
|
||||||
status = status_from_timestamp(
|
status = status_from_timestamp(
|
||||||
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
||||||
assert.equal(status.mobile, false);
|
|
||||||
assert.equal(status.status, "active");
|
assert.equal(status.status, "active");
|
||||||
|
|
||||||
status = status_from_timestamp(
|
status = status_from_timestamp(
|
||||||
base_time + OFFLINE_THRESHOLD_SECS * 2, info);
|
base_time + OFFLINE_THRESHOLD_SECS * 2, info);
|
||||||
assert.equal(status.mobile, false);
|
|
||||||
assert.equal(status.status, "offline");
|
assert.equal(status.status, "offline");
|
||||||
|
|
||||||
info.Android = {
|
info.random_client = {
|
||||||
status: "idle",
|
status: "idle",
|
||||||
timestamp: base_time + OFFLINE_THRESHOLD_SECS / 2,
|
timestamp: base_time + OFFLINE_THRESHOLD_SECS / 2,
|
||||||
pushable: true,
|
pushable: true,
|
||||||
};
|
};
|
||||||
status = status_from_timestamp(
|
status = status_from_timestamp(
|
||||||
base_time + OFFLINE_THRESHOLD_SECS, info);
|
base_time + OFFLINE_THRESHOLD_SECS, info);
|
||||||
assert.equal(status.mobile, true);
|
|
||||||
assert.equal(status.status, "idle");
|
assert.equal(status.status, "idle");
|
||||||
|
|
||||||
status = status_from_timestamp(
|
status = status_from_timestamp(
|
||||||
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
||||||
assert.equal(status.mobile, false);
|
|
||||||
assert.equal(status.status, "active");
|
assert.equal(status.status, "active");
|
||||||
|
|
||||||
status = status_from_timestamp(
|
status = status_from_timestamp(
|
||||||
base_time + OFFLINE_THRESHOLD_SECS * 2, info);
|
base_time + OFFLINE_THRESHOLD_SECS * 2, info);
|
||||||
assert.equal(status.mobile, true);
|
|
||||||
assert.equal(status.status, "offline");
|
assert.equal(status.status, "offline");
|
||||||
|
|
||||||
info.Android = {
|
info.random_client = {
|
||||||
status: "offline",
|
status: "offline",
|
||||||
timestamp: base_time + OFFLINE_THRESHOLD_SECS / 2,
|
timestamp: base_time + OFFLINE_THRESHOLD_SECS / 2,
|
||||||
pushable: true,
|
pushable: true,
|
||||||
};
|
};
|
||||||
status = status_from_timestamp(
|
status = status_from_timestamp(
|
||||||
base_time + OFFLINE_THRESHOLD_SECS, info);
|
base_time + OFFLINE_THRESHOLD_SECS, info);
|
||||||
assert.equal(status.mobile, true);
|
|
||||||
assert.equal(status.status, "offline");
|
assert.equal(status.status, "offline");
|
||||||
|
|
||||||
status = status_from_timestamp(
|
status = status_from_timestamp(
|
||||||
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
||||||
assert.equal(status.mobile, false);
|
|
||||||
assert.equal(status.status, "active"); // website
|
assert.equal(status.status, "active"); // website
|
||||||
|
|
||||||
status = status_from_timestamp(
|
status = status_from_timestamp(
|
||||||
base_time + OFFLINE_THRESHOLD_SECS * 2, info);
|
base_time + OFFLINE_THRESHOLD_SECS * 2, info);
|
||||||
assert.equal(status.mobile, true);
|
|
||||||
assert.equal(status.status, "offline");
|
assert.equal(status.status, "offline");
|
||||||
|
|
||||||
info.Android = {
|
info.random_client = {
|
||||||
status: "unknown",
|
status: "unknown",
|
||||||
timestamp: base_time + OFFLINE_THRESHOLD_SECS / 2,
|
timestamp: base_time + OFFLINE_THRESHOLD_SECS / 2,
|
||||||
pushable: true,
|
pushable: true,
|
||||||
@@ -136,13 +125,12 @@ run_test('on_mobile_property', () => {
|
|||||||
let called = false;
|
let called = false;
|
||||||
blueslip.error = function () {
|
blueslip.error = function () {
|
||||||
assert.equal(arguments[0], 'Unexpected status');
|
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);
|
assert.equal(arguments[2], undefined);
|
||||||
called = true;
|
called = true;
|
||||||
};
|
};
|
||||||
status = status_from_timestamp(
|
status = status_from_timestamp(
|
||||||
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
base_time + OFFLINE_THRESHOLD_SECS - 1, info);
|
||||||
assert.equal(status.mobile, false);
|
|
||||||
assert.equal(status.status, "active"); // website
|
assert.equal(status.status, "active"); // website
|
||||||
assert(called);
|
assert(called);
|
||||||
});
|
});
|
||||||
@@ -175,19 +163,19 @@ run_test('set_presence_info', () => {
|
|||||||
presence.set_info(presences, base_time);
|
presence.set_info(presences, base_time);
|
||||||
|
|
||||||
assert.deepEqual(presence.presence_info[alice.user_id],
|
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],
|
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],
|
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],
|
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]);
|
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.presence_info[alice.user_id] = undefined;
|
||||||
presence.set_info_for_user(alice.user_id, info, server_time);
|
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);
|
assert.deepEqual(presence.presence_info[alice.user_id], expected);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,12 +14,6 @@ const OFFLINE_THRESHOLD_SECS = 140;
|
|||||||
|
|
||||||
const BIG_REALM_COUNT = 250;
|
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) {
|
exports.is_active = function (user_id) {
|
||||||
if (exports.presence_info[user_id]) {
|
if (exports.presence_info[user_id]) {
|
||||||
const status = exports.presence_info[user_id].status;
|
const status = exports.presence_info[user_id].status;
|
||||||
@@ -49,24 +43,15 @@ exports.get_user_ids = function () {
|
|||||||
function status_from_timestamp(baseline_time, info) {
|
function status_from_timestamp(baseline_time, info) {
|
||||||
let status = 'offline';
|
let status = 'offline';
|
||||||
let last_active = 0;
|
let last_active = 0;
|
||||||
let mobileAvailable = false;
|
|
||||||
let nonmobileAvailable = false;
|
|
||||||
_.each(info, function (device_presence, device) {
|
_.each(info, function (device_presence, device) {
|
||||||
const age = baseline_time - device_presence.timestamp;
|
const age = baseline_time - device_presence.timestamp;
|
||||||
if (last_active < device_presence.timestamp) {
|
if (last_active < device_presence.timestamp) {
|
||||||
last_active = device_presence.timestamp;
|
last_active = device_presence.timestamp;
|
||||||
}
|
}
|
||||||
if (is_mobile(device)) {
|
|
||||||
mobileAvailable = device_presence.pushable || mobileAvailable;
|
|
||||||
}
|
|
||||||
if (age < OFFLINE_THRESHOLD_SECS) {
|
if (age < OFFLINE_THRESHOLD_SECS) {
|
||||||
switch (device_presence.status) {
|
switch (device_presence.status) {
|
||||||
case 'active':
|
case 'active':
|
||||||
if (is_mobile(device)) {
|
|
||||||
mobileAvailable = true;
|
|
||||||
} else {
|
|
||||||
nonmobileAvailable = true;
|
|
||||||
}
|
|
||||||
status = device_presence.status;
|
status = device_presence.status;
|
||||||
break;
|
break;
|
||||||
case 'idle':
|
case 'idle':
|
||||||
@@ -85,7 +70,6 @@ function status_from_timestamp(baseline_time, info) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return {status: status,
|
return {status: status,
|
||||||
mobile: !nonmobileAvailable && mobileAvailable,
|
|
||||||
last_active: last_active };
|
last_active: last_active };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +137,6 @@ exports.update_info_for_small_realm = function () {
|
|||||||
|
|
||||||
exports.presence_info[user_id] = {
|
exports.presence_info[user_id] = {
|
||||||
status: status,
|
status: status,
|
||||||
mobile: false,
|
|
||||||
last_active: undefined,
|
last_active: undefined,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user