Rename package, bump Go to 1.22

This commit is contained in:
Jarno Rankinen 2024-03-24 14:22:00 +02:00
parent 2e905544ae
commit f3f6b8e23f
18 changed files with 75 additions and 69 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
__debug_bin*
config.yaml
registration.yaml
logs/
matrix-skype.db

View File

@ -5,9 +5,9 @@ import (
"fmt" "fmt"
"math" "math"
"github.com/0ranki/matrix-skype/database"
skypeExt "github.com/0ranki/matrix-skype/skype-ext"
skype "github.com/kelaresg/go-skypeapi" skype "github.com/kelaresg/go-skypeapi"
"github.com/kelaresg/matrix-skype/database"
skypeExt "github.com/kelaresg/matrix-skype/skype-ext"
"maunium.net/go/mautrix/patch" "maunium.net/go/mautrix/patch"
"sort" "sort"
@ -388,8 +388,8 @@ func (handler *CommandHandler) CommandPing(ce *CommandEvent) {
} }
ce.Reply("You're logged in as @" + username + ", orgid is " + orgId) ce.Reply("You're logged in as @" + username + ", orgid is " + orgId)
} }
var password string; var password string
var username string; var username string
ret := ce.User.bridge.DB.User.GetCredentialsByMXID(ce.User.MXID, &password, &username) ret := ce.User.bridge.DB.User.GetCredentialsByMXID(ce.User.MXID, &password, &username)
if ret && password != "" { if ret && password != "" {
ce.Reply("WARNING, your password is stored in database. Use command `remove-password` to remove it.") ce.Reply("WARNING, your password is stored in database. Use command `remove-password` to remove it.")

View File

@ -11,7 +11,7 @@ import (
"maunium.net/go/mautrix/event" "maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id" "maunium.net/go/mautrix/id"
"github.com/kelaresg/matrix-skype/types" "github.com/0ranki/matrix-skype/types"
) )
type BridgeConfig struct { type BridgeConfig struct {
@ -42,7 +42,7 @@ type BridgeConfig struct {
SyncChatMaxAge uint64 `yaml:"sync_max_chat_age"` SyncChatMaxAge uint64 `yaml:"sync_max_chat_age"`
SyncContact bool `yaml:"sync_contact"` SyncContact bool `yaml:"sync_contact"`
SyncWithCustomPuppets bool `yaml:"sync_with_custom_puppets"` SyncWithCustomPuppets bool `yaml:"sync_with_custom_puppets"`
InviteOwnPuppetForBackfilling bool `yaml:"invite_own_puppet_for_backfilling"` InviteOwnPuppetForBackfilling bool `yaml:"invite_own_puppet_for_backfilling"`
PrivateChatPortalMeta bool `yaml:"private_chat_portal_meta"` PrivateChatPortalMeta bool `yaml:"private_chat_portal_meta"`
@ -68,7 +68,7 @@ type BridgeConfig struct {
} `yaml:"key_sharing"` } `yaml:"key_sharing"`
PuppetId struct { PuppetId struct {
Allow bool `yaml:"allow"` Allow bool `yaml:"allow"`
Key string `yaml:"key"` Key string `yaml:"key"`
UsernameTemplatePrefix string `yaml:"username_template_prefix"` UsernameTemplatePrefix string `yaml:"username_template_prefix"`
} `yaml:"puppet_id"` } `yaml:"puppet_id"`

View File

@ -30,7 +30,7 @@ import (
"maunium.net/go/mautrix/event" "maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id" "maunium.net/go/mautrix/id"
"github.com/kelaresg/matrix-skype/database" "github.com/0ranki/matrix-skype/database"
) )
var levelTrace = maulogger.Level{ var levelTrace = maulogger.Level{

View File

@ -24,7 +24,7 @@ import (
log "maunium.net/go/maulogger/v2" log "maunium.net/go/maulogger/v2"
"github.com/kelaresg/matrix-skype/database/upgrades" "github.com/0ranki/matrix-skype/database/upgrades"
) )
type Database struct { type Database struct {

View File

@ -6,7 +6,7 @@ import (
"encoding/json" "encoding/json"
log "maunium.net/go/maulogger/v2" log "maunium.net/go/maulogger/v2"
"github.com/kelaresg/matrix-skype/types" "github.com/0ranki/matrix-skype/types"
"maunium.net/go/mautrix/id" "maunium.net/go/mautrix/id"
) )
@ -35,27 +35,27 @@ func (mq *MessageQuery) GetAll(chat PortalKey) (messages []*Message) {
} }
func (mq *MessageQuery) GetByJID(chat PortalKey, jid types.SkypeMessageID) *Message { func (mq *MessageQuery) GetByJID(chat PortalKey, jid types.SkypeMessageID) *Message {
return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content " + return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content "+
"FROM message WHERE chat_jid=$1 AND jid=$2", chat.JID, jid) "FROM message WHERE chat_jid=$1 AND jid=$2", chat.JID, jid)
} }
func (mq *MessageQuery) oldGetByJID(chat PortalKey, jid types.SkypeMessageID) *Message { func (mq *MessageQuery) oldGetByJID(chat PortalKey, jid types.SkypeMessageID) *Message {
return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content " + return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content "+
"FROM message WHERE chat_jid=$1 AND chat_receiver=$2 AND jid=$3", chat.JID, chat.Receiver, jid) "FROM message WHERE chat_jid=$1 AND chat_receiver=$2 AND jid=$3", chat.JID, chat.Receiver, jid)
} }
func (mq *MessageQuery) GetByMXID(mxid id.EventID) *Message { func (mq *MessageQuery) GetByMXID(mxid id.EventID) *Message {
return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content " + return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content "+
"FROM message WHERE mxid=$1", mxid) "FROM message WHERE mxid=$1", mxid)
} }
func (mq *MessageQuery) GetByID(id string) *Message { func (mq *MessageQuery) GetByID(id string) *Message {
return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content " + return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content "+
"FROM message WHERE id=$1", id) "FROM message WHERE id=$1", id)
} }
func (mq *MessageQuery) GetLastInChat(chat PortalKey) *Message { func (mq *MessageQuery) GetLastInChat(chat PortalKey) *Message {
msg := mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content " + msg := mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content "+
"FROM message WHERE chat_jid=$1 AND chat_receiver=$2 ORDER BY timestamp DESC LIMIT 1", chat.JID, chat.Receiver) "FROM message WHERE chat_jid=$1 AND chat_receiver=$2 ORDER BY timestamp DESC LIMIT 1", chat.JID, chat.Receiver)
if msg == nil || msg.Timestamp == 0 { if msg == nil || msg.Timestamp == 0 {
// Old db, we don't know what the last message is. // Old db, we don't know what the last message is.
@ -122,7 +122,7 @@ func (msg *Message) encodeBinaryContent() []byte {
} }
func (msg *Message) Insert() { func (msg *Message) Insert() {
_, err := msg.db.Exec("INSERT INTO message (id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content) " + _, err := msg.db.Exec("INSERT INTO message (id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content) "+
"VALUES ($1, $2, $3, $4, $5, $6, $7, $8)", "VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
msg.ID, msg.Chat.JID, msg.Chat.Receiver, msg.JID, msg.MXID, msg.Sender, msg.Timestamp, msg.encodeBinaryContent()) msg.ID, msg.Chat.JID, msg.Chat.Receiver, msg.JID, msg.MXID, msg.Sender, msg.Timestamp, msg.encodeBinaryContent())
if err != nil { if err != nil {

View File

@ -2,14 +2,14 @@ package database
import ( import (
"database/sql" "database/sql"
skypeExt "github.com/kelaresg/matrix-skype/skype-ext" skypeExt "github.com/0ranki/matrix-skype/skype-ext"
"strings" "strings"
log "maunium.net/go/maulogger/v2" log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/id" "maunium.net/go/mautrix/id"
"github.com/kelaresg/matrix-skype/types" "github.com/0ranki/matrix-skype/types"
) )
type PortalKey struct { type PortalKey struct {

View File

@ -5,7 +5,7 @@ import (
log "maunium.net/go/maulogger/v2" log "maunium.net/go/maulogger/v2"
"github.com/kelaresg/matrix-skype/types" "github.com/0ranki/matrix-skype/types"
"maunium.net/go/mautrix/id" "maunium.net/go/mautrix/id"
) )

View File

@ -3,14 +3,14 @@ package database
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
skypeExt "github.com/0ranki/matrix-skype/skype-ext"
skype "github.com/kelaresg/go-skypeapi" skype "github.com/kelaresg/go-skypeapi"
skypeExt "github.com/kelaresg/matrix-skype/skype-ext"
"strings" "strings"
"time" "time"
log "maunium.net/go/maulogger/v2" log "maunium.net/go/maulogger/v2"
"github.com/kelaresg/matrix-skype/types" "github.com/0ranki/matrix-skype/types"
"maunium.net/go/mautrix/id" "maunium.net/go/mautrix/id"
) )

View File

@ -6,13 +6,13 @@ import (
"regexp" "regexp"
"strings" "strings"
skypeExt "github.com/kelaresg/matrix-skype/skype-ext" skypeExt "github.com/0ranki/matrix-skype/skype-ext"
"maunium.net/go/mautrix/event" "maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/format" "maunium.net/go/mautrix/format"
"maunium.net/go/mautrix/id" "maunium.net/go/mautrix/id"
"github.com/kelaresg/matrix-skype/types" "github.com/0ranki/matrix-skype/types"
) )
var italicRegex = regexp.MustCompile("([\\s>~*]|^)_(.+?)_([^a-zA-Z\\d]|$)") var italicRegex = regexp.MustCompile("([\\s>~*]|^)_(.+?)_([^a-zA-Z\\d]|$)")
@ -20,8 +20,8 @@ var boldRegex = regexp.MustCompile("([\\s>_~]|^)\\*(.+?)\\*([^a-zA-Z\\d]|$)")
var strikethroughRegex = regexp.MustCompile("([\\s>_*]|^)~(.+?)~([^a-zA-Z\\d]|$)") var strikethroughRegex = regexp.MustCompile("([\\s>_*]|^)~(.+?)~([^a-zA-Z\\d]|$)")
var codeBlockRegex = regexp.MustCompile("```(?:.|\n)+?```") var codeBlockRegex = regexp.MustCompile("```(?:.|\n)+?```")
//var mentionRegex = regexp.MustCompile("@[0-9]+") // var mentionRegex = regexp.MustCompile("@[0-9]+")
//var mentionRegex = regexp.MustCompile("@(.*)") // var mentionRegex = regexp.MustCompile("@(.*)")
var mentionRegex = regexp.MustCompile("<at[^>]+\\bid=\"([^\"]+)\"(.*?)</at>*") var mentionRegex = regexp.MustCompile("<at[^>]+\\bid=\"([^\"]+)\"(.*?)</at>*")
type Formatter struct { type Formatter struct {
@ -81,8 +81,7 @@ func NewFormatter(bridge *Bridge) *Formatter {
return fmt.Sprintf("<code>%s</code>", str) return fmt.Sprintf("<code>%s</code>", str)
}, },
} }
formatter.waReplFuncText = map[*regexp.Regexp]func(string) string{ formatter.waReplFuncText = map[*regexp.Regexp]func(string) string{}
}
return formatter return formatter
} }
@ -99,7 +98,7 @@ func (formatter *Formatter) getMatrixInfoByJID(jid types.SkypeID) (mxid id.UserI
func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomMXID id.RoomID) { func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomMXID id.RoomID) {
// parse '<a><a/>' tag // parse '<a><a/>' tag
reg:= regexp.MustCompile(`(?U)(<a .*>(.*)</a>)`) reg := regexp.MustCompile(`(?U)(<a .*>(.*)</a>)`)
bodyMatch := reg.FindAllStringSubmatch(content.Body, -1) bodyMatch := reg.FindAllStringSubmatch(content.Body, -1)
for _, match := range bodyMatch { for _, match := range bodyMatch {
content.Body = strings.ReplaceAll(content.Body, match[1], match[2]) content.Body = strings.ReplaceAll(content.Body, match[1], match[2])
@ -139,7 +138,7 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomM
content.Body = fmt.Sprintf("%s\n\n", match[6]) content.Body = fmt.Sprintf("%s\n\n", match[6])
// this means that there are forwarding messages across groups // this means that there are forwarding messages across groups
if strings.HasSuffix(match[4], skypeExt.GroupSuffix) || strings.HasSuffix(portal.Key.JID, skypeExt.GroupSuffix){ if strings.HasSuffix(match[4], skypeExt.GroupSuffix) || strings.HasSuffix(portal.Key.JID, skypeExt.GroupSuffix) {
continue continue
} }
} }
@ -159,7 +158,7 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomM
content.FormattedBody = newContent content.FormattedBody = newContent
content.Body = fmt.Sprintf("> <%s> %s\n\n", mxid, match[6]) content.Body = fmt.Sprintf("> <%s> %s\n\n", mxid, match[6])
inRelateTo := &event.RelatesTo{ inRelateTo := &event.RelatesTo{
Type: event.RelReply, Type: event.RelReply,
EventID: id.EventID(msgMXID), EventID: id.EventID(msgMXID),
} }
content.SetRelatesTo(inRelateTo) content.SetRelatesTo(inRelateTo)
@ -190,7 +189,7 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomM
} }
// number := "@" + strings.Replace(match[1], skypeExt.NewUserSuffix, "", 1) // number := "@" + strings.Replace(match[1], skypeExt.NewUserSuffix, "", 1)
originStr = strings.ReplaceAll(originStr, match[0], replaceStr) originStr = strings.ReplaceAll(originStr, match[0], replaceStr)
originBodyStr = strings.ReplaceAll(originStr, replaceStr, displayname + ":") originBodyStr = strings.ReplaceAll(originStr, replaceStr, displayname+":")
} }
if len(backStr) == 0 { if len(backStr) == 0 {
content.Format = event.FormatHTML content.Format = event.FormatHTML

View File

@ -1,8 +1,8 @@
package main package main
import ( import (
"github.com/kelaresg/matrix-skype/database" "github.com/0ranki/matrix-skype/database"
"github.com/kelaresg/matrix-skype/types" "github.com/0ranki/matrix-skype/types"
"maunium.net/go/mautrix/event" "maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/format" "maunium.net/go/mautrix/format"
"reflect" "reflect"

6
go.mod
View File

@ -1,13 +1,13 @@
module github.com/kelaresg/matrix-skype module github.com/0ranki/matrix-skype
go 1.18 go 1.22
require ( require (
github.com/gabriel-vasile/mimetype v1.1.2 github.com/gabriel-vasile/mimetype v1.1.2
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/kelaresg/go-skypeapi v0.1.2-0.20210813144457-5bc29092a74e github.com/kelaresg/go-skypeapi v0.1.2-0.20210813144457-5bc29092a74e
github.com/lib/pq v1.9.0 github.com/lib/pq v1.9.0
github.com/mattn/go-sqlite3 v2.0.3+incompatible github.com/mattn/go-sqlite3 v1.14.22
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v2 v2.4.0
maunium.net/go/mauflag v1.0.0 maunium.net/go/mauflag v1.0.0

2
go.sum
View File

@ -151,6 +151,8 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U= github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=

10
main.go
View File

@ -17,10 +17,10 @@ import (
"maunium.net/go/mautrix/event" "maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id" "maunium.net/go/mautrix/id"
"github.com/kelaresg/matrix-skype/config" "github.com/0ranki/matrix-skype/config"
"github.com/kelaresg/matrix-skype/database" "github.com/0ranki/matrix-skype/database"
"github.com/kelaresg/matrix-skype/database/upgrades" "github.com/0ranki/matrix-skype/database/upgrades"
"github.com/kelaresg/matrix-skype/types" "github.com/0ranki/matrix-skype/types"
) )
var ( var (
@ -48,7 +48,7 @@ func init() {
var configPath = flag.MakeFull("c", "config", "The path to your config file.", "config.yaml").String() var configPath = flag.MakeFull("c", "config", "The path to your config file.", "config.yaml").String()
//var baseConfigPath = flag.MakeFull("b", "base-config", "The path to the example config file.", "example-config.yaml").String() // var baseConfigPath = flag.MakeFull("b", "base-config", "The path to the example config file.", "example-config.yaml").String()
var registrationPath = flag.MakeFull("r", "registration", "The path where to save the appservice registration.", "registration.yaml").String() var registrationPath = flag.MakeFull("r", "registration", "The path where to save the appservice registration.", "registration.yaml").String()
var generateRegistration = flag.MakeFull("g", "generate-registration", "Generate registration and quit.", "false").Bool() var generateRegistration = flag.MakeFull("g", "generate-registration", "Generate registration and quit.", "false").Bool()
var version = flag.MakeFull("v", "version", "View bridge version and quit.", "false").Bool() var version = flag.MakeFull("v", "version", "View bridge version and quit.", "false").Bool()

View File

@ -6,8 +6,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/0ranki/matrix-skype/database"
skype "github.com/kelaresg/go-skypeapi" skype "github.com/kelaresg/go-skypeapi"
"github.com/kelaresg/matrix-skype/database"
"maunium.net/go/mautrix" "maunium.net/go/mautrix"
"maunium.net/go/mautrix/patch" "maunium.net/go/mautrix/patch"
@ -398,7 +398,7 @@ func (mx *MatrixHandler) HandleMessage(evt *event.Event) {
} }
if hasCommandPrefix || evt.RoomID == user.ManagementRoom { if hasCommandPrefix || evt.RoomID == user.ManagementRoom {
mx.cmd.Handle(evt.RoomID, user, content.Body) mx.cmd.Handle(evt.RoomID, user, content.Body)
if strings.HasPrefix(content.Body, "login") == true { if strings.HasPrefix(content.Body, "login") == true {
go func() { go func() {
time.Sleep(time.Second * 10) time.Sleep(time.Second * 10)
customPuppet := user.bridge.GetPuppetByJID(user.JID) customPuppet := user.bridge.GetPuppetByJID(user.JID)

View File

@ -23,8 +23,8 @@ import (
"sync" "sync"
"time" "time"
skypeExt "github.com/0ranki/matrix-skype/skype-ext"
skype "github.com/kelaresg/go-skypeapi" skype "github.com/kelaresg/go-skypeapi"
skypeExt "github.com/kelaresg/matrix-skype/skype-ext"
"github.com/pkg/errors" "github.com/pkg/errors"
log "maunium.net/go/maulogger/v2" log "maunium.net/go/maulogger/v2"
@ -36,8 +36,8 @@ import (
"maunium.net/go/mautrix/id" "maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/pushrules" "maunium.net/go/mautrix/pushrules"
"github.com/kelaresg/matrix-skype/database" "github.com/0ranki/matrix-skype/database"
"github.com/kelaresg/matrix-skype/types" "github.com/0ranki/matrix-skype/types"
) )
func (bridge *Bridge) GetPortalByMXID(mxid id.RoomID) *Portal { func (bridge *Bridge) GetPortalByMXID(mxid id.RoomID) *Portal {
@ -409,13 +409,13 @@ func (portal *Portal) SyncParticipants(user *User, metadata *skypeExt.GroupInfo)
for _, participant := range metadata.Participants { for _, participant := range metadata.Participants {
portal.log.Debugln("SyncParticipants: participant.JID= ", participant.JID) portal.log.Debugln("SyncParticipants: participant.JID= ", participant.JID)
// When synchronizing Skype room members, first look up whether there is a corresponding record in the user table. // When synchronizing Skype room members, first look up whether there is a corresponding record in the user table.
// If there is, there are two possibilities: // If there is, there are two possibilities:
// 1. This member is the puppet of the skype account A that you are currently importing, // 1. This member is the puppet of the skype account A that you are currently importing,
// and has a corresponding matrix account // and has a corresponding matrix account
// 2. This member is a puppet of other people's skype account B. // 2. This member is a puppet of other people's skype account B.
// the other people have registered a matrix account in the same matrix server // the other people have registered a matrix account in the same matrix server
// and have also synchronized (bridged) skype account B. skype A and skype B are in the same skype room. // and have also synchronized (bridged) skype account B. skype A and skype B are in the same skype room.
participantUser := portal.bridge.GetUserByJID(participant.JID) participantUser := portal.bridge.GetUserByJID(participant.JID)
if participantUser != nil { if participantUser != nil {
@ -614,7 +614,7 @@ func (portal *Portal) userMXIDAction(user *User, fn func(mxid id.UserID)) {
} }
func (portal *Portal) ensureMXIDInvited(mxid id.UserID) { func (portal *Portal) ensureMXIDInvited(mxid id.UserID) {
portal.log.Debugfln("ensureMXIDInvited portal.MXID %s: %s", portal.MXID, mxid); portal.log.Debugfln("ensureMXIDInvited portal.MXID %s: %s", portal.MXID, mxid)
err := portal.MainIntent().EnsureInvited(portal.MXID, mxid) err := portal.MainIntent().EnsureInvited(portal.MXID, mxid)
if err != nil { if err != nil {
portal.log.Warnfln("Failed to ensure %s is invited to %s: %v", mxid, portal.MXID, err) portal.log.Warnfln("Failed to ensure %s is invited to %s: %v", mxid, portal.MXID, err)
@ -1152,7 +1152,7 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
portal.Name = portalName portal.Name = portalName
} else { } else {
portal.Name = metadata.Name portal.Name = metadata.Name
if (user.currentCreateRoomName == portal.Name && portal.Name != "") { if user.currentCreateRoomName == portal.Name && portal.Name != "" {
return errors.New("It looks like a room is being created in the matrix using command 'create', so there is no need to create a new room here.") return errors.New("It looks like a room is being created in the matrix using command 'create', so there is no need to create a new room here.")
} }
} }

View File

@ -2,21 +2,21 @@ package main
import ( import (
"fmt" "fmt"
skypeExt "github.com/0ranki/matrix-skype/skype-ext"
skype "github.com/kelaresg/go-skypeapi" skype "github.com/kelaresg/go-skypeapi"
skypeExt "github.com/kelaresg/matrix-skype/skype-ext"
"net/http" "net/http"
"regexp" "regexp"
"sync"
"strings" "strings"
"sync"
log "maunium.net/go/maulogger/v2" log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/appservice" "maunium.net/go/mautrix/appservice"
"maunium.net/go/mautrix/id" "maunium.net/go/mautrix/id"
"github.com/kelaresg/matrix-skype/database" "github.com/0ranki/matrix-skype/database"
"github.com/kelaresg/matrix-skype/types" "github.com/0ranki/matrix-skype/types"
//"github.com/kelaresg/matrix-skype/whatsapp-ext" //"github.com/0ranki/matrix-skype/whatsapp-ext"
) )
func (bridge *Bridge) ParsePuppetMXID(mxid id.UserID) (types.SkypeID, bool) { func (bridge *Bridge) ParsePuppetMXID(mxid id.UserID) (types.SkypeID, bool) {
@ -36,7 +36,7 @@ func (bridge *Bridge) ParsePuppetMXID(mxid id.UserID) (types.SkypeID, bool) {
cond2 := "8-" cond2 := "8-"
if strings.HasPrefix(realId, cond1) { if strings.HasPrefix(realId, cond1) {
realId = strings.Replace(realId, cond1, "8:live:", 1) realId = strings.Replace(realId, cond1, "8:live:", 1)
} else if strings.HasPrefix(realId, cond2){ } else if strings.HasPrefix(realId, cond2) {
realId = strings.Replace(realId, cond2, "8:", 1) realId = strings.Replace(realId, cond2, "8:", 1)
} }
jid := types.SkypeID(realId + skypeExt.NewUserSuffix) jid := types.SkypeID(realId + skypeExt.NewUserSuffix)
@ -140,8 +140,8 @@ func (bridge *Bridge) NewPuppet(dbPuppet *database.Puppet) *Puppet {
":", ":",
"-", "-",
-1, -1,
),
), ),
),
bridge.Config.Homeserver.Domain), bridge.Config.Homeserver.Domain),
} }
} }
@ -172,13 +172,13 @@ func (puppet *Puppet) IntentFor(portal *Portal) *appservice.IntentAPI {
puppet.log.Debugln("puppent IntentFor: %+v", puppet) puppet.log.Debugln("puppent IntentFor: %+v", puppet)
if (!portal.IsPrivateChat() && puppet.customIntent == nil) || if (!portal.IsPrivateChat() && puppet.customIntent == nil) ||
(portal.backfilling && portal.bridge.Config.Bridge.InviteOwnPuppetForBackfilling) || (portal.backfilling && portal.bridge.Config.Bridge.InviteOwnPuppetForBackfilling) ||
portal.Key.JID + skypeExt.NewUserSuffix == puppet.JID { portal.Key.JID+skypeExt.NewUserSuffix == puppet.JID {
puppet.log.Debugln("puppent IntentFor0:", portal.Key.JID, puppet.JID) puppet.log.Debugln("puppent IntentFor0:", portal.Key.JID, puppet.JID)
puppet.log.Debugln("puppent IntentFor0:", portal.Key.JID, puppet.JID) puppet.log.Debugln("puppent IntentFor0:", portal.Key.JID, puppet.JID)
return puppet.DefaultIntent() return puppet.DefaultIntent()
} }
puppet.log.Debugln("puppent IntentFor2: %+v", puppet.customIntent) puppet.log.Debugln("puppent IntentFor2: %+v", puppet.customIntent)
if portal.IsPrivateChat() && puppet.customIntent == nil{ if portal.IsPrivateChat() && puppet.customIntent == nil {
return puppet.DefaultIntent() return puppet.DefaultIntent()
} }
return puppet.customIntent return puppet.customIntent
@ -309,8 +309,8 @@ func (puppet *Puppet) Sync(source *User, contact skype.Contact) {
// contact.Notify = source.Conn.Info.Pushname // contact.Notify = source.Conn.Info.Pushname
//} //}
avatar := &skypeExt.ProfilePicInfo{ avatar := &skypeExt.ProfilePicInfo{
URL: contact.Profile.AvatarUrl, URL: contact.Profile.AvatarUrl,
Tag: contact.Profile.AvatarUrl, Tag: contact.Profile.AvatarUrl,
Status: 0, Status: 0,
} }
update := false update := false

12
user.go
View File

@ -7,8 +7,8 @@ import (
"fmt" "fmt"
"sort" "sort"
skypeExt "github.com/0ranki/matrix-skype/skype-ext"
skype "github.com/kelaresg/go-skypeapi" skype "github.com/kelaresg/go-skypeapi"
skypeExt "github.com/kelaresg/matrix-skype/skype-ext"
"maunium.net/go/mautrix/patch" "maunium.net/go/mautrix/patch"
//"strconv" //"strconv"
@ -25,9 +25,9 @@ import (
"maunium.net/go/mautrix/event" "maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id" "maunium.net/go/mautrix/id"
"github.com/kelaresg/matrix-skype/database" "github.com/0ranki/matrix-skype/database"
"github.com/kelaresg/matrix-skype/types" "github.com/0ranki/matrix-skype/types"
//"github.com/kelaresg/matrix-skype/whatsapp-ext" //"github.com/0ranki/matrix-skype/whatsapp-ext"
) )
type User struct { type User struct {
@ -56,7 +56,7 @@ type User struct {
mgmtCreateLock sync.Mutex mgmtCreateLock sync.Mutex
contactsPresence map[string]*skypeExt.Presence contactsPresence map[string]*skypeExt.Presence
currentCreateRoomName string currentCreateRoomName string
} }
@ -657,7 +657,7 @@ func (user *User) syncPuppets(contacts map[string]skype.Contact, toHomeserver bo
user.log.Infoln("Syncing puppet info from contacts", personId, skypeExt.NewUserSuffix) user.log.Infoln("Syncing puppet info from contacts", personId, skypeExt.NewUserSuffix)
if strings.HasSuffix(personId, skypeExt.NewUserSuffix) { if strings.HasSuffix(personId, skypeExt.NewUserSuffix) {
puppet := user.bridge.GetPuppetByJID(personId) puppet := user.bridge.GetPuppetByJID(personId)
if (!toHomeserver) { if !toHomeserver {
puppet.Sync(user, contact) puppet.Sync(user, contact)
} }
matrixContacts = append(matrixContacts, string(puppet.MXID)) matrixContacts = append(matrixContacts, string(puppet.MXID))