aboutsummaryrefslogtreecommitdiff
path: root/appservice
diff options
context:
space:
mode:
Diffstat (limited to 'appservice')
-rw-r--r--appservice/account.go7
-rw-r--r--appservice/db.go32
-rw-r--r--appservice/matrix.go58
-rw-r--r--appservice/server.go11
4 files changed, 53 insertions, 55 deletions
diff --git a/appservice/account.go b/appservice/account.go
index 8430cc1..d8bf8cf 100644
--- a/appservice/account.go
+++ b/appservice/account.go
@@ -10,10 +10,10 @@ import (
)
type Account struct {
- MatrixUser string
+ MatrixUser string
AccountName string
- Protocol string
- Conn Connector
+ Protocol string
+ Conn Connector
JoinedRooms map[RoomID]bool
}
@@ -240,4 +240,3 @@ func (a *Account) eventInternal(event *Event) error {
return mxSendMessageAs(mx_room_id, typ, event.Text, mx_user_id)
}
}
-
diff --git a/appservice/db.go b/appservice/db.go
index 6c215d4..512e7b5 100644
--- a/appservice/db.go
+++ b/appservice/db.go
@@ -3,14 +3,14 @@ package appservice
import (
"fmt"
- log "github.com/sirupsen/logrus"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite"
+ log "github.com/sirupsen/logrus"
- "git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
+ "git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
)
var db *gorm.DB
@@ -40,7 +40,7 @@ type DbUserMap struct {
gorm.Model
Protocol string
- UserID connector.UserID
+ UserID connector.UserID
MxUserID string `gorm:"index:mxuserid"`
}
@@ -63,8 +63,8 @@ type DbPmRoomMap struct {
gorm.Model
// User id and account name of the local end viewed on Matrix
- MxUserID string
- Protocol string
+ MxUserID string
+ Protocol string
AccountName string
// User id to reach them
@@ -83,7 +83,7 @@ func dbGetMxRoom(protocol string, roomId connector.RoomID) (string, error) {
// If not create it
must_create := db.First(&room, DbRoomMap{
Protocol: protocol,
- RoomID: roomId,
+ RoomID: roomId,
}).RecordNotFound()
if must_create {
alias := roomAlias(protocol, roomId)
@@ -103,7 +103,7 @@ func dbGetMxRoom(protocol string, roomId connector.RoomID) (string, error) {
room = DbRoomMap{
Protocol: protocol,
- RoomID: roomId,
+ RoomID: roomId,
MxRoomID: mx_room_id,
}
db.Create(&room)
@@ -117,10 +117,10 @@ func dbGetMxPmRoom(protocol string, them connector.UserID, themMxId string, usMx
var room DbPmRoomMap
must_create := db.First(&room, DbPmRoomMap{
- MxUserID: usMxId,
- Protocol: protocol,
+ MxUserID: usMxId,
+ Protocol: protocol,
AccountName: usAccount,
- UserID: them,
+ UserID: them,
}).RecordNotFound()
if must_create {
name := fmt.Sprintf("%s (%s)", them, protocol)
@@ -138,11 +138,11 @@ func dbGetMxPmRoom(protocol string, them connector.UserID, themMxId string, usMx
}
room = DbPmRoomMap{
- MxUserID: usMxId,
- Protocol: protocol,
+ MxUserID: usMxId,
+ Protocol: protocol,
AccountName: usAccount,
- UserID: them,
- MxRoomID: mx_room_id,
+ UserID: them,
+ MxRoomID: mx_room_id,
}
db.Create(&room)
}
@@ -156,7 +156,7 @@ func dbGetMxUser(protocol string, userId connector.UserID) (string, error) {
must_create := db.First(&user, DbUserMap{
Protocol: protocol,
- UserID: userId,
+ UserID: userId,
}).RecordNotFound()
if must_create {
username := userMxId(protocol, userId)
@@ -174,7 +174,7 @@ func dbGetMxUser(protocol string, userId connector.UserID) (string, error) {
user = DbUserMap{
Protocol: protocol,
- UserID: userId,
+ UserID: userId,
MxUserID: mxid,
}
db.Create(&user)
diff --git a/appservice/matrix.go b/appservice/matrix.go
index 2c4562e..550e5a5 100644
--- a/appservice/matrix.go
+++ b/appservice/matrix.go
@@ -1,12 +1,12 @@
package appservice
import (
+ "bytes"
+ "encoding/json"
"fmt"
- "net/url"
"net/http"
+ "net/url"
"time"
- "bytes"
- "encoding/json"
log "github.com/sirupsen/logrus"
@@ -33,7 +33,7 @@ func init() {
func mxGetApiCall(endpoint string, response interface{}) error {
log.Debugf("Matrix GET request: %s\n", endpoint)
- req, err := http.NewRequest("GET", config.Server + endpoint, nil)
+ req, err := http.NewRequest("GET", config.Server+endpoint, nil)
if err != nil {
return err
}
@@ -49,7 +49,7 @@ func mxPutApiCall(endpoint string, data interface{}, response interface{}) error
log.Debugf("Matrix PUT request: %s %s\n", endpoint, string(body))
- req, err := http.NewRequest("PUT", config.Server + endpoint, bytes.NewBuffer(body))
+ req, err := http.NewRequest("PUT", config.Server+endpoint, bytes.NewBuffer(body))
if err != nil {
return err
}
@@ -66,7 +66,7 @@ func mxPostApiCall(endpoint string, data interface{}, response interface{}) erro
log.Debugf("Matrix POST request: %s %s\n", endpoint, string(body))
- req, err := http.NewRequest("POST", config.Server + endpoint, bytes.NewBuffer(body))
+ req, err := http.NewRequest("POST", config.Server+endpoint, bytes.NewBuffer(body))
if err != nil {
return err
}
@@ -76,7 +76,7 @@ func mxPostApiCall(endpoint string, data interface{}, response interface{}) erro
}
func mxDoAndParse(req *http.Request, response interface{}) error {
- req.Header.Add("Authorization", "Bearer " + registration.AsToken)
+ req.Header.Add("Authorization", "Bearer "+registration.AsToken)
resp, err := httpClient.Do(req)
if err != nil {
@@ -125,7 +125,7 @@ func mxProfileDisplayname(userid string, displayname string) error {
func mxDirectoryRoom(alias string) (string, error) {
var rep DirectoryRoomResponse
- err := mxGetApiCall("/_matrix/client/r0/directory/room/" + url.QueryEscape(alias), &rep)
+ err := mxGetApiCall("/_matrix/client/r0/directory/room/"+url.QueryEscape(alias), &rep)
if err != nil {
return "", err
}
@@ -134,18 +134,18 @@ func mxDirectoryRoom(alias string) (string, error) {
func mxCreateRoom(name string, alias string, invite []string) (string, error) {
rq := CreateRoomRequest{
- Preset: "private_chat",
+ Preset: "private_chat",
RoomAliasName: alias,
- Name: name,
- Topic: "",
- Invite: invite,
- CreationContent: map[string]interface{} {
+ Name: name,
+ Topic: "",
+ Invite: invite,
+ CreationContent: map[string]interface{}{
"m.federate": false,
},
- PowerLevels: map[string]interface{} {
+ PowerLevels: map[string]interface{}{
"invite": 100,
- "events": map[string]interface{} {
- "m.room.topic": 0,
+ "events": map[string]interface{}{
+ "m.room.topic": 0,
"m.room.avatar": 0,
},
},
@@ -161,19 +161,19 @@ func mxCreateRoom(name string, alias string, invite []string) (string, error) {
func mxCreateDirectRoomAs(name string, invite []string, as_user string) (string, error) {
rq := CreateRoomNoAliasRequest{
Preset: "private_chat",
- Name: name,
- Topic: "",
+ Name: name,
+ Topic: "",
Invite: invite,
- CreationContent: map[string]interface{} {
+ CreationContent: map[string]interface{}{
"m.federate": false,
},
- PowerLevels: map[string]interface{} {
+ PowerLevels: map[string]interface{}{
"invite": 100,
},
IsDirect: true,
}
var rep CreateRoomResponse
- err := mxPostApiCall("/_matrix/client/r0/createRoom?user_id=" + url.QueryEscape(as_user), &rq, &rep)
+ err := mxPostApiCall("/_matrix/client/r0/createRoom?user_id="+url.QueryEscape(as_user), &rq, &rep)
if err != nil {
return "", err
}
@@ -185,7 +185,7 @@ func mxRoomInvite(room string, user string) error {
UserId: user,
}
var rep struct{}
- err := mxPostApiCall("/_matrix/client/r0/rooms/" + url.QueryEscape(room) + "/invite", &rq, &rep)
+ err := mxPostApiCall("/_matrix/client/r0/rooms/"+url.QueryEscape(room)+"/invite", &rq, &rep)
return err
}
@@ -195,21 +195,21 @@ func mxRoomKick(room string, user string, reason string) error {
Reason: reason,
}
var rep struct{}
- err := mxPostApiCall("/_matrix/client/r0/rooms/" + url.QueryEscape(room) + "/kick", &rq, &rep)
+ err := mxPostApiCall("/_matrix/client/r0/rooms/"+url.QueryEscape(room)+"/kick", &rq, &rep)
return err
}
func mxRoomJoinAs(room string, user string) error {
rq := struct{}{}
var rep RoomJoinResponse
- err := mxPostApiCall("/_matrix/client/r0/rooms/" + url.QueryEscape(room) + "/join?user_id=" + url.QueryEscape(user), &rq, &rep)
+ err := mxPostApiCall("/_matrix/client/r0/rooms/"+url.QueryEscape(room)+"/join?user_id="+url.QueryEscape(user), &rq, &rep)
return err
}
func mxRoomLeaveAs(room string, user string) error {
rq := struct{}{}
var rep struct{}
- err := mxPostApiCall("/_matrix/client/r0/rooms/" + url.QueryEscape(room) + "/leave?user_id=" + url.QueryEscape(user), &rq, &rep)
+ err := mxPostApiCall("/_matrix/client/r0/rooms/"+url.QueryEscape(room)+"/leave?user_id="+url.QueryEscape(user), &rq, &rep)
return err
}
@@ -224,9 +224,9 @@ func mxSendAs(room string, event_type string, content map[string]interface{}, us
}
func mxSendMessageAs(room string, typ string, body string, user string) error {
- content := map[string]interface{} {
+ content := map[string]interface{}{
"msgtype": typ,
- "body": body,
+ "body": body,
}
return mxSendAs(room, "m.room.message", content, user)
}
@@ -241,14 +241,14 @@ func mxPutStateAs(room string, event_type string, key string, content map[string
}
func mxRoomNameAs(room string, name string, as_user string) error {
- content := map[string]interface{} {
+ content := map[string]interface{}{
"name": name,
}
return mxPutStateAs(room, "m.room.name", "", content, as_user)
}
func mxRoomTopicAs(room string, topic string, as_user string) error {
- content := map[string]interface{} {
+ content := map[string]interface{}{
"topic": topic,
}
return mxPutStateAs(room, "m.room.topic", "", content, as_user)
diff --git a/appservice/server.go b/appservice/server.go
index 580d1f1..f207eb4 100644
--- a/appservice/server.go
+++ b/appservice/server.go
@@ -3,25 +3,24 @@ package appservice
import (
"encoding/json"
"fmt"
- "strings"
"net/http"
+ "strings"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
- "git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
+ "git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
)
type Config struct {
HttpBindAddr string
- Server string
- DbType string
- DbPath string
+ Server string
+ DbType string
+ DbPath string
MatrixDomain string
}
-
var registration *mxlib.Registration
var config *Config