small fixes

This commit is contained in:
fiaxh 2018-04-17 20:11:44 +02:00
parent 105006c5f1
commit c656c7e9c2
3 changed files with 41 additions and 23 deletions

View file

@ -151,57 +151,70 @@ public class MucManager : StreamInteractionModule, Object {
}
public string? get_room_name(Account account, Jid jid) {
XmppStream? stream = stream_interactor.get_stream(account);
return stream != null ? stream.get_flag(Xep.Muc.Flag.IDENTITY).get_room_name(jid) : null;
Xep.Muc.Flag? flag = get_muc_flag(account);
if (flag != null) {
return flag.get_room_name(jid);
}
return null;
}
public string? get_groupchat_subject(Jid jid, Account account) {
XmppStream? stream = stream_interactor.get_stream(account);
if (stream != null) {
return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_muc_subject(jid.bare_jid);
Xep.Muc.Flag? flag = get_muc_flag(account);
if (flag != null) {
return flag.get_muc_subject(jid.bare_jid);
}
return null;
}
public Jid? get_real_jid(Jid jid, Account account) {
XmppStream? stream = stream_interactor.get_stream(account);
if (stream != null) {
return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_real_jid(jid);
Xep.Muc.Flag? flag = get_muc_flag(account);
if (flag != null) {
return flag.get_real_jid(jid);
}
return null;
}
public Xep.Muc.Role? get_role(Jid jid, Account account) {
XmppStream? stream = stream_interactor.get_stream(account);
if (stream != null) return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_occupant_role(jid);
Xep.Muc.Flag? flag = get_muc_flag(account);
if (flag != null) {
return flag.get_occupant_role(jid);
}
return null;
}
public Xep.Muc.Affiliation? get_affiliation(Jid muc_jid, Jid jid, Account account) {
XmppStream? stream = stream_interactor.get_stream(account);
if (stream != null) return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_affiliation(muc_jid, jid);
Xep.Muc.Flag? flag = get_muc_flag(account);
if (flag != null) {
return flag.get_affiliation(muc_jid, jid);
}
return null;
}
public Gee.List<Jid>? get_offline_members(Jid jid, Account account) {
XmppStream? stream = stream_interactor.get_stream(account);
if (stream != null) {
return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_offline_members(jid);
Xep.Muc.Flag? flag = get_muc_flag(account);
if (flag != null) {
return flag.get_offline_members(jid);
}
return null;
}
public Jid? get_own_jid(Jid muc_jid, Account account) {
XmppStream? stream = stream_interactor.get_stream(account);
if (stream != null) {
Xep.Muc.Flag? flag = stream.get_flag(Xep.Muc.Flag.IDENTITY);
if (flag == null) return null;
Xep.Muc.Flag? flag = get_muc_flag(account);
if (flag != null) {
string? nick = flag.get_muc_nick(muc_jid);
if (nick != null) return muc_jid.with_resource(nick);
}
return null;
}
private Xep.Muc.Flag? get_muc_flag(Account account) {
XmppStream? stream = stream_interactor.get_stream(account);
if (stream != null) {
return stream.get_flag(Xep.Muc.Flag.IDENTITY);
}
return null;
}
public bool is_joined(Jid jid, Account account) {
return get_own_jid(jid, account) != null;
}

View file

@ -20,7 +20,12 @@ public abstract class StanzaListener<T> : OrderedListener {
public class StanzaListenerHolder<T> : ListenerHolder {
public async void run(XmppStream stream, T stanza) {
foreach (OrderedListener ol in listeners) {
// listeners can change e.g. when switching to another stream
ArrayList<OrderedListener> listeners_copy = new ArrayList<OrderedListener>();
listeners_copy.add_all(listeners);
foreach (OrderedListener ol in listeners_copy) {
StanzaListener<T> l = ol as StanzaListener<T>;
bool stop = yield l.run(stream, stanza);
if (stop) break;

View file

@ -173,7 +173,7 @@ public class Module : XmppStreamModule {
}
public override void attach(XmppStream stream) {
stream.add_flag(new Muc.Flag());
stream.add_flag(new Flag());
stream.get_module(MessageModule.IDENTITY).received_message.connect(on_received_message);
stream.get_module(Presence.Module.IDENTITY).received_presence.connect(check_for_enter_error);
stream.get_module(Presence.Module.IDENTITY).received_available.connect(on_received_available);
@ -368,7 +368,7 @@ public class Module : XmppStreamModule {
Jid? jid_ = Jid.parse(item.get_attribute("jid"));
string? affiliation_ = item.get_attribute("affiliation");
if (jid_ != null && affiliation_ != null) {
stream.get_flag(Muc.Flag.IDENTITY).set_offline_member(iq.from, jid_, parse_affiliation(affiliation_));
stream.get_flag(Flag.IDENTITY).set_offline_member(iq.from, jid_, parse_affiliation(affiliation_));
ret_jids.add(jid_);
}
}