aboutsummaryrefslogtreecommitdiff
path: root/connector
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-23 20:24:50 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-23 20:24:50 +0100
commitec9bc9b7520a8e8c3c372943126df985329dcd18 (patch)
tree000683f506359d0463e37010996aab8422620e78 /connector
parent0f6be9663e6e8b954d24596c455a704d42499a52 (diff)
downloadeasybridge-ec9bc9b7520a8e8c3c372943126df985329dcd18.tar.gz
easybridge-ec9bc9b7520a8e8c3c372943126df985329dcd18.zip
go fmt
Diffstat (limited to 'connector')
-rw-r--r--connector/connector.go8
-rw-r--r--connector/mattermost/mattermost.go35
-rw-r--r--connector/mediaobject.go21
-rw-r--r--connector/xmpp/xmpp.go55
4 files changed, 59 insertions, 60 deletions
diff --git a/connector/connector.go b/connector/connector.go
index 3a2e20c..38ce828 100644
--- a/connector/connector.go
+++ b/connector/connector.go
@@ -136,12 +136,12 @@ type UserInfo struct {
// If non-empty, the Filename of the avatar object will be used by Easybridge
// to deduplicate the update events and prevent needless reuploads.
// Example strategy that works for the mattermost backend: use the update timestamp as fictious file name
- Avatar MediaObject
+ Avatar MediaObject
}
type RoomInfo struct {
- Name string
- Topic string
+ Name string
+ Topic string
// Same deduplication comment as for UserInfo.Avatar
Picture MediaObject
@@ -164,6 +164,6 @@ type MediaObject interface {
}
type ImageSize struct {
- Width int
+ Width int
Height int
}
diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go
index 13deb6e..010e102 100644
--- a/connector/mattermost/mattermost.go
+++ b/connector/mattermost/mattermost.go
@@ -1,16 +1,16 @@
package mattermost
import (
- "net/http"
+ "encoding/json"
"fmt"
+ "io/ioutil"
+ "net/http"
_ "os"
"strings"
"time"
- "io/ioutil"
- "encoding/json"
- "github.com/mattermost/mattermost-server/model"
"github.com/42wim/matterbridge/matterclient"
+ "github.com/mattermost/mattermost-server/model"
log "github.com/sirupsen/logrus"
. "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
@@ -22,19 +22,18 @@ import (
type Mattermost struct {
handler Handler
- server string
+ server string
username string
- teams map[string]bool
+ teams map[string]bool
- conn *matterclient.MMClient
+ conn *matterclient.MMClient
handlerStopChan chan bool
- usermap map[string]string // map username to mm user id
- sentjoinedmap map[string]bool // map username/room name to bool
- userdisplaynamemap map[UserID]string // map username to last displayname
+ usermap map[string]string // map username to mm user id
+ sentjoinedmap map[string]bool // map username/room name to bool
+ userdisplaynamemap map[UserID]string // map username to last displayname
}
-
func (mm *Mattermost) SetHandler(h Handler) {
mm.handler = h
}
@@ -318,7 +317,7 @@ func (mm *Mattermost) handleConnected() {
// Update room info
room_info := &RoomInfo{
- Name: ch.DisplayName,
+ Name: ch.DisplayName,
Topic: ch.Header,
}
for _, t := range mm.conn.OtherTeams {
@@ -446,8 +445,8 @@ func (mm *Mattermost) ensureJoined(user *model.User, roomId RoomID) {
if _, ok := mm.sentjoinedmap[cache_key]; !ok {
mm.handler.Event(&Event{
Author: userId,
- Room: roomId,
- Type: EVENT_JOIN,
+ Room: roomId,
+ Type: EVENT_JOIN,
})
mm.sentjoinedmap[cache_key] = true
}
@@ -484,10 +483,10 @@ func (mm *Mattermost) handlePost(channel_name string, post *model.Post, only_mes
// Build message event
msg_ev := &Event{
- Id: post.Id,
+ Id: post.Id,
Author: userId,
- Text: post.Message,
- Type: EVENT_MESSAGE,
+ Text: post.Message,
+ Type: EVENT_MESSAGE,
}
if post.Type == "me" {
msg_ev.Type = EVENT_ACTION
@@ -511,7 +510,7 @@ func (mm *Mattermost) handlePost(channel_name string, post *model.Post, only_mes
}
if file.Width > 0 {
media_object.ObjectImageSize = &ImageSize{
- Width: file.Width,
+ Width: file.Width,
Height: file.Height,
}
}
diff --git a/connector/mediaobject.go b/connector/mediaobject.go
index 244e571..f904459 100644
--- a/connector/mediaobject.go
+++ b/connector/mediaobject.go
@@ -58,10 +58,10 @@ func (m *FileMediaObject) URL() string {
// ----
type UrlMediaObject struct {
- ObjectFilename string
- ObjectSize int64
- ObjectMimetype string
- ObjectURL string
+ ObjectFilename string
+ ObjectSize int64
+ ObjectMimetype string
+ ObjectURL string
ObjectImageSize *ImageSize
}
@@ -96,10 +96,10 @@ func (m *UrlMediaObject) URL() string {
// ----
type BlobMediaObject struct {
- ObjectFilename string
- ObjectMimetype string
+ ObjectFilename string
+ ObjectMimetype string
ObjectImageSize *ImageSize
- ObjectData []byte
+ ObjectData []byte
}
func (m *BlobMediaObject) Filename() string {
@@ -129,6 +129,7 @@ func (m *BlobMediaObject) URL() string {
type nullCloseReader struct {
io.Reader
}
+
func (ncr nullCloseReader) Close() error {
return nil
}
@@ -136,10 +137,10 @@ func (ncr nullCloseReader) Close() error {
// ----
type LazyBlobMediaObject struct {
- ObjectFilename string
- ObjectMimetype string
+ ObjectFilename string
+ ObjectMimetype string
ObjectImageSize *ImageSize
- ObjectData []byte
+ ObjectData []byte
GetFn func(o *LazyBlobMediaObject) error
}
diff --git a/connector/xmpp/xmpp.go b/connector/xmpp/xmpp.go
index 02d1a96..7e35135 100644
--- a/connector/xmpp/xmpp.go
+++ b/connector/xmpp/xmpp.go
@@ -3,12 +3,12 @@ package xmpp
import (
"time"
//"os"
- "strings"
- "fmt"
"crypto/tls"
+ "fmt"
+ "strings"
- log "github.com/sirupsen/logrus"
gxmpp "github.com/mattn/go-xmpp"
+ log "github.com/sirupsen/logrus"
. "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
)
@@ -22,16 +22,16 @@ type XMPP struct {
handler Handler
connectorLoopNum int
- connected bool
- timeout int
+ connected bool
+ timeout int
- server string
- port int
- ssl bool
- jid string
+ server string
+ port int
+ ssl bool
+ jid string
jid_localpart string
- password string
- nickname string
+ password string
+ nickname string
conn *gxmpp.Client
@@ -42,7 +42,7 @@ func (xm *XMPP) SetHandler(h Handler) {
xm.handler = h
}
-func(xm *XMPP) Protocol() string {
+func (xm *XMPP) Protocol() string {
return "xmpp"
}
@@ -97,7 +97,7 @@ func (xm *XMPP) Configure(c Configuration) error {
go xm.connectLoop(xm.connectorLoopNum)
for i := 0; i < 42; i++ {
- time.Sleep(time.Duration(1)*time.Second)
+ time.Sleep(time.Duration(1) * time.Second)
if xm.connected {
return nil
}
@@ -116,12 +116,12 @@ func (xm *XMPP) connectLoop(num int) {
InsecureSkipVerify: true,
}
options := gxmpp.Options{
- Host: xm.server,
- User: xm.jid,
- Password: xm.password,
- NoTLS: true,
- StartTLS: xm.ssl,
- Session: true,
+ Host: xm.server,
+ User: xm.jid,
+ Password: xm.password,
+ NoTLS: true,
+ StartTLS: xm.ssl,
+ Session: true,
TLSConfig: tc,
}
var err error
@@ -237,8 +237,8 @@ func (xm *XMPP) handleXMPP() error {
user := UserID(remote[1] + "@" + remote[0])
event := &Event{
- Type: EVENT_JOIN,
- Room: RoomID(remote[0]),
+ Type: EVENT_JOIN,
+ Room: RoomID(remote[0]),
Author: user,
}
if v.Type == "unavailable" {
@@ -264,8 +264,8 @@ func (xm *XMPP) SetUserInfo(info *UserInfo) error {
func (xm *XMPP) SetRoomInfo(roomId RoomID, info *RoomInfo) error {
if info.Topic != "" {
_, err := xm.conn.Send(gxmpp.Chat{
- Type: "groupchat",
- Remote: string(roomId),
+ Type: "groupchat",
+ Remote: string(roomId),
Subject: info.Topic,
})
if err != nil {
@@ -324,16 +324,16 @@ func (xm *XMPP) Send(event *Event) error {
fmt.Printf("xm *XMPP Send %#v\n", event)
if len(event.Recipient) > 0 {
_, err := xm.conn.Send(gxmpp.Chat{
- Type: "chat",
+ Type: "chat",
Remote: string(event.Recipient),
- Text: event.Text,
+ Text: event.Text,
})
return err
} else if len(event.Room) > 0 {
_, err := xm.conn.Send(gxmpp.Chat{
- Type: "groupchat",
+ Type: "groupchat",
Remote: string(event.Room),
- Text: event.Text,
+ Text: event.Text,
})
return err
} else {
@@ -346,4 +346,3 @@ func (xm *XMPP) Close() {
xm.conn = nil
xm.connectorLoopNum += 1
}
-