Optimize the synchronization of skype group names without topics
This commit is contained in:
parent
f0c76006f2
commit
0b18b231bb
76
portal.go
76
portal.go
|
@ -533,19 +533,37 @@ func (portal *Portal) UpdateMetadata(user *User) bool {
|
|||
}
|
||||
|
||||
portalName := ""
|
||||
noRoomTopic := false
|
||||
names := strings.Split(metadata.Name, ", ")
|
||||
for _, name := range names {
|
||||
if strings.Index(name, ":") > 0 {
|
||||
key := "8:" + name + skypeExt.NewUserSuffix
|
||||
if key == user.JID {
|
||||
noRoomTopic = true
|
||||
}
|
||||
}
|
||||
if noRoomTopic {
|
||||
for index, participant := range metadata.Participants {
|
||||
fmt.Println()
|
||||
fmt.Printf("metadata.Participants1: %+v", participant)
|
||||
fmt.Println()
|
||||
|
||||
if participant.JID == user.JID {
|
||||
continue
|
||||
}
|
||||
if contact, ok := user.Conn.Store.Contacts[key]; ok {
|
||||
portalName += contact.DisplayName
|
||||
if contact, ok := user.Conn.Store.Contacts[participant.JID]; ok {
|
||||
if len(portalName) == 0 {
|
||||
portalName = contact.DisplayName
|
||||
} else {
|
||||
if index > 5 {
|
||||
portalName = portalName + ", ..."
|
||||
break
|
||||
} else {
|
||||
portalName = portalName + ", " + contact.DisplayName
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(portalName) < 1 {
|
||||
}
|
||||
} else {
|
||||
portalName = metadata.Name
|
||||
}
|
||||
// portal.Topic = ""
|
||||
|
@ -1085,25 +1103,36 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|||
metadata, err = user.Conn.GetGroupMetaData(portal.Key.JID)
|
||||
if err == nil {
|
||||
portalName := ""
|
||||
noRoomTopic := false
|
||||
names := strings.Split(metadata.Name, ", ")
|
||||
for _, name := range names {
|
||||
if strings.Index(name, ":") > 0 {
|
||||
key := "8:" + name + skypeExt.NewUserSuffix
|
||||
if key == user.JID {
|
||||
noRoomTopic = true
|
||||
}
|
||||
}
|
||||
if noRoomTopic {
|
||||
for index, participant := range metadata.Participants {
|
||||
fmt.Println()
|
||||
fmt.Printf("metadata.Participants2: %+v", participant)
|
||||
fmt.Println()
|
||||
|
||||
if participant.JID == user.JID {
|
||||
continue
|
||||
}
|
||||
if contact, ok := user.Conn.Store.Contacts[key]; ok {
|
||||
if len(portalName) > 0 {
|
||||
portalName = portalName + ", " + contact.DisplayName
|
||||
} else {
|
||||
if contact, ok := user.Conn.Store.Contacts[participant.JID]; ok {
|
||||
if len(portalName) == 0 {
|
||||
portalName = contact.DisplayName
|
||||
}
|
||||
}
|
||||
} else if name == "..." {
|
||||
} else {
|
||||
if index > 5 {
|
||||
portalName = portalName + ", ..."
|
||||
break
|
||||
} else {
|
||||
portalName = portalName + ", " + contact.DisplayName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(portalName) > 0 {
|
||||
portal.Name = portalName
|
||||
} else {
|
||||
portal.Name = metadata.Name
|
||||
|
@ -2391,6 +2420,27 @@ func (portal *Portal) GetMatrixUsers() ([]id.UserID, error) {
|
|||
return users, nil
|
||||
}
|
||||
|
||||
func (portal *Portal) GetPuppets() ([]struct {
|
||||
DisplayName *string `json:"display_name"`
|
||||
AvatarURL *string `json:"avatar_url"`
|
||||
}, error) {
|
||||
members, err := portal.MainIntent().JoinedMembers(portal.MXID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get member list")
|
||||
}
|
||||
var puppets []struct {
|
||||
DisplayName *string `json:"display_name"`
|
||||
AvatarURL *string `json:"avatar_url"`
|
||||
}
|
||||
for userID := range members.Joined {
|
||||
_, isPuppet := portal.bridge.ParsePuppetMXID(userID)
|
||||
if isPuppet && userID != portal.bridge.Bot.UserID {
|
||||
puppets = append(puppets, members.Joined[userID])
|
||||
}
|
||||
}
|
||||
return puppets, nil
|
||||
}
|
||||
|
||||
func (portal *Portal) CleanupIfEmpty() {
|
||||
users, err := portal.GetMatrixUsers()
|
||||
if err != nil {
|
||||
|
|
30
user.go
30
user.go
|
@ -1007,8 +1007,36 @@ func (user *User) HandleChatUpdate(cmd skype.Resource) {
|
|||
topicContent := skype.ChatTopicContent{}
|
||||
//把xml数据解析成bs对象
|
||||
xml.Unmarshal([]byte(cmd.Content), &topicContent)
|
||||
portalName := ""
|
||||
noRoomTopic := false
|
||||
names := strings.Split(cmd.ThreadTopic, ", ")
|
||||
for _, name := range names {
|
||||
key := "8:" + name + skypeExt.NewUserSuffix
|
||||
if key == user.JID {
|
||||
noRoomTopic = true
|
||||
}
|
||||
}
|
||||
if noRoomTopic {
|
||||
participants, _ := portal.GetPuppets()
|
||||
for index, participant := range participants {
|
||||
if *participant.DisplayName != user.Conn.LoginInfo.Username {
|
||||
if len(portalName) == 0 {
|
||||
portalName = *participant.DisplayName
|
||||
} else {
|
||||
if index > 5 {
|
||||
portalName = portalName + ", ..."
|
||||
break
|
||||
} else {
|
||||
portalName = *participant.DisplayName + ", " + portalName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
portalName = cmd.ThreadTopic
|
||||
}
|
||||
cmd.SendId = topicContent.Initiator + skypeExt.NewUserSuffix
|
||||
go portal.UpdateName(cmd.ThreadTopic, cmd.SendId)
|
||||
go portal.UpdateName(portalName, cmd.SendId)
|
||||
case skypeExt.ChatPictureUpdate:
|
||||
topicContent := skype.ChatPictureContent{}
|
||||
//把xml数据解析成bs对象
|
||||
|
|
Loading…
Reference in New Issue