~singpolyma/jabber-client-demo

f42589efcd22bdc165c4974830717c0828fa84cd — Stephen Paul Weber 2 years ago c7f1548
XEP-0172 PEP Nickname
1 files changed, 24 insertions(+), 2 deletions(-)

M client.rb
M client.rb => client.rb +24 -2
@@ 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")