Skip to content
Permalink
Browse files

Work on bookmarks

- Remove "channels" menu and instead list group chats in the roster view
- Allow joining a group chat by double ckicking on it in the roster
- Support for bookmarks2 (XEP-0402). XEP-0048 is also implemented, but
  currently disabled.
- Joining a group chat adds it to the bookmarks with autojoin enabled,
  unless it is not an user initiated action (for example, someone else
  invited you in a room)
- Leaving a groupchat adds it to the bootkmarks, with autojoin disabled
  (so you can easily access the server-side history for it or join back)
- Bookmarks can be deleted by right click->remove in the Roster.

Fixes #32, #40
  • Loading branch information...
pulkomandy committed Sep 28, 2019
1 parent 8e01949 commit d6cbfe4ad90d860c1af234219af5bd0931c4aba5
@@ -53,10 +53,17 @@ add_executable(Renga
jabber/XMLEntity.cpp
jabber/XMLReader.cpp

# Gloox extras (to be upstreamed, I guess)
network/bob.cpp
network/bookmark2storage.cpp
network/media.cpp

# "Modern" XMPP classes using gloox cleanly and directly
network/BookmarkManager.cpp
network/GlooxHandler.cpp

# "Modern" UI classes using gloox types and StartWatching/SendNotices
ui/BookmarkItem.cpp
ui/RegisterAccountWindow.cpp
)

@@ -85,11 +85,12 @@
</implements>
<implements>
<xmpp:SupportedXep>
<!-- Bookmarks (legacy) -->
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0048.html"/>
<xmpp:status>partial</xmpp:status>
<xmpp:version>1.1</xmpp:version>
<xmpp:since>1.22.0</xmpp:since>
<xmpp:note>retrieval only, autojoin only</xmpp:note>
<xmpp:note>no URL bookmarks, no pubsub. use XEP-0402 instead.</xmpp:note>
</xmpp:SupportedXep>
</implements>
<implements>
@@ -144,6 +145,16 @@
<xmpp:note>only for in-band registration</xmpp:note>
</xmpp:SupportedXep>
</implements>
<implements>
<xmpp:SupportedXep>
<!-- Bookmarks 2 -->
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0402.html"/>
<xmpp:status>partial</xmpp:status>
<xmpp:version>0.2.1</xmpp:version>
<xmpp:since>1.22.0</xmpp:since>
<xmpp:note>no bookmark renaming</xmpp:note>
</xmpp:SupportedXep>
</implements>

<release>
<Version>
@@ -6,6 +6,8 @@

#include "../ui/RegisterAccountWindow.h"

#include <gloox/jid.h>

#include <InterfaceKit.h>
#include <be_apps/NetPositive/NetPositive.h>
#include "AppLocation.h"
@@ -100,22 +102,6 @@ void BlabberMainWindow::MessageReceived(BMessage *msg) {
(new RegisterAccountWindow(this))->Show();
break;
}
// channels
case JAB_A_CHANNEL: {
if (!BlabberSettings::Instance()->Data("channel-name")) {
ModalAlertFactory::Alert("Before you may use channels, you must select a channel name under the Messages/Chat section of Preferences.", "OK");
break;
}

BString fChannelName;
if (msg->FindString("channel",&fChannelName) == B_OK)
{
//TODO ValidateRoom (see SendTalkWindow.cpp)
TalkManager::Instance()->CreateTalkSession(gloox::Message::Groupchat, NULL, fChannelName.String(), BlabberSettings::Instance()->Data("channel-name"));
}

break;
}

// transplanted from LoginWindow
case JAB_LOGIN: {
@@ -356,7 +342,25 @@ void BlabberMainWindow::MessageReceived(BMessage *msg) {
const UserID *user = item->GetUserID();

// open chat window
TalkManager::Instance()->CreateTalkSession(gloox::Message::Chat, new UserID(*user), "", "");
TalkManager::Instance()->CreateTalkSession(gloox::Message::Chat,
new UserID(*user), "", "");
}

// if there's a current selection, begin chat with that group
BookmarkItem *bookmark = _roster->CurrentBookmarkSelection();

if (bookmark != NULL) {
const gloox::JID& group = bookmark->GetUserID();
const gloox::ConferenceListItem* info
= BookmarkManager::Instance().GetBookmark(group.full().c_str());

// open chat window
TalkManager::Instance()->CreateTalkSession(gloox::Message::Groupchat,
NULL, group.full(), info->nick);

// Enable autojoin if needed
BookmarkManager::Instance().SetBookmark(group.full().c_str(),
info->nick.c_str(), true);
}

break;
@@ -468,6 +472,10 @@ void BlabberMainWindow::MessageReceived(BMessage *msg) {
JabberSpeak::Instance()->RemoveFromRoster(user);
}

BookmarkItem *bookmark = _roster->CurrentBookmarkSelection();
if (bookmark)
BookmarkManager::Instance().RemoveBookmark(bookmark->GetUserID().full().c_str());

break;
}

@@ -641,6 +649,11 @@ bool BlabberMainWindow::QuitRequested() {
BlabberSettings::Instance()->SetFloatData("main-window-height", Bounds().Height());
BlabberSettings::Instance()->WriteToFile();

// FIXME we are doing this from the wrong thread, but I see no better place.
// It needs to be done immediately here, so that closing the other windows
// doen't remove them from autojoin.
BookmarkManager::Instance().Disconnect();

be_app->PostMessage(B_QUIT_REQUESTED);
return true;
}
@@ -777,20 +790,10 @@ BlabberMainWindow::BlabberMainWindow(BRect frame)
_talk_menu->AddItem(_send_groupchat_item);
_talk_menu->SetTargetForItems(this);

// CHANNEL MENU
_channel_menu = new BMenu("Channels");

BMessage* haiku_channel = new BMessage(JAB_A_CHANNEL);
haiku_channel->AddString("channel", "haiku-os@conference.jabber.org");

BMenuItem* _a_channel = new BMenuItem("haiku-os", haiku_channel);
_channel_menu->AddItem(_a_channel);

_menubar->AddItem(_file_menu);
_menubar->AddItem(_edit_menu);
_menubar->AddItem(_status_menu);
_menubar->AddItem(_talk_menu);
_menubar->AddItem(_channel_menu);
//_menubar->AddItem(_help_menu);

// tabbed view
@@ -85,7 +85,6 @@ class BlabberMainWindow : public BWindow {
BMenu *_file_menu;
BMenu *_edit_menu;
BMenu *_status_menu;
BMenu *_channel_menu;
BMenu *_talk_menu;

BMenu *_common_status_menu;
@@ -52,16 +52,13 @@ JabberSpeak *JabberSpeak::Instance() {
JabberSpeak::JabberSpeak()
: XMLReader()
, fClient(NULL)
, fBookmarks(NULL)
{
// grab a handle to the settings now for convenience later
_blabber_settings = BlabberSettings::Instance();
}

JabberSpeak::~JabberSpeak() {
_instance = NULL;

delete fBookmarks;
}

void JabberSpeak::Reset() {
@@ -72,6 +69,7 @@ void JabberSpeak::Reset() {
}

if (!_reconnecting) {
BookmarkManager::Instance().Disconnect();
TalkManager::Instance()->Reset();
}

@@ -563,6 +561,9 @@ void JabberSpeak::SendGroupUnvitation(string _group_room, string _group_username
// Send presence Stanza
gloox::Presence presence(gloox::Presence::Unavailable, gloox::JID(group_presence));
fClient->send(presence);

// Disable autologin in bookmarks and store username
BookmarkManager::Instance().SetBookmark(_group_room.c_str(), _group_username.c_str(), false);
}

void JabberSpeak::RegisterWithAgent(string agent) {
@@ -675,11 +676,9 @@ JabberSpeak::onConnect()
fprintf(stderr, "Logged in!\n");
MessageRepeater::Instance()->PostMessage(JAB_LOGGED_IN);
//SendLastPresence();

BookmarkManager::Instance().Connect();

// Request for bookmarks
fBookmarks = new gloox::BookmarkStorage(fClient);
fBookmarks->registerBookmarkHandler(this);
fBookmarks->requestBookmarks();
_reconnecting = false;
}

@@ -689,6 +688,7 @@ JabberSpeak::onDisconnect(gloox::ConnectionError e)
{
fprintf(stderr, "%s(%d)\n", __PRETTY_FUNCTION__, e);

BookmarkManager::Instance().Disconnect();
if (e == gloox::ConnAuthenticationFailed) {
// FIXME back to login screen
fprintf(stderr, " > auth error %d\n", fClient->authError());
@@ -911,26 +911,3 @@ JabberSpeak::handleRosterError(const gloox::IQ&)
printf("%s\n", __PRETTY_FUNCTION__);
}


void
JabberSpeak::handleBookmarks(const gloox::BookmarkList& bList,
const gloox::ConferenceList& cList)
{
for (auto i: bList) {
printf("%s\n", __PRETTY_FUNCTION__);

printf("%s -> %s\n", i.name.c_str(), i.url.c_str());
}

for (auto i: cList) {
if (i.autojoin) {
TalkManager::Instance()->CreateTalkSession(gloox::Message::Groupchat, NULL,
i.jid.c_str(), i.nick.c_str());
} else {
printf("%s\n", __PRETTY_FUNCTION__);

printf("%s -> jid %s nick %s pwd %s autojoin %d\n", i.name.c_str(),
i.jid.c_str(), i.nick.c_str(), i.password.c_str(), i.autojoin);
}
}
}
@@ -6,7 +6,6 @@
#ifndef JABBER_SPEAK_H
#define JABBER_SPEAK_H

#include <gloox/bookmarkhandler.h>
#include <gloox/bookmarkstorage.h>
#include <gloox/client.h>
#include <gloox/connectionlistener.h>
@@ -15,6 +14,8 @@
#include <gloox/rosterlistener.h>
#include <gloox/softwareversion.h>

#include "../network/BookmarkManager.h"

#include <map>
#include <string>
#include <Looper.h>
@@ -26,8 +27,7 @@
#include "XMLReader.h"

class JabberSpeak : public XMLReader,
public gloox::ConnectionListener, public gloox::RosterListener,
public gloox::BookmarkHandler
public gloox::ConnectionListener, public gloox::RosterListener
{
public:
enum iq_intent {LOGIN, ROSTER, AGENTS, REGISTER, SEND_REGISTER, UNREGISTER, SEND_UNREGISTER, NEW_USER, MESSAGE, CHAT};
@@ -95,9 +95,6 @@ class JabberSpeak : public XMLReader,
void handleNonrosterPresence(const gloox::Presence&) final;
void handleRosterError(const gloox::IQ&) final;

void handleBookmarks(const gloox::BookmarkList& bList,
const gloox::ConferenceList& cList) final;

gloox::Client* GlooxClient() { return fClient; }

protected:
@@ -141,7 +138,6 @@ class JabberSpeak : public XMLReader,
thread_id _connection_thread_id;

gloox::Client* fClient;
gloox::BookmarkStorage* fBookmarks;
gloox::Registration* fRegistration;
};

@@ -155,8 +155,5 @@
#define GO_TO_RIV 0x1B000000
#define GO_TO_BEBITS 0x1B000001

// channels
#define JAB_A_CHANNEL 0x1C000000


#endif

0 comments on commit d6cbfe4

Please sign in to comment.
You can’t perform that action at this time.