mirror of
https://github.com/matrix-construct/construct
synced 2024-07-01 00:08:22 +02:00
modules/client/sync: Sketch various preliminary linear sync handlers.
This commit is contained in:
parent
a263b2ff40
commit
7f57a4c422
|
@ -34,7 +34,14 @@ ircd::m::sync::account_data
|
||||||
bool
|
bool
|
||||||
ircd::m::sync::account_data_linear(data &data)
|
ircd::m::sync::account_data_linear(data &data)
|
||||||
{
|
{
|
||||||
return false;
|
assert(data.event);
|
||||||
|
assert(data.event_idx);
|
||||||
|
json::stack::array array
|
||||||
|
{
|
||||||
|
*data.out, "events"
|
||||||
|
};
|
||||||
|
|
||||||
|
return account_data_(data, *data.event, data.event_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -47,41 +47,75 @@ ircd::m::sync::rooms_linear(data &data)
|
||||||
json::get<"room_id"_>(event)
|
json::get<"room_id"_>(event)
|
||||||
};
|
};
|
||||||
|
|
||||||
const scope_restore<decltype(data.room)> theirs
|
const scope_restore their_room
|
||||||
{
|
{
|
||||||
data.room, &room
|
data.room, &room
|
||||||
};
|
};
|
||||||
|
|
||||||
bool ret{false};
|
char membuf[32];
|
||||||
ret |= _rooms_linear(data, "invite");
|
const string_view &membership
|
||||||
ret |= _rooms_linear(data, "join");
|
|
||||||
ret |= _rooms_linear(data, "leave");
|
|
||||||
ret |= _rooms_linear(data, "ban");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
ircd::m::sync::_rooms_linear(data &data,
|
|
||||||
const string_view &membership)
|
|
||||||
{
|
{
|
||||||
const scope_restore<decltype(data.membership)> theirs
|
data.room->membership(membuf, data.user)
|
||||||
|
};
|
||||||
|
|
||||||
|
if(!membership)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const scope_restore their_membership
|
||||||
{
|
{
|
||||||
data.membership, membership
|
data.membership, membership
|
||||||
};
|
};
|
||||||
|
|
||||||
bool ret{false};
|
const event::idx room_head
|
||||||
|
{
|
||||||
|
head_idx(std::nothrow, *data.room)
|
||||||
|
};
|
||||||
|
|
||||||
|
const scope_restore their_head
|
||||||
|
{
|
||||||
|
data.room_head, room_head
|
||||||
|
};
|
||||||
|
|
||||||
|
json::stack::checkpoint checkpoint
|
||||||
|
{
|
||||||
|
*data.out
|
||||||
|
};
|
||||||
|
|
||||||
|
json::stack::object membership_
|
||||||
|
{
|
||||||
|
*data.out, membership
|
||||||
|
};
|
||||||
|
|
||||||
|
json::stack::object room_
|
||||||
|
{
|
||||||
|
*data.out, data.room->room_id
|
||||||
|
};
|
||||||
|
|
||||||
|
bool ret(false);
|
||||||
m::sync::for_each("rooms", [&data, &ret]
|
m::sync::for_each("rooms", [&data, &ret]
|
||||||
(item &item)
|
(item &item)
|
||||||
{
|
{
|
||||||
|
json::stack::checkpoint checkpoint
|
||||||
|
{
|
||||||
|
*data.out
|
||||||
|
};
|
||||||
|
|
||||||
json::stack::object object
|
json::stack::object object
|
||||||
{
|
{
|
||||||
*data.out, item.member_name()
|
*data.out, item.member_name()
|
||||||
};
|
};
|
||||||
|
|
||||||
ret |= item.linear(data);
|
if(item.linear(data))
|
||||||
return true;
|
ret = true;
|
||||||
|
else
|
||||||
|
checkpoint.rollback();
|
||||||
|
|
||||||
|
return !ret;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(!ret)
|
||||||
|
checkpoint.rollback();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace ircd::m::sync
|
||||||
static bool room_account_data_polylog_events_event(data &, const m::event &);
|
static bool room_account_data_polylog_events_event(data &, const m::event &);
|
||||||
static bool room_account_data_polylog_events(data &);
|
static bool room_account_data_polylog_events(data &);
|
||||||
static bool room_account_data_polylog(data &);
|
static bool room_account_data_polylog(data &);
|
||||||
|
static bool room_account_data_linear(data &);
|
||||||
|
|
||||||
extern item room_account_data;
|
extern item room_account_data;
|
||||||
}
|
}
|
||||||
|
@ -27,9 +28,16 @@ decltype(ircd::m::sync::room_account_data)
|
||||||
ircd::m::sync::room_account_data
|
ircd::m::sync::room_account_data
|
||||||
{
|
{
|
||||||
"rooms.account_data",
|
"rooms.account_data",
|
||||||
room_account_data_polylog
|
room_account_data_polylog,
|
||||||
|
room_account_data_linear
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::sync::room_account_data_linear(data &data)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::m::sync::room_account_data_polylog(data &data)
|
ircd::m::sync::room_account_data_polylog(data &data)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,7 +33,33 @@ ircd::m::sync::rooms_ephemeral
|
||||||
bool
|
bool
|
||||||
ircd::m::sync::rooms_ephemeral_linear(data &data)
|
ircd::m::sync::rooms_ephemeral_linear(data &data)
|
||||||
{
|
{
|
||||||
|
assert(data.event);
|
||||||
|
if(json::get<"event_id"_>(*data.event))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
json::stack::array array
|
||||||
|
{
|
||||||
|
*data.out, "events"
|
||||||
|
};
|
||||||
|
|
||||||
|
bool ret{false};
|
||||||
|
m::sync::for_each("rooms.ephemeral", [&data, &ret]
|
||||||
|
(item &item)
|
||||||
|
{
|
||||||
|
json::stack::checkpoint checkpoint
|
||||||
|
{
|
||||||
|
*data.out
|
||||||
|
};
|
||||||
|
|
||||||
|
if(item.linear(data))
|
||||||
|
ret = true;
|
||||||
|
else
|
||||||
|
checkpoint.rollback();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace ircd::m::sync
|
||||||
static bool _handle_message_receipt(data &, const m::event &);
|
static bool _handle_message_receipt(data &, const m::event &);
|
||||||
static bool _handle_message(data &, const m::event::idx &);
|
static bool _handle_message(data &, const m::event::idx &);
|
||||||
static bool room_ephemeral_m_receipt_m_read_polylog(data &);
|
static bool room_ephemeral_m_receipt_m_read_polylog(data &);
|
||||||
|
static bool room_ephemeral_m_receipt_m_read_linear(data &);
|
||||||
extern item room_ephemeral_m_receipt_m_read;
|
extern item room_ephemeral_m_receipt_m_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,9 +27,21 @@ decltype(ircd::m::sync::room_ephemeral_m_receipt_m_read)
|
||||||
ircd::m::sync::room_ephemeral_m_receipt_m_read
|
ircd::m::sync::room_ephemeral_m_receipt_m_read
|
||||||
{
|
{
|
||||||
"rooms.ephemeral.m_receipt",
|
"rooms.ephemeral.m_receipt",
|
||||||
room_ephemeral_m_receipt_m_read_polylog
|
room_ephemeral_m_receipt_m_read_polylog,
|
||||||
|
room_ephemeral_m_receipt_m_read_linear
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::sync::room_ephemeral_m_receipt_m_read_linear(data &data)
|
||||||
|
{
|
||||||
|
assert(data.event);
|
||||||
|
if(json::get<"type"_>(*data.event) != "m.receipt")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_handle_message_receipt(data, *data.event);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::m::sync::room_ephemeral_m_receipt_m_read_polylog(data &data)
|
ircd::m::sync::room_ephemeral_m_receipt_m_read_polylog(data &data)
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,17 +63,16 @@ bool
|
||||||
ircd::m::sync::room_state_linear(data &data)
|
ircd::m::sync::room_state_linear(data &data)
|
||||||
{
|
{
|
||||||
assert(data.event);
|
assert(data.event);
|
||||||
assert(data.room);
|
|
||||||
assert(json::get<"room_id"_>(*data.event));
|
|
||||||
|
|
||||||
if(!json::get<"state_key"_>(*data.event))
|
if(!json::get<"state_key"_>(*data.event))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!data.room->membership(data.user, data.membership))
|
json::stack::array array
|
||||||
return false;
|
{
|
||||||
|
*data.out, "events"
|
||||||
|
};
|
||||||
|
|
||||||
//data.array->append(*data.event);
|
array.append(*data.event);
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -19,7 +19,6 @@ namespace ircd::m::sync
|
||||||
static event::id::buf _room_timeline_polylog_events(data &, const m::room &, bool &, bool &);
|
static event::id::buf _room_timeline_polylog_events(data &, const m::room &, bool &, bool &);
|
||||||
static bool room_timeline_polylog(data &);
|
static bool room_timeline_polylog(data &);
|
||||||
|
|
||||||
static event::id::buf _room_timeline_linear_events(data &, const m::room &, bool &);
|
|
||||||
static bool room_timeline_linear(data &);
|
static bool room_timeline_linear(data &);
|
||||||
|
|
||||||
extern const event::keys::include default_keys;
|
extern const event::keys::include default_keys;
|
||||||
|
@ -52,46 +51,17 @@ ircd::m::sync::default_keys
|
||||||
bool
|
bool
|
||||||
ircd::m::sync::room_timeline_linear(data &data)
|
ircd::m::sync::room_timeline_linear(data &data)
|
||||||
{
|
{
|
||||||
json::stack::object object
|
assert(data.event);
|
||||||
{
|
if(!json::get<"event_id"_>(*data.event))
|
||||||
*data.out
|
|
||||||
};
|
|
||||||
|
|
||||||
m::room room;
|
|
||||||
|
|
||||||
// events
|
|
||||||
bool limited{false};
|
|
||||||
m::event::id::buf prev
|
|
||||||
{
|
|
||||||
_room_timeline_linear_events(data, room, limited)
|
|
||||||
};
|
|
||||||
|
|
||||||
// prev_batch
|
|
||||||
json::stack::member
|
|
||||||
{
|
|
||||||
object, "prev_batch", string_view{prev}
|
|
||||||
};
|
|
||||||
|
|
||||||
// limited
|
|
||||||
json::stack::member
|
|
||||||
{
|
|
||||||
object, "limited", json::value{limited}
|
|
||||||
};
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
ircd::m::event::id::buf
|
|
||||||
ircd::m::sync::_room_timeline_linear_events(data &data,
|
|
||||||
const m::room &room,
|
|
||||||
bool &limited)
|
|
||||||
{
|
|
||||||
json::stack::array array
|
json::stack::array array
|
||||||
{
|
{
|
||||||
*data.out, "events"
|
*data.out, "events"
|
||||||
};
|
};
|
||||||
|
|
||||||
return {};
|
array.append(*data.event);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -34,7 +34,39 @@ ircd::m::sync::room_unread_notifications
|
||||||
bool
|
bool
|
||||||
ircd::m::sync::room_unread_notifications_linear(data &data)
|
ircd::m::sync::room_unread_notifications_linear(data &data)
|
||||||
{
|
{
|
||||||
|
assert(data.event);
|
||||||
|
if(!json::get<"event_id"_>(*data.event))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
const auto &room{*data.room};
|
||||||
|
m::event::id::buf last_read;
|
||||||
|
if(!m::receipt::read(last_read, room.room_id, data.user))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const auto start_idx
|
||||||
|
{
|
||||||
|
index(last_read)
|
||||||
|
};
|
||||||
|
|
||||||
|
// highlight_count
|
||||||
|
json::stack::member
|
||||||
|
{
|
||||||
|
*data.out, "highlight_count", json::value
|
||||||
|
{
|
||||||
|
_highlight_count(room, data.user, start_idx, data.range.second)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// notification_count
|
||||||
|
json::stack::member
|
||||||
|
{
|
||||||
|
*data.out, "notification_count", json::value
|
||||||
|
{
|
||||||
|
_notification_count(room, start_idx, data.range.second)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
Loading…
Reference in a new issue