@@ 30,9 30,15 @@ include Glimmer
$conversations = {}
$roster = [["", ""]]
+public def write_with_handler(stanza, &block)
+ client.write_with_handler(stanza, &block)
+end
+
class Conversation
include Glimmer
+ attr_accessor :nickname
+
def self.open(jid)
return if $conversations[jid]
@@ 61,10 67,24 @@ class Conversation
@messages.replace(mam_messages + @messages)
end
end
+
+ self.nickname = BLATHER.my_roster[jid]&.name || jid
+ return unless nickname.to_s == jid.to_s
+
+ BLATHER.write_with_handler(
+ Blather::Stanza::PubSub::Items.new(:get).tap { |iq|
+ iq.node = "http://jabber.org/protocol/nick"
+ iq.to = @jid
+ }
+ ) do |reply|
+ self.nickname = reply.items.first.payload_node.text rescue @nickname
+ end
end
def launch
- window("Conversation With #{@jid}") {
+ window {
+ title <=> [self, :nickname]
+
vertical_box {
table {
text_column("Sender")
@@ 111,6 131,8 @@ class Conversation
end
def format_sender(jid)
+ return nickname if jid.to_s == @jid.to_s
+
BLATHER.my_roster[jid]&.name || jid
end
@@ 192,7 214,7 @@ def sync_mam(last_id)
end
}
- client.write_with_handler(start_mam) do |reply|
+ write_with_handler(start_mam) do |reply|
next if reply.error?
fin = reply.find_first("./ns:fin", ns: "urn:xmpp:mam:2")