Include default templates, split "room"
The "room" template has been split into two seperate templates― "join_room" and "create_room". Before, "room" was used in the room creation window, but now that's delegated to "create_room". "join_room" is used with the join window― so now, the add-on has total control over the slots used to join/create rooms generally, if they specify the templates. Even a "/join" command could be overriden by the add-on. Also, default templates are now in use. Rather than add-ons being required to specify templates, there are sensible defaults included with Cardie for each one.
This commit is contained in:
parent
23bee9b0a6
commit
c0f126206a
|
@ -226,8 +226,8 @@ enum im_what_code {
|
|||
/*! Create a room →Protocol
|
||||
The required slots for this message are completely determined by the
|
||||
protocol itself― the protocol will just receive data from the
|
||||
"room" template (which is fetched via
|
||||
ChatProtocol::SettingsTemplate("room") */
|
||||
"create_room" template (which is fetched via
|
||||
ChatProtocol::SettingsTemplate("create_room") */
|
||||
IM_CREATE_ROOM = 152,
|
||||
|
||||
/*! Inform App room was created →App
|
||||
|
@ -236,7 +236,8 @@ enum im_what_code {
|
|||
IM_ROOM_CREATED = 153,
|
||||
|
||||
/*! Join a room →Protocol
|
||||
Requires: String "chat_id" */
|
||||
The required slots for this message are completely determined by the
|
||||
protocol itself― like IM_CREATE_ROOM― with the "join_room" template. */
|
||||
IM_JOIN_ROOM = 154,
|
||||
|
||||
/*! Confirm the room's been joined →App
|
||||
|
@ -308,6 +309,11 @@ enum im_what_code {
|
|||
The idea is that all other metadata-related messages should only be
|
||||
called either from a request, or from a change.
|
||||
This shouldn't be sent automatically upon joining a room.
|
||||
|
||||
Recommendations on default room flags: Unless your protocol has remote
|
||||
logs, ROOM_LOG_LOCALLY and ROOM_POPULATE_LOGS should be enabled; and for
|
||||
multi-user rooms, ROOM_AUTOJOIN should be enabled by default (again,
|
||||
unless the protocol manages auto-joins).
|
||||
Requires: String "chat_id"
|
||||
Allows: String "chat_name", String "subject",
|
||||
int32 "room_default_flags", int32 "room_disallowed_flags" */
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "ChatProtocol.h"
|
||||
#include "ChatProtocolAddOn.h"
|
||||
#include "Utils.h"
|
||||
|
||||
|
||||
const float kDividerWidth = 1.0f;
|
||||
|
@ -40,6 +41,15 @@ ProtocolTemplate::ProtocolTemplate(ChatProtocol* protocol, const char* type)
|
|||
{
|
||||
// Load protocol's settings template
|
||||
BMessage settingsTemplate = fProtocol->SettingsTemplate(type);
|
||||
if (settingsTemplate.IsEmpty() == true) {
|
||||
size_t size;
|
||||
const void* buff =
|
||||
ChatResources()->LoadResource(B_MESSAGE_TYPE, type, &size);
|
||||
|
||||
if (buff != NULL)
|
||||
settingsTemplate.Unflatten((const char*)buff);
|
||||
}
|
||||
|
||||
*fTemplate = settingsTemplate;
|
||||
}
|
||||
|
||||
|
|
|
@ -123,26 +123,17 @@ MainWindow::MessageReceived(BMessage* message)
|
|||
createMsg->AddInt32("im_what", IM_CREATE_ROOM);
|
||||
|
||||
TemplateWindow* win = new TemplateWindow("Create room",
|
||||
"room", createMsg, fServer);
|
||||
"create_room", createMsg, fServer);
|
||||
win->Show();
|
||||
break;
|
||||
}
|
||||
case APP_JOIN_ROOM:
|
||||
{
|
||||
BMessage temp;
|
||||
BMessage roomId;
|
||||
roomId.AddString("name", "chat_id");
|
||||
roomId.AddString("description", "Room ID:");
|
||||
roomId.AddString("error", "You can't join an addressless room! "
|
||||
"Please enter a valid room ID.");
|
||||
roomId.AddInt32("type", 'CSTR');
|
||||
temp.AddMessage("setting", &roomId);
|
||||
|
||||
BMessage* joinMsg = new BMessage(IM_MESSAGE);
|
||||
joinMsg->AddInt32("im_what", IM_JOIN_ROOM);
|
||||
|
||||
TemplateWindow* win = new TemplateWindow("Join a room",
|
||||
new ProtocolTemplate(temp), joinMsg, fServer);
|
||||
"join_room", joinMsg, fServer);
|
||||
win->Show();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,40 @@
|
|||
#include "Flags.h"
|
||||
|
||||
// Default templates
|
||||
resource(1001, "roster") message('IMst')
|
||||
{
|
||||
"setting" = message
|
||||
{
|
||||
"name" = "user_id",
|
||||
"description" = "Username:",
|
||||
"error" = "You can't friend someone without a username.",
|
||||
int32 "type" = 'CSTR'
|
||||
}
|
||||
};
|
||||
|
||||
resource(1002, "create_room") message('IMst')
|
||||
{
|
||||
"setting" = message
|
||||
{
|
||||
"name" = "chat_id",
|
||||
"description" = "Room:",
|
||||
"error" = "You can't quite seem to find ' ' on the map.",
|
||||
int32 "type" = 'CSTR'
|
||||
}
|
||||
};
|
||||
|
||||
resource(1003, "join_room") message('IMst')
|
||||
{
|
||||
"setting" = message
|
||||
{
|
||||
"name" = "chat_id",
|
||||
"description" = "Room:",
|
||||
"error" = "You can't quite seem to find ' ' on the map.",
|
||||
int32 "type" = 'CSTR'
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// User pop-up menu items
|
||||
resource(1100) message
|
||||
{
|
||||
|
@ -173,3 +208,6 @@ resource(1148) message
|
|||
bool "_proto" = true,
|
||||
int32 "_argtype" = 1128362608
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -46,25 +46,3 @@ resource(1000, "account") message('IMst')
|
|||
int32 "type" = 'LONG'
|
||||
}
|
||||
};
|
||||
|
||||
resource(1001, "roster") message('IMst')
|
||||
{
|
||||
"setting" = message
|
||||
{
|
||||
"name" = "user_id",
|
||||
"description" = "Nickname:",
|
||||
"error" = "You can't friend someone without a nick.",
|
||||
int32 "type" = 'CSTR'
|
||||
}
|
||||
};
|
||||
|
||||
resource(1002, "room") message('IMst')
|
||||
{
|
||||
"setting" = message
|
||||
{
|
||||
"name" = "room_id",
|
||||
"description" = "Room:",
|
||||
"error" = "You can't friend someone without a nick.",
|
||||
int32 "type" = 'CSTR'
|
||||
}
|
||||
};
|
||||
|
|
|
@ -197,18 +197,7 @@ PurpleApp::ImMessage(BMessage* msg)
|
|||
}
|
||||
case IM_JOIN_ROOM:
|
||||
{
|
||||
PurpleConnection* conn = _ConnectionFromMessage(msg);
|
||||
BString chat_id = msg->FindString("chat_id");
|
||||
if (conn == NULL || chat_id.IsEmpty() == true) break;
|
||||
|
||||
PurplePluginProtocolInfo* info =
|
||||
PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(conn));
|
||||
|
||||
if (info->chat_info_defaults != NULL) {
|
||||
GHashTable* hash = info->chat_info_defaults(conn,
|
||||
chat_id.String());
|
||||
serv_join_chat(conn, hash);
|
||||
}
|
||||
serv_join_chat(_ConnectionFromMessage(msg), _ParseRoomTemplate(msg));
|
||||
break;
|
||||
}
|
||||
case IM_LEAVE_ROOM:
|
||||
|
|
|
@ -216,7 +216,7 @@ PurpleProtocol::SettingsTemplate(const char* name)
|
|||
return _RosterTemplate();
|
||||
else if (strcmp(name, "account") == 0)
|
||||
fTemplates.FindMessage("account", &temp);
|
||||
else if (strcmp(name, "room") == 0 || strcmp(name, "join") == 0)
|
||||
else if (strcmp(name, "create_room") == 0 || strcmp(name, "join_room") == 0)
|
||||
fTemplates.FindMessage("room", &temp);
|
||||
return temp;
|
||||
}
|
||||
|
|
|
@ -1264,7 +1264,7 @@ JabberHandler::_RoomTemplate()
|
|||
BMessage roomIdentifier;
|
||||
roomIdentifier.AddString("name", "chat_id");
|
||||
roomIdentifier.AddString("description", "Room ID:");
|
||||
roomIdentifier.AddString("error", "You can't create a room without a JID!\n"
|
||||
roomIdentifier.AddString("error", "You can't have a room without a JID!\n"
|
||||
"Use the \"name@server\" format.");
|
||||
roomIdentifier.AddInt32("type", 'CSTR');
|
||||
stemplate.AddMessage("setting", &roomIdentifier);
|
||||
|
|
|
@ -48,11 +48,11 @@ JabberProtocol::Icon() const
|
|||
BMessage
|
||||
JabberProtocol::SettingsTemplate(const char* name)
|
||||
{
|
||||
if (name == BString("account"))
|
||||
if (strcmp(name, "account") == 0)
|
||||
return JabberHandler::_SettingsTemplate("Jabber identifier:", true);
|
||||
if (name == BString("room"))
|
||||
if (strcmp(name, "join_room") == 0 || strcmp(name, "create_room") == 0)
|
||||
return JabberHandler::_RoomTemplate();
|
||||
if (name == BString("roster"))
|
||||
if (strcmp(name, "roster") == 0)
|
||||
return JabberHandler::_RosterTemplate();
|
||||
else
|
||||
return BMessage();
|
||||
|
|
Ŝarĝante…
Reference in New Issue