presence: Add user_id to presence event.

In a later commit, we will eliminate email for
clients who have set slim_presence as their
preference.
This commit is contained in:
Steve Howell 2020-02-03 15:25:13 +00:00 committed by Tim Abbott
parent 36aee9e69c
commit a672a00677
7 changed files with 13 additions and 23 deletions

View File

@ -798,24 +798,16 @@ run_test('update_presence_info', () => {
};
presence.presence_info[me.user_id] = undefined;
activity.update_presence_info(me.email, info, server_time);
activity.update_presence_info(me.user_id, info, server_time);
assert(inserted);
assert.deepEqual(presence.presence_info[me.user_id].status, 'active');
presence.presence_info[alice.user_id] = undefined;
activity.update_presence_info(alice.email, info, server_time);
activity.update_presence_info(alice.user_id, info, server_time);
assert(inserted);
const expected = { status: 'active', mobile: false, last_active: 500 };
assert.deepEqual(presence.presence_info[alice.user_id], expected);
activity.update_presence_info(alice.email, info, server_time);
blueslip.set_test_data('warn', 'unknown email: foo@bar.com');
blueslip.set_test_data('error', 'Unknown email for get_user_id: foo@bar.com');
activity.update_presence_info('foo@bar.com', info, server_time);
assert.equal(blueslip.get_test_logs('warn').length, 1);
assert.equal(blueslip.get_test_logs('error').length, 1);
blueslip.clear_test_data();
});
run_test('initialize', () => {

View File

@ -169,6 +169,7 @@ const event_fixtures = {
presence: {
type: 'presence',
email: 'alice@example.com',
user_id: 42,
presence: {
client_name: 'electron',
is_mirror_dummy: false,
@ -856,8 +857,8 @@ with_overrides(function (override) {
global.with_stub(function (stub) {
override('activity.update_presence_info', stub.f);
dispatch(event);
const args = stub.get_args('email', 'presence', 'server_time');
assert_same(args.email, 'alice@example.com');
const args = stub.get_args('user_id', 'presence', 'server_time');
assert_same(args.user_id, event.user_id);
assert_same(args.presence, event.presence);
assert_same(args.server_time, event.server_timestamp);
});

View File

@ -380,13 +380,7 @@ exports.initialize = function () {
setInterval(get_full_presence_list_update, ACTIVE_PING_INTERVAL_MS);
};
exports.update_presence_info = function (email, info, server_time) {
const user_id = people.get_user_id(email);
if (!user_id) {
blueslip.warn('unknown email: ' + email);
return;
}
exports.update_presence_info = function (user_id, info, server_time) {
presence.set_info_for_user(user_id, info, server_time);
exports.redraw_user(user_id);
exports.update_huddles();

View File

@ -56,7 +56,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
break;
case 'presence':
activity.update_presence_info(event.email, event.presence, event.server_timestamp);
activity.update_presence_info(event.user_id, event.presence, event.server_timestamp);
break;
case 'restart': {

View File

@ -4000,7 +4000,9 @@ def do_update_user_activity(user_profile_id: int,
def send_presence_changed(user_profile: UserProfile, presence: UserPresence) -> None:
presence_dict = presence.to_dict()
event = dict(type="presence", email=user_profile.email,
event = dict(type="presence",
email=user_profile.email,
user_id=user_profile.id,
server_timestamp=time.time(),
presence={presence_dict['client']: presence_dict})
send_event(user_profile.realm, event, active_user_ids(user_profile.realm_id))

View File

@ -606,10 +606,9 @@ def apply_event(state: Dict[str, Any],
user_id in sub['subscribers']):
sub['subscribers'].remove(user_id)
elif event['type'] == "presence":
# TODO: Add user_id to presence update events / state format!
presence_user_profile = get_user(event['email'], user_profile.realm)
if slim_presence:
user_key = str(presence_user_profile.id)
user_key = str(event['user_id'])
else:
user_key = event['email']
state['presences'][user_key] = UserPresence.get_status_dict_by_user(

View File

@ -1190,6 +1190,7 @@ class EventsRegisterTest(ZulipTestCase):
schema_checker = self.check_events_dict([
('type', equals('presence')),
('email', check_string),
('user_id', check_int),
('server_timestamp', check_float),
('presence', check_dict_only([
('website', check_dict_only([
@ -1219,6 +1220,7 @@ class EventsRegisterTest(ZulipTestCase):
schema_checker_android = self.check_events_dict([
('type', equals('presence')),
('email', check_string),
('user_id', check_int),
('server_timestamp', check_float),
('presence', check_dict_only([
('ZulipAndroid/1.0', check_dict_only([