From 36d40136fbb00a3dcff185300a816e23861edf48 Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 1 Apr 2021 20:30:16 -0400 Subject: [PATCH] Reactions groupme -> Matrix finalizing --- ROADMAP.md | 6 ++++++ database/reactions.go | 6 +++--- portal.go | 14 +++++--------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 2dd54e9..0a93149 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -6,6 +6,9 @@ * [ ] Media/files * [ ] Replies * [ ] Message redactions + * [ ] Reactions + * [ ] Addition + * [ ] Deletion * [ ] Presence - N/A * [ ] Typing notifications * [ ] Read receipts @@ -41,6 +44,9 @@ * [ ] Events created * [ ] Events modified * [ ] Going/Not + * [ ] Reactions + * [x] Addition + * [ ] Deletion [3] * [ ] Admin/superadmin status * [ ] Membership actions * [ ] Invite diff --git a/database/reactions.go b/database/reactions.go index 9b3853f..d1a2cb5 100644 --- a/database/reactions.go +++ b/database/reactions.go @@ -20,7 +20,7 @@ func (mq *ReactionQuery) New() *Reaction { func (mq *ReactionQuery) GetByJID(jid types.GroupMeID) (reactions []*Reaction) { ans := mq.db.Model(&Reaction{}). - Joins("Users"). // TODO: Do this in seperate function? + Preload("Puppet"). // TODO: Do this in seperate function? Where("message_jid = ?", jid). Limit(1).Find(&reactions) @@ -54,8 +54,8 @@ type Reaction struct { Message Message `gorm:"foreignKey:MessageMXID,MessageJID;references:MXID,JID;"` //User - UserMXID id.UserID `gorm:"notNull"` - User User `gorm:"foreignKey:UserMXID;references:MXID;"` + PuppetJID types.GroupMeID `gorm:"notNull"` + Puppet Puppet `gorm:"foreignKey:PuppetJID;references:jid;"` } func (reaction *Reaction) Insert() { diff --git a/portal.go b/portal.go index 99d07ec..9ae656c 100644 --- a/portal.go +++ b/portal.go @@ -1608,10 +1608,6 @@ func (portal *Portal) handleReaction(msgID types.GroupMeID, ppl []types.GroupMeI } eventID = message.MXID } - for _, i := range reactions { - fmt.Printf("%+v, ", i.User) - } - fmt.Println(newLikes, ppl) for _, jid := range newLikes { intent := portal.getReactionIntent(jid) @@ -1625,18 +1621,18 @@ func (portal *Portal) handleReaction(msgID types.GroupMeID, ppl []types.GroupMeI newReaction.MXID = resp.EventID newReaction.MessageJID = msgID newReaction.MessageMXID = eventID - newReaction.UserMXID = portal.bridge.GetPuppetByJID(jid).MXID + newReaction.PuppetJID = jid newReaction.Insert() } for _, reaction := range removeLikes { - if len(reaction.User.JID) == 0 { + if len(reaction.Puppet.JID) == 0 { portal.log.Warnln("Reaction user state wrong", reaction.MXID, msgID) continue } - intent := portal.getReactionIntent(reaction.User.JID) + intent := portal.getReactionIntent(reaction.PuppetJID) _, err := intent.RedactEvent(portal.MXID, reaction.MXID) if err != nil { portal.log.Errorln("Something wrong with reaction redaction", reaction.MXID) @@ -1651,7 +1647,7 @@ func oldReactions(a []*database.Reaction, b []string) (ans []*database.Reaction) for _, i := range a { flag := false for _, j := range b { - if i.User.JID == j { + if i.PuppetJID == j { flag = true break } @@ -1668,7 +1664,7 @@ func newReactions(a []*database.Reaction, b []string) (ans []string) { for _, j := range b { flag := false for _, i := range a { - if i.User.JID == j { + if i.PuppetJID == j { flag = true break }