mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 17:05:11 +00:00
[ADD] Start cleaning up more
Yeah. Let's clean up a bit more.
This commit is contained in:
parent
2b0ffe6ae1
commit
de1ee3986e
2 changed files with 34 additions and 23 deletions
|
|
@ -66,8 +66,8 @@ ParseeCleanup(void *datp)
|
|||
for (i = 0; i < ArraySize(chats); i++)
|
||||
{
|
||||
DbRef *ref;
|
||||
HashMap *json, *stanzas;
|
||||
char *stanza;
|
||||
HashMap *json, *stanzas, *events, *ids;
|
||||
char *stanza, *event, *id;
|
||||
JsonValue *val;
|
||||
Array *to_delete;
|
||||
size_t j;
|
||||
|
|
@ -75,27 +75,36 @@ ParseeCleanup(void *datp)
|
|||
chat = ArrayGet(chats, i);
|
||||
ref = DbLock(data->db, 2, "chats", chat);
|
||||
json = DbJson(ref);
|
||||
stanzas = JsonValueAsObject(HashMapGet(json, "stanzas"));
|
||||
to_delete = ArrayCreate();
|
||||
while (HashMapIterate(stanzas, &stanza, (void **) &val))
|
||||
{
|
||||
HashMap *obj = JsonValueAsObject(val);
|
||||
uint64_t age = JsonValueAsInteger(HashMapGet(obj, "age"));
|
||||
uint64_t dur = ts - age;
|
||||
|
||||
if ((dur > (30 MINUTES)))
|
||||
{
|
||||
ArrayAdd(to_delete, StrDuplicate(stanza));
|
||||
}
|
||||
}
|
||||
#define CleanupField(field, timeout) do \
|
||||
{ \
|
||||
field##s = JsonValueAsObject(HashMapGet(json, #field"s")); \
|
||||
to_delete = ArrayCreate(); \
|
||||
while (HashMapIterate(field##s, &field, (void **) &val)) \
|
||||
{ \
|
||||
HashMap *obj = JsonValueAsObject(val); \
|
||||
uint64_t age = JsonValueAsInteger(HashMapGet(obj, "age")); \
|
||||
uint64_t dur = ts - age; \
|
||||
\
|
||||
if ((dur > (timeout))) \
|
||||
{ \
|
||||
ArrayAdd(to_delete, StrDuplicate(field)); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
for (j = 0; j < ArraySize(to_delete); j++) \
|
||||
{ \
|
||||
field = ArrayGet(to_delete, j); \
|
||||
JsonValueFree(HashMapDelete(field##s, field)); \
|
||||
Free(field); \
|
||||
} \
|
||||
ArrayFree(to_delete); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
for (j = 0; j < ArraySize(to_delete); j++)
|
||||
{
|
||||
stanza = ArrayGet(to_delete, j);
|
||||
JsonValueFree(HashMapDelete(stanzas, stanza));
|
||||
Free(stanza);
|
||||
}
|
||||
ArrayFree(to_delete);
|
||||
CleanupField(stanza, 5 MINUTES);
|
||||
CleanupField(event, 5 MINUTES);
|
||||
CleanupField(id, 5 MINUTES);
|
||||
|
||||
DbUnlock(data->db, ref);
|
||||
}
|
||||
|
|
@ -385,6 +394,7 @@ ParseePushStanza(ParseeData *data, char *chat_id, char *stanza_id, char *id, cha
|
|||
HashMapSet(obj, "stanza", JsonValueString(stanza_id));
|
||||
HashMapSet(obj, "origin", JsonValueString(id));
|
||||
HashMapSet(obj, "sender", JsonValueString(sender));
|
||||
HashMapSet(obj, "age", JsonValueInteger(age));
|
||||
JsonValueFree(HashMapSet(events, ev, JsonValueObject(obj)));
|
||||
if (new_events)
|
||||
{
|
||||
|
|
@ -402,6 +412,8 @@ ParseePushStanza(ParseeData *data, char *chat_id, char *stanza_id, char *id, cha
|
|||
obj = HashMapCreate();
|
||||
HashMapSet(obj, "stanza", JsonValueString(stanza_id));
|
||||
HashMapSet(obj, "event", JsonValueString(ev));
|
||||
HashMapSet(obj, "sender", JsonValueString(sender));
|
||||
HashMapSet(obj, "age", JsonValueInteger(age));
|
||||
JsonValueFree(HashMapSet(ids, id, JsonValueObject(obj)));
|
||||
if (new_ids)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -115,7 +115,6 @@ MessageStanza(ParseeData *args, XMLElement *stanza)
|
|||
else if (replaced)
|
||||
{
|
||||
event_id = ParseeEventFromID(args, chat_id, replaced);
|
||||
Log(LOG_WARNING, "RETRACTION REQUEST TO %s->%s", replaced, event_id);
|
||||
Free(ASSend(
|
||||
args->config, mroom_id, encoded,
|
||||
"m.room.message", MatrixCreateReplace(event_id, data->data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue