Index: python/implugin.py
===================================================================
--- python/implugin.py	(revision 2b4402fe9a1335d7defbe31fae2006815a037fc8)
+++ python/implugin.py	(revision b09ce17d617ab69f94caf5c655f6119d4362ad1e)
@@ -107,4 +107,5 @@
 	
 	def setting(self, key):
+		"""Throws KeyError if the setting does not exist!"""
 		return self._settings_values[key]
 
Index: python/wa.py
===================================================================
--- python/wa.py	(revision 2b4402fe9a1335d7defbe31fae2006815a037fc8)
+++ python/wa.py	(revision b09ce17d617ab69f94caf5c655f6119d4362ad1e)
@@ -62,5 +62,5 @@
 	def receive(self, entity):
 		print "Received: %r" % entity
-		print entity
+		#print entity
 		super(BitlBeeLayer, self).receive(entity)
 
@@ -68,5 +68,5 @@
 		"""Send an entity into Yowsup, but through the correct thread."""
 		print "Queueing: %s" % entity.getTag()
-		print entity
+		#print entity
 		def doit():
 			self.toLower(entity)
@@ -79,5 +79,10 @@
 		self.b.yow = self
 		self.cb.connected()
-		self.toLower(AvailablePresenceProtocolEntity())
+		try:
+			self.toLower(PresenceProtocolEntity(name=self.b.setting("name")))
+		except KeyError:
+			pass
+		# Should send the contact list now, but BitlBee hasn't given
+		# it yet. See set_away() and send_initial_contacts() below.
 	
 	@ProtocolEntityCallback("failure")
@@ -89,5 +94,5 @@
 
 	def onEvent(self, event):
-		print event
+		print "Received event: %s name %s" % (event, event.getName())
 		if event.getName() == "disconnect":
 			self.getStack().execDetached(self.daemon.StopDaemon)
@@ -96,15 +101,21 @@
 	def onPresence(self, pres):
 		status = 8 # MOBILE
-		online = isinstance(pres, AvailablePresenceProtocolEntity)
-		if online:
-			status += 1 # ONLINE
-		imcb_buddy_status(pres.getFrom(), status, None, None)
+		if pres.getType() != "unavailable":
+			status |= 1 # ONLINE
+		self.cb.buddy_status(pres.getFrom(), status, None, None)
 	
 	@ProtocolEntityCallback("message")
 	def onMessage(self, msg):
-		self.cb.buddy_msg(msg.getFrom(), msg.getBody(), 0, msg.getTimestamp())
-
 		receipt = OutgoingReceiptProtocolEntity(msg.getId(), msg.getFrom())
 		self.toLower(receipt)
+
+		if msg.getParticipant():
+			group = self.b.groups.get(msg.getFrom(), None)
+			if not group:
+				self.cb.log("Warning: Activity in room %s" % msg.getFrom())
+				return
+			self.cb.chat_msg(group["id"], msg.getParticipant(), msg.getBody(), 0, msg.getTimestamp())
+		else:
+			self.cb.buddy_msg(msg.getFrom(), msg.getBody(), 0, msg.getTimestamp())
 
 	@ProtocolEntityCallback("receipt")
@@ -141,7 +152,7 @@
 		print "New status for %s: %s" % (status.getFrom(), status.status)
 
-	@ProtocolEntityCallback("chatstate")
-	def onChatstate(self, entity):
-		print(entity)
+	#@ProtocolEntityCallback("chatstate")
+	#def onChatstate(self, entity):
+	#	print(entity)
 
 
@@ -176,5 +187,5 @@
 		},
 	}
-	AWAY_STATES = ["Available"]
+	AWAY_STATES = ["Away"]
 	ACCOUNT_FLAGS = 14 # HANDLE_DOMAINS + STATUS_MESSAGE + LOCAL_CONTACTS
 	# TODO: LOCAL LIST CAUSES CRASH!
@@ -192,7 +203,11 @@
 		self.logging_in = True
 		self.contacts = set()
+		self.groups = {}
+		self.groups_by_id = {}
 
 	def keepalive(self):
-		self.yow.Ship(PingIqProtocolEntity(to="s.whatsapp.net"))
+		# Too noisy while debugging
+		pass
+		#self.yow.Ship(PingIqProtocolEntity(to="s.whatsapp.net"))
 
 	def logout(self):
@@ -216,5 +231,5 @@
 		self.yow.Ship(UnsubscribePresenceProtocolEntity(handle))
 
-	def set_away(self, _state, status):
+	def set_away(self, state, status):
 		# When our first status is set, we've finalised login.
 		# Which means sync the full contact list now.
@@ -223,7 +238,12 @@
 			self.send_initial_contacts()
 		
-		# I think state is not supported?
-		print "Trying to set status to %r, %r" % (_state, status)
-		self.yow.Ship(SetStatusIqProtocolEntity(status))
+		print "Trying to set status to %r, %r" % (state, status)
+		if state:
+			# Only one option offered so None = available, not None = away.
+			self.yow.Ship(AvailablePresenceProtocolEntity())
+		else:
+			self.yow.Ship(UnavailablePresenceProtocolEntity())
+		if status:
+			self.yow.Ship(SetStatusIqProtocolEntity(status))
 
 	def send_initial_contacts(self):
@@ -236,5 +256,16 @@
 		self.yow.Ship(PresenceProtocolEntity(name=value))
 
+	def chat_join(self, id, name, _nick, _password, settings):
+		print "New chat created with id: %d" % id
+		self.groups[name] = {"id": id, "name": name}
+		self.groups_by_id[id] = self.groups[name]
+		self.bee.chat_add_buddy(id, self.account["user"])
+	
+	def chat_msg(self, id, text, flags):
+		msg = TextMessageProtocolEntity(text, to=self.groups_by_id[id]["name"])
+		self.yow.Ship(msg)
+
 	def build_stack(self, account):
+		self.account = account
 		creds = (account["user"].split("@")[0], account["pass"])
 
