0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-26 02:18:53 +02:00

ircd:Ⓜ️ Query range of messages user is presently engaged in reading.

This commit is contained in:
Jason Volk 2021-01-24 22:40:11 -08:00
parent 2d0a565ede
commit 744744f88a
4 changed files with 133 additions and 0 deletions

View file

@ -0,0 +1,39 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2021 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_M_USER_READING_H
struct ircd::m::user::reading
{
/// The user is currently viewing this room (any device).
id::room::buf room_id;
/// The user hasn't seen events later than this in the room (m.read)
id::event::buf last;
/// The client claims the user saw `last` at this time.
milliseconds last_ts {0ms};
/// The client reported `last` at this time.
milliseconds last_ots {0ms};
/// The user has fully read up to this event (m.fully_read)
id::event::buf full;
/// The client reported `full` at this time
milliseconds full_ots {0ms};
/// User is currently_active.
bool currently_active {false};
reading(const user &);
reading() = default;
};

View file

@ -51,6 +51,7 @@ struct ircd::m::user
struct notifications;
struct tokens;
struct devices;
struct reading;
using id = m::id::user;
using closure = std::function<void (const user &)>;
@ -100,3 +101,4 @@ const
#include "notifications.h"
#include "tokens.h"
#include "devices.h"
#include "reading.h"

View file

@ -14,6 +14,64 @@ namespace ircd::m
static room create_user_room(const user::id &, const room::id &, const json::members &contents);
}
ircd::m::user::reading::reading(const user &user)
{
if(!(room_id = viewing(user)))
return;
const user::room user_room
{
user
};
const auto last_event_idx
{
user_room.get(std::nothrow, "ircd.read", room_id)
};
const bool last_content_prefetched
{
prefetch(last_event_idx, "content")
};
time_t last_ots {0};
get<time_t>(last_event_idx, "origin_server_ts", last_ots);
this->last_ots = milliseconds(last_ots) / 1000;
get(std::nothrow, last_event_idx, "content", [this]
(const json::object &content)
{
this->last_ts = content.get<milliseconds>("ts");
this->last = json::string
{
content["event_id"]
};
});
const user::room_account_data room_account_data
{
user, room_id
};
room_account_data.get(std::nothrow, "m.fully_read", [this]
(const string_view &key, const json::object &content)
{
this->full = json::string
{
content["event_id"]
};
});
//TODO: XXX
// full_ots
presence::get(std::nothrow, user, [this]
(const json::object &event)
{
this->currently_active = event.get<bool>("currently_active", false);
});
}
ircd::m::room::id::buf
ircd::m::viewing(const user &user,
size_t i)

View file

@ -13567,6 +13567,40 @@ console_cmd__user__viewing(opt &out, const string_view &line)
return true;
}
bool
console_cmd__user__reading(opt &out, const string_view &line)
{
const params param{line, " ",
{
"user_id"
}};
const m::user::id user_id
{
param.at("user_id")
};
const m::user::reading r
{
user_id
};
out
<< r.room_id
<< " "
<< r.last
<< " "
<< r.last_ts
<< " "
<< r.full
<< " "
<< r.full_ots
<< " "
<< (r.currently_active? "active"_sv: "inactive"_sv)
<< std::endl;
return true;
}
bool
console_cmd__user__pushrules(opt &out, const string_view &line)
{