Store MUC passwords in bookmark

fixes #470
This commit is contained in:
fiaxh 2019-12-24 16:46:55 +01:00
parent 2d8a1374ad
commit bce709b794
4 changed files with 25 additions and 31 deletions

View file

@ -9,8 +9,6 @@ public class MucManager : StreamInteractionModule, Object {
public static ModuleIdentity<MucManager> IDENTITY = new ModuleIdentity<MucManager>("muc_manager");
public string id { get { return IDENTITY.id; } }
public signal void joined(Account account, Jid jid, string nick);
public signal void enter_error(Account account, Jid jid, Xep.Muc.MucEnterError error);
public signal void left(Account account, Jid jid);
public signal void subject_set(Account account, Jid jid, string? subject);
public signal void room_name_set(Account account, Jid jid, string? room_name);
@ -49,7 +47,23 @@ public class MucManager : StreamInteractionModule, Object {
if (last_message != null) history_since = last_message.time;
}
return yield stream.get_module(Xep.Muc.Module.IDENTITY).enter(stream, jid.bare_jid, nick_, password, history_since);
Muc.JoinResult? res = yield stream.get_module(Xep.Muc.Module.IDENTITY).enter(stream, jid.bare_jid, nick_, password, history_since);
if (res.nick != null) {
// Join completed
enter_errors.unset(jid);
set_autojoin(account, stream, jid, nick, password);
stream_interactor.get_module(MessageProcessor.IDENTITY).send_unsent_messages(account, jid);
Conversation joined_conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.GROUPCHAT);
joined_conversation.nickname = nick;
stream_interactor.get_module(ConversationManager.IDENTITY).start_conversation(conversation);
} else if (res.muc_error != null) {
// Join failed
enter_errors[jid] = res.muc_error;
}
return res;
}
public void part(Account account, Jid jid) {
@ -264,13 +278,6 @@ public class MucManager : StreamInteractionModule, Object {
}
private void on_account_added(Account account) {
stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_entered.connect( (stream, jid, nick) => {
on_room_entred(account, stream, jid, nick);
});
stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_enter_error.connect( (stream, jid, error) => {
enter_errors[jid] = error;
enter_error(account, jid, error);
});
stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).self_removed_from_room.connect( (stream, jid, code) => {
left(account, jid);
});
@ -317,16 +324,6 @@ public class MucManager : StreamInteractionModule, Object {
}
}
private void on_room_entred(Account account, XmppStream stream, Jid jid, string nick) {
enter_errors.unset(jid);
set_autojoin(account, stream, jid, nick, null); // TODO password
joined(account, jid, nick);
stream_interactor.get_module(MessageProcessor.IDENTITY).send_unsent_messages(account, jid);
Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.GROUPCHAT);
stream_interactor.get_module(ConversationManager.IDENTITY).start_conversation(conversation);
conversation.nickname = nick;
}
private void join_all_active(Account account) {
Gee.List<Conversation> conversations = stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations(account);
foreach (Conversation conversation in conversations) {

View file

@ -70,8 +70,6 @@ public class Module : XmppStreamModule {
public signal void room_name_set(XmppStream stream, Jid jid, string? room_name);
public signal void invite_received(XmppStream stream, Jid room_jid, Jid from_jid, string? password, string? reason);
public signal void room_entered(XmppStream stream, Jid jid, string nick);
public signal void room_enter_error(XmppStream stream, Jid jid, MucEnterError? error); // TODO "?" shoudln't be necessary (vala bug), remove someday
public signal void self_removed_from_room(XmppStream stream, Jid jid, StatusCode code);
public signal void removed_from_room(XmppStream stream, Jid jid, StatusCode? code);
@ -226,12 +224,6 @@ public class Module : XmppStreamModule {
if (stream.get_module(ServiceDiscovery.Module.IDENTITY) != null) {
stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature(stream, NS_URI);
}
room_entered.connect((stream, jid, nick) => {
query_affiliation(stream, jid, "member", null);
query_affiliation(stream, jid, "admin", null);
query_affiliation(stream, jid, "owner", null);
});
}
public override void detach(XmppStream stream) {
@ -300,7 +292,6 @@ public class Module : XmppStreamModule {
break;
}
if (error != MucEnterError.NONE) {
room_enter_error(stream, bare_jid, error);
flag.enter_futures[bare_jid].set_value(new JoinResult() {muc_error=error});
} else {
flag.enter_futures[bare_jid].set_value(new JoinResult() {stanza_error=error_stanza.condition});
@ -319,7 +310,11 @@ public class Module : XmppStreamModule {
if (status_codes.contains(StatusCode.SELF_PRESENCE)) {
Jid bare_jid = presence.from.bare_jid;
if (flag.get_enter_id(bare_jid) != null) {
room_entered(stream, bare_jid, presence.from.resourcepart);
query_affiliation(stream, bare_jid, "member", null);
query_affiliation(stream, bare_jid, "admin", null);
query_affiliation(stream, bare_jid, "owner", null);
flag.finish_muc_enter(bare_jid, presence.from.resourcepart);
flag.enter_futures[bare_jid].set_value(new JoinResult() {nick=presence.from.resourcepart});
}

View file

@ -42,6 +42,7 @@ public class Module : BookmarksProvider, XmppStreamModule {
conference_node.put_node(new StanzaNode.build("nick", NS_URI)
.put_node(new StanzaNode.text(conference.nick)));
}
// TODO (?) Bookmarks 2 currently don't define a password
storage_node.put_node(conference_node);
}
}

View file

@ -71,9 +71,10 @@ public class Bookmarks1Conference : Conference {
return;
}
if (password_node == null) {
password_node = new StanzaNode.build(NODE_PASSWORD);
password_node = new StanzaNode.build(NODE_PASSWORD, NS_URI);
stanza_node.put_node(password_node);
}
password_node.sub_nodes.clear();
password_node.put_node(new StanzaNode.text(value));
}
}