mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 16:55:10 +00:00
[ADD/WIP] Chat settings
Right now, they are currently unused. Extensions, and Parsee itself will be able to use those, though.
This commit is contained in:
parent
55ac682d26
commit
064040c18f
17 changed files with 449 additions and 14 deletions
117
src/XMPPCommands/MUCKV.c
Normal file
117
src/XMPPCommands/MUCKV.c
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
|
||||
#include <Cytoplasm/HashMap.h>
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Json.h>
|
||||
#include <Cytoplasm/Util.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
|
||||
#include <XMPPFormTool.h>
|
||||
#include <XMPPCommand.h>
|
||||
#include <Matrix.h>
|
||||
#include <Parsee.h>
|
||||
#include <XMPP.h>
|
||||
#include <XML.h>
|
||||
#include <AS.h>
|
||||
|
||||
void
|
||||
MUCSetKey(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *out)
|
||||
{
|
||||
ParseeData *data = XMPPGetManagerCookie(m);
|
||||
char *affiliation, *role;
|
||||
char *chat_id;
|
||||
char *muc;
|
||||
|
||||
char *key, *val;
|
||||
|
||||
ParseeLookupAffiliation(from, &affiliation, &role);
|
||||
Free(role);
|
||||
if (!StrEquals(affiliation, "owner"))
|
||||
{
|
||||
SetNote("error", "Setting MUC properties requires the 'owner' affiliation.");
|
||||
Free(affiliation);
|
||||
return;
|
||||
}
|
||||
|
||||
GetFieldValue(key, "key", form);
|
||||
GetFieldValue(val, "val", form);
|
||||
if (!key || !val)
|
||||
{
|
||||
SetNote("error", "No keys or no value given.");
|
||||
goto end;
|
||||
}
|
||||
|
||||
muc = ParseeTrimJID(from);
|
||||
chat_id = ParseeGetFromMUCID(data, muc);
|
||||
ParseeSetChatSetting(data, chat_id, key, val);
|
||||
|
||||
SetNote("info", "Set key-value pair!");
|
||||
end:
|
||||
Free(affiliation);
|
||||
Free(chat_id);
|
||||
Free(muc);
|
||||
(void) form;
|
||||
}
|
||||
void
|
||||
MUCGetKeys(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *out)
|
||||
{
|
||||
ParseeData *data = XMPPGetManagerCookie(m);
|
||||
char *affiliation = NULL, *role = NULL;
|
||||
char *chat_id = NULL;
|
||||
char *muc = NULL;
|
||||
|
||||
XMLElement *x;
|
||||
XMLElement *title;
|
||||
XMLElement *reported, *item, *field, *value, *txt;
|
||||
|
||||
HashMap *settings = NULL;
|
||||
|
||||
ParseeLookupAffiliation(from, &affiliation, &role);
|
||||
Free(role);
|
||||
if (!StrEquals(affiliation, "owner"))
|
||||
{
|
||||
SetNote("error", "Getting MUC roperties requires the 'owner' affiliation.");
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
muc = ParseeTrimJID(from);
|
||||
chat_id = ParseeGetFromMUCID(data, muc);
|
||||
settings = ParseeGetChatSettings(data, chat_id);
|
||||
|
||||
x = XMLCreateTag("x");
|
||||
title = XMLCreateTag("title");
|
||||
|
||||
SetTitle(x, "MUC/room settings");
|
||||
|
||||
XMLAddChild(x, title);
|
||||
|
||||
XMLAddAttr(x, "xmlns", "jabber:x:data");
|
||||
XMLAddAttr(x, "type", "result");
|
||||
{
|
||||
char *key, *val;
|
||||
reported = XMLCreateTag("reported");
|
||||
XMLAddChild(x, reported);
|
||||
|
||||
/* Report */
|
||||
Report("key", "Setting's key");
|
||||
Report("val", "Setting's value");
|
||||
|
||||
/* Set */
|
||||
while (HashMapIterate(settings, &key, (void **) &val))
|
||||
{
|
||||
BeginItem();
|
||||
SetField("key", key);
|
||||
SetField("val", val);
|
||||
EndItem();
|
||||
}
|
||||
}
|
||||
XMLAddChild(out, x);
|
||||
|
||||
end:
|
||||
ParseeFreeChatSettings(settings);
|
||||
Free(affiliation);
|
||||
Free(chat_id);
|
||||
Free(muc);
|
||||
(void) form;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue