diff --git a/application/ChatProtocolMessages.h b/application/ChatProtocolMessages.h index 06c2dee..9e8e8a8 100644 --- a/application/ChatProtocolMessages.h +++ b/application/ChatProtocolMessages.h @@ -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" */ diff --git a/application/ProtocolTemplate.cpp b/application/ProtocolTemplate.cpp index f8b2f87..2a7c8fb 100644 --- a/application/ProtocolTemplate.cpp +++ b/application/ProtocolTemplate.cpp @@ -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; } diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index 7a697f1..c315a34 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -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; } diff --git a/data/misc/Templates.rdef b/data/misc/Templates.rdef index b370d6b..a1dfddb 100644 --- a/data/misc/Templates.rdef +++ b/data/misc/Templates.rdef @@ -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 }; + + + diff --git a/protocols/irc/Templates.rdef b/protocols/irc/Templates.rdef index 9719663..ce3db1e 100644 --- a/protocols/irc/Templates.rdef +++ b/protocols/irc/Templates.rdef @@ -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' - } -}; diff --git a/protocols/purple/PurpleApp.cpp b/protocols/purple/PurpleApp.cpp index d8e27f1..c2b3d5d 100644 --- a/protocols/purple/PurpleApp.cpp +++ b/protocols/purple/PurpleApp.cpp @@ -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: diff --git a/protocols/purple/PurpleProtocol.cpp b/protocols/purple/PurpleProtocol.cpp index 5320b23..0fe3c06 100644 --- a/protocols/purple/PurpleProtocol.cpp +++ b/protocols/purple/PurpleProtocol.cpp @@ -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; } diff --git a/protocols/xmpp/JabberHandler.cpp b/protocols/xmpp/JabberHandler.cpp index 08e3ad3..c73c5d3 100644 --- a/protocols/xmpp/JabberHandler.cpp +++ b/protocols/xmpp/JabberHandler.cpp @@ -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); diff --git a/protocols/xmpp/JabberProtocol.cpp b/protocols/xmpp/JabberProtocol.cpp index 3e796c1..6881ddc 100644 --- a/protocols/xmpp/JabberProtocol.cpp +++ b/protocols/xmpp/JabberProtocol.cpp @@ -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();