Reactions groupme -> Matrix

finalizing
This commit is contained in:
Karmanyaah Malhotra 2021-04-01 20:30:16 -04:00
parent 086cff7244
commit 36d40136fb
3 changed files with 14 additions and 12 deletions

View File

@ -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 <sup>[3]</sup>
* [ ] Admin/superadmin status
* [ ] Membership actions
* [ ] Invite

View File

@ -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() {

View File

@ -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
}