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++)
|
for (i = 0; i < ArraySize(chats); i++)
|
||||||
{
|
{
|
||||||
DbRef *ref;
|
DbRef *ref;
|
||||||
HashMap *json, *stanzas;
|
HashMap *json, *stanzas, *events, *ids;
|
||||||
char *stanza;
|
char *stanza, *event, *id;
|
||||||
JsonValue *val;
|
JsonValue *val;
|
||||||
Array *to_delete;
|
Array *to_delete;
|
||||||
size_t j;
|
size_t j;
|
||||||
|
|
@ -75,27 +75,36 @@ ParseeCleanup(void *datp)
|
||||||
chat = ArrayGet(chats, i);
|
chat = ArrayGet(chats, i);
|
||||||
ref = DbLock(data->db, 2, "chats", chat);
|
ref = DbLock(data->db, 2, "chats", chat);
|
||||||
json = DbJson(ref);
|
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)))
|
#define CleanupField(field, timeout) do \
|
||||||
{
|
{ \
|
||||||
ArrayAdd(to_delete, StrDuplicate(stanza));
|
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++)
|
CleanupField(stanza, 5 MINUTES);
|
||||||
{
|
CleanupField(event, 5 MINUTES);
|
||||||
stanza = ArrayGet(to_delete, j);
|
CleanupField(id, 5 MINUTES);
|
||||||
JsonValueFree(HashMapDelete(stanzas, stanza));
|
|
||||||
Free(stanza);
|
|
||||||
}
|
|
||||||
ArrayFree(to_delete);
|
|
||||||
|
|
||||||
DbUnlock(data->db, ref);
|
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, "stanza", JsonValueString(stanza_id));
|
||||||
HashMapSet(obj, "origin", JsonValueString(id));
|
HashMapSet(obj, "origin", JsonValueString(id));
|
||||||
HashMapSet(obj, "sender", JsonValueString(sender));
|
HashMapSet(obj, "sender", JsonValueString(sender));
|
||||||
|
HashMapSet(obj, "age", JsonValueInteger(age));
|
||||||
JsonValueFree(HashMapSet(events, ev, JsonValueObject(obj)));
|
JsonValueFree(HashMapSet(events, ev, JsonValueObject(obj)));
|
||||||
if (new_events)
|
if (new_events)
|
||||||
{
|
{
|
||||||
|
|
@ -402,6 +412,8 @@ ParseePushStanza(ParseeData *data, char *chat_id, char *stanza_id, char *id, cha
|
||||||
obj = HashMapCreate();
|
obj = HashMapCreate();
|
||||||
HashMapSet(obj, "stanza", JsonValueString(stanza_id));
|
HashMapSet(obj, "stanza", JsonValueString(stanza_id));
|
||||||
HashMapSet(obj, "event", JsonValueString(ev));
|
HashMapSet(obj, "event", JsonValueString(ev));
|
||||||
|
HashMapSet(obj, "sender", JsonValueString(sender));
|
||||||
|
HashMapSet(obj, "age", JsonValueInteger(age));
|
||||||
JsonValueFree(HashMapSet(ids, id, JsonValueObject(obj)));
|
JsonValueFree(HashMapSet(ids, id, JsonValueObject(obj)));
|
||||||
if (new_ids)
|
if (new_ids)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,6 @@ MessageStanza(ParseeData *args, XMLElement *stanza)
|
||||||
else if (replaced)
|
else if (replaced)
|
||||||
{
|
{
|
||||||
event_id = ParseeEventFromID(args, chat_id, replaced);
|
event_id = ParseeEventFromID(args, chat_id, replaced);
|
||||||
Log(LOG_WARNING, "RETRACTION REQUEST TO %s->%s", replaced, event_id);
|
|
||||||
Free(ASSend(
|
Free(ASSend(
|
||||||
args->config, mroom_id, encoded,
|
args->config, mroom_id, encoded,
|
||||||
"m.room.message", MatrixCreateReplace(event_id, data->data)
|
"m.room.message", MatrixCreateReplace(event_id, data->data)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue