about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-04-10 22:47:01 +0100
committerJames Booth <boothj5@gmail.com>2013-04-10 22:47:01 +0100
commit202bc6b427c05f2ec06ef984848f05bfea78b42d (patch)
tree2e6ee3a1b8d2f530b6c7fc4200e96b776bb536ae /src/command
parentf4041f049ce4f66ad6fa9ef167e0a095b35d9f60 (diff)
downloadprofani-tty-202bc6b427c05f2ec06ef984848f05bfea78b42d.tar.gz
Guess conference server if not supplied when joining room (/join)
"@conference.<domain-part>" will be appended to the /join argument where
<domain-part> is the domainpart of the users jid. E.g. the user
"user@server.org" typing "/join chatroom" is equivalent to "/join
chatroom@conference.server.org"
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 58b241f1..d3279a01 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -324,16 +324,18 @@ static struct cmd_t main_commands[] =
 
     { "/join",
         _cmd_join, parse_args_with_freetext, 1, 2,
-        { "/join room [nick]", "Join a chat room.",
-        { "/join room [nick]",
-          "-----------------",
+        { "/join room[@server] [nick]", "Join a chat room.",
+        { "/join room[@server] [nick]",
+          "--------------------------",
           "Join a chat room at the conference server.",
           "If nick is specified you will join with this nickname.",
           "Otherwise the 'localpart' of your JID (before the @) will be used.",
+          "If no server is supplied, it will default to 'conference.<domain-part>'",
           "If the room doesn't exist, and the server allows it, a new one will be created.",
           "",
           "Example : /join jdev@conference.jabber.org",
           "Example : /join jdev@conference.jabber.org mynick",
+          "Example : /join jdev (as user@jabber.org will join jdev@conference.jabber.org)",
           NULL } } },
 
     { "/rooms",
@@ -2078,16 +2080,32 @@ _cmd_join(gchar **args, struct cmd_help_t help)
         return TRUE;
     }
 
-    char *room = args[0];
+    int num_args = g_strv_length(args);
+    char *room = NULL;
     char *nick = NULL;
+    Jid *room_arg = jid_create(args[0]);
+    GString *room_str = g_string_new("");
+    Jid *my_jid = jid_create(jabber_get_jid());
 
-    int num_args = g_strv_length(args);
+    // full room jid supplied (room@server)
+    if (room_arg->localpart != NULL) {
+        room = args[0];
+
+    // server not supplied (room), guess conference.<users-domain-part>
+    } else {
+        g_string_append(room_str, args[0]);
+        g_string_append(room_str, "@conference.");
+        g_string_append(room_str, strdup(my_jid->domainpart));
+        room = room_str->str;
+    }
+
+    // nick supplied
     if (num_args == 2) {
         nick = args[1];
+
+    // use localpart for nick
     } else {
-        Jid *jid = jid_create(jabber_get_jid());
-        nick = strdup(jid->localpart);
-        jid_destroy(jid);
+        nick = my_jid->localpart;
     }
 
     Jid *room_jid = jid_create_from_bare_and_resource(room, nick);
@@ -2097,6 +2115,10 @@ _cmd_join(gchar **args, struct cmd_help_t help)
     }
     win_join_chat(room_jid);
 
+    jid_destroy(room_jid);
+    jid_destroy(my_jid);
+    g_string_free(room_str, TRUE);
+
     return TRUE;
 }
 
30 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488