Fixed bug where users were not authenticated until restart
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Brandon Watson 2023-09-15 16:49:25 -05:00
parent f32d3f1668
commit b067459739
2 changed files with 16 additions and 111 deletions

102
portal.go
View File

@ -189,8 +189,6 @@ func (portal *Portal) SyncDM(user *User, dm *groupme.Chat) {
}
update := false
update = portal.updateMetadata(user) || update
update = portal.UpdateAvatar(user, dm.OtherUser.AvatarURL, false) || update
if update {
@ -618,7 +616,6 @@ func (portal *Portal) handleMessage(msg PortalMessage) {
return
}
portal.HandleTextMessage(msg.source, msg.data)
portal.handleReaction(msg.data.ID, msg.data.SenderID, msg.data.FavoritedBy)
}
func (portal *Portal) handleAttachment(intent *appservice.IntentAPI, attachment *groupme.Attachment, source *User, message *groupme.Message) (msg *event.MessageEventContent, sendText bool, err error) {
@ -794,91 +791,6 @@ func (portal *Portal) handleAttachment(intent *appservice.IntentAPI, attachment
// return nil, true, errors.New("Unknown type")
}
func (portal *Portal) handleReaction(msgID groupme.ID, senderId groupme.ID, ppl []string) {
fmt.Println("hello")
//reactions := portal.bridge.DB.Reaction.GetByTargetGMID(portal.Key, msgID, senderId)
//newLikes := newReactions(reactions, ppl)
//removeLikes := oldReactions(reactions, ppl)
//
//var eventID id.EventID
//if len(newLikes) > 0 {
// message := portal.bridge.DB.Message.GetByGMID(portal.Key, msgID)
// if message == nil {
// portal.log.Errorln("Received reaction for unknown message", msgID)
// return
// }
// eventID = message.MXID
//}
//
//for _, gmid := range newLikes {
// intent := portal.getReactionIntent(gmid)
// resp, err := portal.sendReaction(intent, eventID, "❤")
// if err != nil {
// portal.log.Errorln("Something wrong with sending reaction", msgID, gmid, err)
// continue
// }
//
// newReaction := portal.bridge.DB.Reaction.New()
// newReaction.MXID = resp.EventID
// newReaction.GMID = msgID
// newReaction.MXID = eventID
// newReaction.Chat.GMID = gmid
//
// portal.bridge.DB.Reaction.Insert()
// newReaction.Insert()
//
//}
//
//for _, reaction := range removeLikes {
// if len(reaction.Chat.GMID) == 0 {
// portal.log.Warnln("Reaction user state wrong", reaction.MXID, msgID)
// continue
// }
// intent := portal.getReactionIntent(reaction.Chat.GMID)
// _, err := intent.RedactEvent(portal.MXID, reaction.MXID)
// if err != nil {
// portal.log.Errorln("Something wrong with reaction redaction", reaction.MXID)
// continue
// }
// reaction.Delete()
//
//}
}
//func oldReactions(a []*database.Reaction, b []string) (ans []*database.Reaction) {
// for _, i := range a {
// flag := false
// for _, j := range b {
// if i.Chat.GMID == j {
// flag = true
// break
// }
// }
// if !flag {
// ans = append(ans, i)
// }
// }
//
// return
//}
//
//func newReactions(a []*database.Reaction, b []string) (ans []string) {
// for _, j := range b {
// flag := false
// for _, i := range a {
// if i.PuppetJID == j {
// flag = true
// break
// }
// }
// if !flag {
// ans = append(ans, j)
// }
// }
//
// return
//}
// Private Methods
func (portal *Portal) createMatrixRoom(user *User) error {
@ -911,18 +823,14 @@ func (portal *Portal) createMatrixRoom(user *User) error {
Type: event.StateHalfShotBridge,
Content: event.Content{Parsed: bridgeInfo},
StateKey: &bridgeInfoStateKey,
}}
spaceIDStr := user.SpaceId
initialState = append(initialState, &event.Event{
}, {
Type: event.StateSpaceParent,
StateKey: &spaceIDStr,
StateKey: &user.SpaceId,
Content: event.Content{Parsed: &event.SpaceParentEventContent{
Via: []string{portal.bridge.AS.HomeserverDomain},
Canonical: true,
}},
})
initialState = append(initialState, &event.Event{
}, {
Type: event.StateJoinRules,
Content: event.Content{Parsed: &event.JoinRulesEventContent{
JoinRule: event.JoinRuleRestricted,
@ -931,7 +839,9 @@ func (portal *Portal) createMatrixRoom(user *User) error {
Type: event.JoinRuleAllowRoomMembership,
}},
}},
})
}}
//initialState = append(initialState, event.Event)
if !portal.AvatarURL.IsEmpty() {
initialState = append(initialState, &event.Event{
Type: event.StateRoomAvatar,

25
user.go
View File

@ -226,8 +226,8 @@ func (user *User) Login(token string) error {
user.Token = token
user.addToGMIDMap()
user.PostLogin()
if user.Connect() {
user.PostLogin()
return nil
}
return errors.New("failed to connect")
@ -260,6 +260,14 @@ func (user *User) Connect() bool {
conn := groupme.NewPushSubscription(context.Background())
user.Conn = &conn
user.Conn.StartListening(context.Background(), groupmeext.NewFayeClient(user.log))
user.Client = groupmeext.NewClient(user.Token)
if len(user.GMID) == 0 {
myuser, err := user.Client.MyUser(context.TODO())
if err != nil {
log.Fatal(err) //TODO
}
user.GMID = myuser.ID
}
user.Conn.AddFullHandler(user)
@ -422,13 +430,7 @@ func (user *User) HandleChatList() {
user.log.Errorln("chat sync error", err) //TODO: handle
return
}
user.log.Debugln("Group")
for _, chat := range chats {
user.log.Debugln(" " + chat.Name)
for _, mem := range chat.Members {
user.log.Debugln(" " + mem.Nickname)
}
chatMap[chat.ID] = chat
}
user.GroupList = chatMap
@ -602,14 +604,7 @@ func (user *User) postConnPing() bool {
func (user *User) intPostLogin() {
defer user.syncWait.Done()
user.lastReconnection = time.Now().Unix()
user.Client = groupmeext.NewClient(user.Token)
if len(user.GMID) == 0 {
myuser, err := user.Client.MyUser(context.TODO())
if err != nil {
log.Fatal(err) //TODO
}
user.GMID = myuser.ID
}
user.Update()
user.tryAutomaticDoublePuppeting()