Fix jid assignments and stuff

This commit is contained in:
Karmanyaah Malhotra 2021-02-28 15:01:32 -05:00
parent a46326cedd
commit b8044adf3f
4 changed files with 21 additions and 10 deletions

View File

@ -160,7 +160,7 @@ type UsernameTemplateArgs struct {
func (bc BridgeConfig) FormatDisplayname(contact groupme.Member) (string, int8) { func (bc BridgeConfig) FormatDisplayname(contact groupme.Member) (string, int8) {
var buf bytes.Buffer var buf bytes.Buffer
if index := strings.IndexRune(contact.ID.String(), '@'); index > 0 { if index := strings.IndexRune(contact.ID.String(), '@'); index > 0 {
contact.ID = groupme.ID("+" + contact.ID.String()[:index]) contact.ID = groupme.ID("+" + contact.UserID.String()[:index])
} }
bc.displaynameTemplate.Execute(&buf, contact) bc.displaynameTemplate.Execute(&buf, contact)
var quality int8 var quality int8
@ -168,7 +168,7 @@ func (bc BridgeConfig) FormatDisplayname(contact groupme.Member) (string, int8)
case len(contact.Nickname) > 0: case len(contact.Nickname) > 0:
quality = 3 quality = 3
//TODO what //TODO what
case len(contact.ID) > 0: case len(contact.UserID) > 0:
quality = 1 quality = 1
default: default:
quality = 0 quality = 0

View File

@ -75,7 +75,7 @@ bridge:
# {{.Short}} - short display name from contact list # {{.Short}} - short display name from contact list
# To use multiple if's, you need to use: {{else if .Name}}, for example: # To use multiple if's, you need to use: {{else if .Name}}, for example:
# "{{if .Notify}}{{.Notify}}{{else if .Name}}{{.Name}}{{else}}{{.Jid}}{{end}} (WA)" # "{{if .Notify}}{{.Notify}}{{else if .Name}}{{.Name}}{{else}}{{.Jid}}{{end}} (WA)"
displayname_template: "{{if .Nickname}}{{.Nickname}}{{else}}{{call .ID.String}}{{end}} (WA)" displayname_template: "{{if .Nickname}}{{.Nickname}}{{else}}{{call .UserID.String}}{{end}} (WA)"
# Localpart template for per-user room grouping community IDs. # Localpart template for per-user room grouping community IDs.
# On startup, the bridge will try to create these communities, add all of the specific user's # On startup, the bridge will try to create these communities, add all of the specific user's
# portals to the community, and invite the Matrix user to it. # portals to the community, and invite the Matrix user to it.

View File

@ -369,11 +369,11 @@ func (portal *Portal) SyncParticipants(metadata *groupme.Group) {
} }
participantMap := make(map[string]bool) participantMap := make(map[string]bool)
for _, participant := range metadata.Members { for _, participant := range metadata.Members {
participantMap[participant.ID.String()] = true participantMap[participant.UserID.String()] = true
user := portal.bridge.GetUserByJID(participant.ID.String()) user := portal.bridge.GetUserByJID(participant.UserID.String())
portal.userMXIDAction(user, portal.ensureMXIDInvited) portal.userMXIDAction(user, portal.ensureMXIDInvited)
puppet := portal.bridge.GetPuppetByJID(participant.ID.String()) puppet := portal.bridge.GetPuppetByJID(participant.UserID.String())
err := puppet.IntentFor(portal).EnsureJoined(portal.MXID) err := puppet.IntentFor(portal).EnsureJoined(portal.MXID)
if err != nil { if err != nil {
portal.log.Warnfln("Failed to make puppet of %s join %s: %v", participant.ID.String(), portal.MXID, err) portal.log.Warnfln("Failed to make puppet of %s join %s: %v", participant.ID.String(), portal.MXID, err)

19
user.go
View File

@ -553,7 +553,7 @@ func (user *User) syncPortals(chatMap map[string]groupme.Group, createAll bool)
existingKeys := user.GetInCommunityMap() existingKeys := user.GetInCommunityMap()
portalKeys := make([]database.PortalKeyWithMeta, 0, len(chatMap)) portalKeys := make([]database.PortalKeyWithMeta, 0, len(chatMap))
for _, chat := range chatMap { for _, chat := range chatMap {
portal := user.GetPortalByJID(chat.ID.String()) portal := user.bridge.GetPortalByJID(database.GroupPortalKey(chat.ID.String()))
chats = append(chats, Chat{ chats = append(chats, Chat{
Portal: portal, Portal: portal,
@ -805,13 +805,12 @@ func (user *User) handleMessageLoop() {
puppet := user.bridge.GetPuppetByJID(msg.data.UserID.String()) puppet := user.bridge.GetPuppetByJID(msg.data.UserID.String())
if puppet != nil { if puppet != nil {
puppet.Sync(user, groupme.Member{ puppet.Sync(user, groupme.Member{
ID: msg.data.ID,
UserID: msg.data.UserID, UserID: msg.data.UserID,
Nickname: msg.data.Name, Nickname: msg.data.Name,
ImageURL: msg.data.AvatarURL, ImageURL: msg.data.AvatarURL,
}) //TODO: add params or docs? }) //TODO: add params or docs?
} }
user.GetPortalByJID(msg.chat).messages <- msg user.bridge.GetPortalByJID(database.GroupPortalKey(msg.chat)).messages <- msg
case <-user.syncStart: case <-user.syncStart:
user.log.Debugln("Processing of incoming messages is locked") user.log.Debugln("Processing of incoming messages is locked")
user.bridge.Metrics.TrackSyncLock(user.JID, true) user.bridge.Metrics.TrackSyncLock(user.JID, true)
@ -851,7 +850,19 @@ func (user *User) handleMessageLoop() {
//} //}
func (user *User) HandleTextMessage(message groupme.Message) { func (user *User) HandleTextMessage(message groupme.Message) {
user.messageInput <- PortalMessage{message.GroupID.String(), user, &message, uint64(message.CreatedAt.ToTime().Unix())} var group bool
var id string
if message.GroupID.String() != "" {
group = true
id = message.GroupID.String()
} else if message.ConversationID.String() != "" {
group = false
id = message.ConversationID.String()
} else {
user.log.Errorln("Message received without conversation or groupid")
return
}
user.messageInput <- PortalMessage{id, group, user, &message, uint64(message.CreatedAt.ToTime().Unix())}
} }
func (user *User) HandleJoin(id groupme.ID) { func (user *User) HandleJoin(id groupme.ID) {