diff --git a/config/bridge.go b/config/bridge.go index dd8fbaa..80ab46a 100644 --- a/config/bridge.go +++ b/config/bridge.go @@ -160,7 +160,7 @@ type UsernameTemplateArgs struct { func (bc BridgeConfig) FormatDisplayname(contact groupme.Member) (string, int8) { var buf bytes.Buffer 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) var quality int8 @@ -168,7 +168,7 @@ func (bc BridgeConfig) FormatDisplayname(contact groupme.Member) (string, int8) case len(contact.Nickname) > 0: quality = 3 //TODO what - case len(contact.ID) > 0: + case len(contact.UserID) > 0: quality = 1 default: quality = 0 diff --git a/example-config.yaml b/example-config.yaml index 5ea0f3d..9b6d5b2 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -75,7 +75,7 @@ bridge: # {{.Short}} - short display name from contact list # 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)" - 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. # 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. diff --git a/portal.go b/portal.go index 748dae5..ae9d937 100644 --- a/portal.go +++ b/portal.go @@ -369,11 +369,11 @@ func (portal *Portal) SyncParticipants(metadata *groupme.Group) { } participantMap := make(map[string]bool) for _, participant := range metadata.Members { - participantMap[participant.ID.String()] = true - user := portal.bridge.GetUserByJID(participant.ID.String()) + participantMap[participant.UserID.String()] = true + user := portal.bridge.GetUserByJID(participant.UserID.String()) 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) if err != nil { portal.log.Warnfln("Failed to make puppet of %s join %s: %v", participant.ID.String(), portal.MXID, err) diff --git a/user.go b/user.go index f887e3f..c685b3e 100644 --- a/user.go +++ b/user.go @@ -553,7 +553,7 @@ func (user *User) syncPortals(chatMap map[string]groupme.Group, createAll bool) existingKeys := user.GetInCommunityMap() portalKeys := make([]database.PortalKeyWithMeta, 0, len(chatMap)) for _, chat := range chatMap { - portal := user.GetPortalByJID(chat.ID.String()) + portal := user.bridge.GetPortalByJID(database.GroupPortalKey(chat.ID.String())) chats = append(chats, Chat{ Portal: portal, @@ -805,13 +805,12 @@ func (user *User) handleMessageLoop() { puppet := user.bridge.GetPuppetByJID(msg.data.UserID.String()) if puppet != nil { puppet.Sync(user, groupme.Member{ - ID: msg.data.ID, UserID: msg.data.UserID, Nickname: msg.data.Name, ImageURL: msg.data.AvatarURL, }) //TODO: add params or docs? } - user.GetPortalByJID(msg.chat).messages <- msg + user.bridge.GetPortalByJID(database.GroupPortalKey(msg.chat)).messages <- msg case <-user.syncStart: user.log.Debugln("Processing of incoming messages is locked") user.bridge.Metrics.TrackSyncLock(user.JID, true) @@ -851,7 +850,19 @@ func (user *User) handleMessageLoop() { //} 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) {