aboutsummaryrefslogtreecommitdiff
path: root/connector
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-17 15:30:01 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-17 15:30:01 +0100
commit584312f30805680711557ff6fbe291d2404367fb (patch)
treec1d7993200ad500003026b77b79f234d79a01981 /connector
parentc740f76826c0291005111c8554c256e8f491e7b9 (diff)
downloadeasybridge-584312f30805680711557ff6fbe291d2404367fb.tar.gz
easybridge-584312f30805680711557ff6fbe291d2404367fb.zip
Correctly update room topics (works on irc)
Diffstat (limited to 'connector')
-rw-r--r--connector/connector.go4
-rw-r--r--connector/irc/irc.go21
-rw-r--r--connector/xmpp/xmpp.go16
3 files changed, 29 insertions, 12 deletions
diff --git a/connector/connector.go b/connector/connector.go
index 92b1adc..0afcd1c 100644
--- a/connector/connector.go
+++ b/connector/connector.go
@@ -74,7 +74,7 @@ type Handler interface {
// Called when a room's info was updated,
// or the first tome a room's info is retreived
- RoomInfoUpdated(roomId RoomID, info *RoomInfo)
+ RoomInfoUpdated(roomId RoomID, author UserID, info *RoomInfo)
// Called when an event occurs in a room
// This must not be called for events authored by the user of the connection
@@ -120,7 +120,7 @@ type UserInfo struct {
type RoomInfo struct {
Name string
- Description string
+ Topic string
Picture MediaObject
}
diff --git a/connector/irc/irc.go b/connector/irc/irc.go
index 8e5cdb0..b673498 100644
--- a/connector/irc/irc.go
+++ b/connector/irc/irc.go
@@ -78,7 +78,8 @@ func (irc *IRC) Configure(c Configuration) error {
client.Handlers.Add(girc.JOIN, irc.ircJoin)
client.Handlers.Add(girc.PART, irc.ircPart)
client.Handlers.Add(girc.RPL_NAMREPLY, irc.ircNamreply)
- client.Handlers.Add(girc.RPL_TOPIC, irc.ircTopic)
+ client.Handlers.Add(girc.TOPIC, irc.ircTopic)
+ client.Handlers.Add(girc.RPL_TOPIC, irc.ircRplTopic)
irc.conn = client
go irc.connectLoop(client)
@@ -131,7 +132,9 @@ func (irc *IRC) SetRoomInfo(roomId RoomID, info *RoomInfo) error {
if info.Picture != nil {
return fmt.Errorf("Room picture not supported on IRC")
}
- irc.conn.Cmd.Topic(ch, info.Description)
+ if info.Topic != "" {
+ irc.conn.Cmd.Topic(ch, info.Topic)
+ }
return nil
}
@@ -302,10 +305,18 @@ func (irc *IRC) ircNamreply(c *girc.Client, e girc.Event) {
}
func (irc *IRC) ircTopic(c *girc.Client, e girc.Event) {
+ source := UserID(e.Source.Name + "@" + irc.server)
+ room := RoomID(e.Params[0] + "@" + irc.server)
+ topic := e.Last()
+ irc.handler.RoomInfoUpdated(room, source, &RoomInfo{
+ Topic: topic,
+ })
+}
+
+func (irc *IRC) ircRplTopic(c *girc.Client, e girc.Event) {
room := RoomID(e.Params[1] + "@" + irc.server)
topic := e.Last()
- irc.handler.RoomInfoUpdated(room, &RoomInfo{
- Name: string(room),
- Description: topic,
+ irc.handler.RoomInfoUpdated(room, "", &RoomInfo{
+ Topic: topic,
})
}
diff --git a/connector/xmpp/xmpp.go b/connector/xmpp/xmpp.go
index 5b1c71a..7516ebc 100644
--- a/connector/xmpp/xmpp.go
+++ b/connector/xmpp/xmpp.go
@@ -183,12 +183,19 @@ func (xm *XMPP) handleXMPP() error {
case gxmpp.Chat:
log.Printf("== Receiving %#v\n", v)
- if v.Text == "" && v.Type == "groupchat" && !strings.Contains(v.Remote, "/") {
+ if v.Text == "" && v.Type == "groupchat" {
// Empty message when we joined group chat
- xm.handler.Joined(RoomID(v.Remote))
+ if !strings.Contains(v.Remote, "/") {
+ xm.handler.Joined(RoomID(v.Remote))
+ }
if v.Subject != "" {
- xm.handler.RoomInfoUpdated(RoomID(v.Remote), &RoomInfo{
- Description: v.Subject,
+ author := UserID("")
+ remote_sp := strings.Split(v.Remote, "/")
+ if len(remote_sp) == 2 {
+ author = UserID(remote_sp[1] + "@" + remote_sp[0])
+ }
+ xm.handler.RoomInfoUpdated(RoomID(v.Remote), author, &RoomInfo{
+ Topic: v.Subject,
})
}
continue
@@ -253,7 +260,6 @@ func (xm *XMPP) User() UserID {
}
func (xm *XMPP) SetUserInfo(info *UserInfo) error {
- //TODO
return fmt.Errorf("Not implemented")
}