mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-23 19:22:03 -08:00
go lint is a bloody picky little bastard
This commit is contained in:
parent
9663721680
commit
14a83e08cb
@ -2,10 +2,10 @@ package bsignald
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"net"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/42wim/matterbridge/bridge"
|
"github.com/42wim/matterbridge/bridge"
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
type JSONCMD map[string]interface{}
|
type JSONCMD map[string]interface{}
|
||||||
@ -13,7 +13,6 @@ type JSONCMD map[string]interface{}
|
|||||||
const (
|
const (
|
||||||
cfgNumber = "Number"
|
cfgNumber = "Number"
|
||||||
cfgSocket = "UnixSocket"
|
cfgSocket = "UnixSocket"
|
||||||
cfgGroupID = "GroupID"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type signaldMessage struct {
|
type signaldMessage struct {
|
||||||
@ -28,30 +27,30 @@ type signaldUnexpectedError struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type signaldMessageData struct {
|
type signaldMessageData struct {
|
||||||
ID string `json:",omitempty"`
|
ID string `json:",omitempty"`
|
||||||
Data signaldData `json:",omitempty"`
|
Data signaldData `json:",omitempty"`
|
||||||
Type string `json:",omitempty"`
|
Type string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type signaldData struct {
|
type signaldData struct {
|
||||||
CallMessage json.RawMessage `json:"callMessage,omitempty"`
|
CallMessage json.RawMessage `json:"callMessage,omitempty"`
|
||||||
DataMessage *signaldDataMessage `json:"dataMessage,omitempty"`
|
DataMessage *signaldDataMessage `json:"dataMessage,omitempty"`
|
||||||
HasContent bool `json:"hasContent,omitempty"`
|
HasContent bool `json:"hasContent,omitempty"`
|
||||||
HasLegacyMessage bool `json:"hasLegacyMessage,omitempty"`
|
HasLegacyMessage bool `json:"hasLegacyMessage,omitempty"`
|
||||||
IsUnidentifiedSender bool `json:"isUnidentifiedSender,omitempty"`
|
IsUnidentifiedSender bool `json:"isUnidentifiedSender,omitempty"`
|
||||||
Receipt json.RawMessage `json:"receipt,omitempty"`
|
Receipt json.RawMessage `json:"receipt,omitempty"`
|
||||||
Relay string `json:"relay,omitempty"`
|
Relay string `json:"relay,omitempty"`
|
||||||
ServerDeliveredTimestamp int64 `json:"serverDeliveredTimestamp,omitempty"`
|
ServerDeliveredTimestamp int64 `json:"serverDeliveredTimestamp,omitempty"`
|
||||||
ServerTimestamp int64 `json:"serverTimestamp,omitempty"`
|
ServerTimestamp int64 `json:"serverTimestamp,omitempty"`
|
||||||
Source *signaldAccount `json:"source,omitempty"`
|
Source *signaldAccount `json:"source,omitempty"`
|
||||||
SourceDevice int32 `json:"sourceDevice,omitempty"`
|
SourceDevice int32 `json:"sourceDevice,omitempty"`
|
||||||
SyncMessage json.RawMessage `json:"syncMessage,omitempty"`
|
SyncMessage json.RawMessage `json:"syncMessage,omitempty"`
|
||||||
Timestamp int64 `json:"timestamp,omitempty"`
|
Timestamp int64 `json:"timestamp,omitempty"`
|
||||||
TimestampISO string `json:"timestampISO,omitempty"`
|
TimestampISO string `json:"timestampISO,omitempty"`
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Typing json.RawMessage `json:"typing,omitempty"`
|
Typing json.RawMessage `json:"typing,omitempty"`
|
||||||
Username string `json:"username,omitempty"`
|
Username string `json:"username,omitempty"`
|
||||||
UUID string `json:"uuid,omitempty"`
|
UUID string `json:"uuid,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type signaldAccount struct {
|
type signaldAccount struct {
|
||||||
@ -88,18 +87,18 @@ type signaldGroupInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type signaldGroupV2Info struct {
|
type signaldGroupV2Info struct {
|
||||||
AccessControl json.RawMessage `json:"accessControl,omitempty"`
|
AccessControl json.RawMessage `json:"accessControl,omitempty"`
|
||||||
Avatar string `json:"avatar,omitempty"`
|
Avatar string `json:"avatar,omitempty"`
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
InviteLink string `json:"inviteLink,omitempty"`
|
InviteLink string `json:"inviteLink,omitempty"`
|
||||||
MemberDetail json.RawMessage `json:"memberDetail,omitempty"`
|
MemberDetail json.RawMessage `json:"memberDetail,omitempty"`
|
||||||
Members json.RawMessage `json:"members,omitempty"`
|
Members json.RawMessage `json:"members,omitempty"`
|
||||||
PendingMemberDetail json.RawMessage `json:"pendingMemberDetail,omitempty"`
|
PendingMemberDetail json.RawMessage `json:"pendingMemberDetail,omitempty"`
|
||||||
PendingMembers json.RawMessage `json:"pendingMembers,omitempty"`
|
PendingMembers json.RawMessage `json:"pendingMembers,omitempty"`
|
||||||
RequestingMembers json.RawMessage `json:"requestingMembers,omitempty"`
|
RequestingMembers json.RawMessage `json:"requestingMembers,omitempty"`
|
||||||
Revision int32 `json:"revision,omitempty"`
|
Revision int32 `json:"revision,omitempty"`
|
||||||
Timer int32 `json:"timer,omitempty"`
|
Timer int32 `json:"timer,omitempty"`
|
||||||
Title string `son:"title,omitempty"`
|
Title string `son:"title,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type signaldSendMessage struct {
|
type signaldSendMessage struct {
|
||||||
@ -126,8 +125,8 @@ type Bsignald struct {
|
|||||||
socket net.Conn
|
socket net.Conn
|
||||||
subscribed bool
|
subscribed bool
|
||||||
reader *bufio.Scanner
|
reader *bufio.Scanner
|
||||||
groupid string
|
groupid string
|
||||||
contacts map[string]signaldContact
|
contacts map[string]signaldContact
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *bridge.Config) bridge.Bridger {
|
func New(cfg *bridge.Config) bridge.Bridger {
|
||||||
@ -142,10 +141,10 @@ func New(cfg *bridge.Config) bridge.Bridger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &Bsignald{
|
return &Bsignald{
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
socketpath: socketpath,
|
socketpath: socketpath,
|
||||||
subscribed: false,
|
subscribed: false,
|
||||||
contacts: make(map[string]signaldContact),
|
contacts: make(map[string]signaldContact),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,13 +179,17 @@ func (b *Bsignald) HandleUnexpectedErrorMessage(msg signaldMessage) {
|
|||||||
func (b *Bsignald) HandleSubscribeMessage() {
|
func (b *Bsignald) HandleSubscribeMessage() {
|
||||||
b.Log.Debugln("subscribe successful", b.GetString(cfgNumber))
|
b.Log.Debugln("subscribe successful", b.GetString(cfgNumber))
|
||||||
b.subscribed = true
|
b.subscribed = true
|
||||||
go b.GetContacts()
|
if err := b.GetContacts(); err != nil {
|
||||||
|
b.Log.Errorln("Error getting contacts: ", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bsignald) HandleListenStoppedMessage() {
|
func (b *Bsignald) HandleListenStoppedMessage() {
|
||||||
b.Log.Errorln("got listen stopped, trying to re-subscribe")
|
b.Log.Errorln("got listen stopped, trying to re-subscribe")
|
||||||
b.subscribed = false
|
b.subscribed = false
|
||||||
go b.Login()
|
if err := b.Login(); err != nil {
|
||||||
|
b.Log.Errorln("Error logging in: ", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bsignald) HandleContactList(msg signaldMessage) {
|
func (b *Bsignald) HandleContactList(msg signaldMessage) {
|
||||||
@ -203,12 +206,13 @@ func (b *Bsignald) HandleContactList(msg signaldMessage) {
|
|||||||
func (b *Bsignald) GetUsername(uuid string) string {
|
func (b *Bsignald) GetUsername(uuid string) string {
|
||||||
username := ""
|
username := ""
|
||||||
if v, found := b.contacts[uuid]; found {
|
if v, found := b.contacts[uuid]; found {
|
||||||
if "" != v.ProfileName {
|
if v.ProfileName != "" {
|
||||||
username = v.ProfileName
|
username = v.ProfileName
|
||||||
} else if "" != v.Name {
|
} else if v.Name != "" {
|
||||||
username = v.Name
|
username = v.Name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return username
|
return username
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +223,7 @@ func (b *Bsignald) HandleMessage(msg signaldMessage) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil == response.Data.DataMessage {
|
if response.Data.DataMessage == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,13 +238,13 @@ func (b *Bsignald) HandleMessage(msg signaldMessage) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if false == groupMatched {
|
if !groupMatched {
|
||||||
b.Log.Debugln("skipping non-group message")
|
b.Log.Debugln("skipping non-group message")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
username := b.GetUsername(response.Data.Source.UUID)
|
username := b.GetUsername(response.Data.Source.UUID)
|
||||||
if "" == username {
|
if username == "" {
|
||||||
username = response.Data.Source.Number
|
username = response.Data.Source.Number
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +260,6 @@ func (b *Bsignald) HandleMessage(msg signaldMessage) {
|
|||||||
b.Log.Debugf("<= Sending message from %s on %s to gateway", rmsg.Username, b.Account)
|
b.Log.Debugf("<= Sending message from %s on %s to gateway", rmsg.Username, b.Account)
|
||||||
b.Log.Debugf("<= Message is %#v", rmsg)
|
b.Log.Debugf("<= Message is %#v", rmsg)
|
||||||
b.Remote <- rmsg
|
b.Remote <- rmsg
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bsignald) Listen() {
|
func (b *Bsignald) Listen() {
|
||||||
@ -277,18 +280,18 @@ func (b *Bsignald) Listen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch msg.Type {
|
switch msg.Type {
|
||||||
case "unexpected_error":
|
case "unexpected_error":
|
||||||
b.HandleUnexpectedErrorMessage(msg)
|
b.HandleUnexpectedErrorMessage(msg)
|
||||||
case "subscribed":
|
case "subscribed":
|
||||||
b.HandleSubscribeMessage()
|
b.HandleSubscribeMessage()
|
||||||
case "listen_stopped":
|
case "listen_stopped":
|
||||||
b.HandleListenStoppedMessage()
|
b.HandleListenStoppedMessage()
|
||||||
case "contact_list":
|
case "contact_list":
|
||||||
b.HandleContactList(msg)
|
b.HandleContactList(msg)
|
||||||
case "message":
|
case "message":
|
||||||
b.HandleMessage(msg)
|
b.HandleMessage(msg)
|
||||||
default:
|
default:
|
||||||
b.Log.Debugln("unsupported signald data received, skipping it");
|
b.Log.Debugln("unsupported signald data received, skipping it")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,7 +299,7 @@ func (b *Bsignald) Listen() {
|
|||||||
|
|
||||||
func (b *Bsignald) GetContacts() error {
|
func (b *Bsignald) GetContacts() error {
|
||||||
cmd := JSONCMD{
|
cmd := JSONCMD{
|
||||||
"type": "list_contacts",
|
"type": "list_contacts",
|
||||||
"username": b.GetString(cfgNumber),
|
"username": b.GetString(cfgNumber),
|
||||||
}
|
}
|
||||||
return b.SendRawJSON(cmd)
|
return b.SendRawJSON(cmd)
|
||||||
@ -304,9 +307,9 @@ func (b *Bsignald) GetContacts() error {
|
|||||||
|
|
||||||
func (b *Bsignald) Login() error {
|
func (b *Bsignald) Login() error {
|
||||||
var err error
|
var err error
|
||||||
if ! b.subscribed {
|
if !b.subscribed {
|
||||||
cmd := JSONCMD{
|
cmd := JSONCMD{
|
||||||
"type": "subscribe",
|
"type": "subscribe",
|
||||||
"username": b.GetString(cfgNumber),
|
"username": b.GetString(cfgNumber),
|
||||||
}
|
}
|
||||||
err = b.SendRawJSON(cmd)
|
err = b.SendRawJSON(cmd)
|
||||||
@ -314,7 +317,7 @@ func (b *Bsignald) Login() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bsignald) SendRawJSON(cmd JSONCMD) (error) {
|
func (b *Bsignald) SendRawJSON(cmd JSONCMD) error {
|
||||||
err := json.NewEncoder(b.socket).Encode(cmd)
|
err := json.NewEncoder(b.socket).Encode(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Log.Errorln(err.Error())
|
b.Log.Errorln(err.Error())
|
||||||
@ -331,11 +334,11 @@ func (b *Bsignald) Disconnect() error {
|
|||||||
func (b *Bsignald) Send(msg config.Message) (string, error) {
|
func (b *Bsignald) Send(msg config.Message) (string, error) {
|
||||||
b.Log.Debugf("message to forward into signal: %#v", msg)
|
b.Log.Debugf("message to forward into signal: %#v", msg)
|
||||||
|
|
||||||
msgJSON := signaldSendMessage {
|
msgJSON := signaldSendMessage{
|
||||||
Type: "send",
|
Type: "send",
|
||||||
Username: b.GetString(cfgNumber),
|
Username: b.GetString(cfgNumber),
|
||||||
RecipientGroupId: b.groupid,
|
RecipientGroupId: b.groupid,
|
||||||
MessageBody: msg.Username + msg.Text,
|
MessageBody: msg.Username + msg.Text,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := json.NewEncoder(b.socket).Encode(msgJSON)
|
err := json.NewEncoder(b.socket).Encode(msgJSON)
|
||||||
|
Loading…
Reference in New Issue
Block a user