Avatar gm -> matrix
mute system messages
This commit is contained in:
parent
5dbace10c6
commit
27d3e0322d
@ -31,7 +31,7 @@
|
|||||||
* [ ] Chat types
|
* [ ] Chat types
|
||||||
* [ ] Private chat
|
* [ ] Private chat
|
||||||
* [x] Group chat
|
* [x] Group chat
|
||||||
* [ ] Avatars
|
* [x] Avatars
|
||||||
* [ ] Presence
|
* [ ] Presence
|
||||||
* [ ] Typing notifications
|
* [ ] Typing notifications
|
||||||
* [ ] Read receipts
|
* [ ] Read receipts
|
||||||
@ -56,7 +56,7 @@
|
|||||||
* [ ] Automatic portal creation
|
* [ ] Automatic portal creation
|
||||||
* [x] At startup
|
* [x] At startup
|
||||||
* [ ] When receiving invite
|
* [ ] When receiving invite
|
||||||
* [ ] When receiving message
|
* [x] When receiving message
|
||||||
* [ ] Private chat creation by inviting Matrix puppet of WhatsApp user to new room
|
* [ ] Private chat creation by inviting Matrix puppet of WhatsApp user to new room
|
||||||
* [ ] Option to use own Matrix account for messages sent from WhatsApp mobile/other web clients
|
* [ ] Option to use own Matrix account for messages sent from WhatsApp mobile/other web clients
|
||||||
* [ ] Shared group chat portals
|
* [ ] Shared group chat portals
|
||||||
|
@ -339,6 +339,8 @@ func (portal *Portal) startHandling(source *User, info *groupme.Message) *appser
|
|||||||
portal.log.Debugfln("Not handling %s: message was recently handled", info.ID)
|
portal.log.Debugfln("Not handling %s: message was recently handled", info.ID)
|
||||||
} else if portal.isDuplicate(info.ID) {
|
} else if portal.isDuplicate(info.ID) {
|
||||||
portal.log.Debugfln("Not handling %s: message is duplicate", info.ID)
|
portal.log.Debugfln("Not handling %s: message is duplicate", info.ID)
|
||||||
|
} else if info.System {
|
||||||
|
portal.log.Debugfln("Not handling %s: message is from system: %s", info.ID, info.Text)
|
||||||
} else {
|
} else {
|
||||||
portal.lastMessageTs = uint64(info.CreatedAt.ToTime().Unix())
|
portal.lastMessageTs = uint64(info.CreatedAt.ToTime().Unix())
|
||||||
intent := portal.getMessageIntent(source, info)
|
intent := portal.getMessageIntent(source, info)
|
||||||
|
90
puppet.go
90
puppet.go
@ -18,6 +18,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -180,55 +182,53 @@ func (puppet *Puppet) DefaultIntent() *appservice.IntentAPI {
|
|||||||
return puppet.bridge.AS.Intent(puppet.MXID)
|
return puppet.bridge.AS.Intent(puppet.MXID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) UpdateAvatar(source *User, avatar *whatsappExt.ProfilePicInfo) bool {
|
func (puppet *Puppet) UpdateAvatar(source *User, avatar string) bool {
|
||||||
// if avatar == nil {
|
if len(avatar) == 0 {
|
||||||
// var err error
|
err := puppet.DefaultIntent().SetAvatarURL(id.ContentURI{})
|
||||||
// avatar, err = source.Conn.GetProfilePicThumb(puppet.JID)
|
if err != nil {
|
||||||
// if err != nil {
|
puppet.log.Warnln("Failed to remove avatar:", err)
|
||||||
// puppet.log.Warnln("Failed to get avatar:", err)
|
}
|
||||||
// return false
|
puppet.AvatarURL = id.ContentURI{}
|
||||||
// }
|
puppet.Avatar = avatar
|
||||||
// }
|
go puppet.updatePortalAvatar()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// if avatar.Status != 0 {
|
if puppet.Avatar == avatar {
|
||||||
// return false
|
return false // up to date
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if avatar.Tag == puppet.Avatar {
|
//TODO check its actually groupme?
|
||||||
// return false
|
response, err := http.Get(avatar + ".large")
|
||||||
// }
|
if err != nil {
|
||||||
|
puppet.log.Warnln("Failed to download avatar:", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
|
|
||||||
// if len(avatar.URL) == 0 {
|
image, err := ioutil.ReadAll(response.Body)
|
||||||
// err := puppet.DefaultIntent().SetAvatarURL(id.ContentURI{})
|
if err != nil {
|
||||||
// if err != nil {
|
puppet.log.Warnln("Failed to read downloaded avatar:", err)
|
||||||
// puppet.log.Warnln("Failed to remove avatar:", err)
|
return false
|
||||||
// }
|
}
|
||||||
// puppet.AvatarURL = id.ContentURI{}
|
|
||||||
// puppet.Avatar = avatar.Tag
|
|
||||||
// go puppet.updatePortalAvatar()
|
|
||||||
// return true
|
|
||||||
// }
|
|
||||||
|
|
||||||
// data, err := avatar.DownloadBytes()
|
mime := response.Header.Get("Content-Type")
|
||||||
// if err != nil {
|
if len(mime) == 0 {
|
||||||
// puppet.log.Warnln("Failed to download avatar:", err)
|
mime = http.DetectContentType(image)
|
||||||
// return false
|
}
|
||||||
// }
|
resp, err := puppet.DefaultIntent().UploadBytes(image, mime)
|
||||||
|
if err != nil {
|
||||||
|
puppet.log.Warnln("Failed to upload avatar:", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// mime := http.DetectContentType(data)
|
puppet.AvatarURL = resp.ContentURI
|
||||||
// resp, err := puppet.DefaultIntent().UploadBytes(data, mime)
|
err = puppet.DefaultIntent().SetAvatarURL(puppet.AvatarURL)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// puppet.log.Warnln("Failed to upload avatar:", err)
|
puppet.log.Warnln("Failed to set avatar:", err)
|
||||||
// return false
|
}
|
||||||
// }
|
puppet.Avatar = avatar
|
||||||
|
go puppet.updatePortalAvatar()
|
||||||
// puppet.AvatarURL = resp.ContentURI
|
|
||||||
// err = puppet.DefaultIntent().SetAvatarURL(puppet.AvatarURL)
|
|
||||||
// if err != nil {
|
|
||||||
// puppet.log.Warnln("Failed to set avatar:", err)
|
|
||||||
// }
|
|
||||||
// puppet.Avatar = avatar.Tag
|
|
||||||
// go puppet.updatePortalAvatar()
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ func (puppet *Puppet) Sync(source *User, contact groupme.User) {
|
|||||||
|
|
||||||
update := false
|
update := false
|
||||||
update = puppet.UpdateName(source, contact) || update
|
update = puppet.UpdateName(source, contact) || update
|
||||||
update = puppet.UpdateAvatar(source, nil) || update
|
update = puppet.UpdateAvatar(source, contact.AvatarURL) || update
|
||||||
if update {
|
if update {
|
||||||
puppet.Update()
|
puppet.Update()
|
||||||
}
|
}
|
||||||
|
5
user.go
5
user.go
@ -800,8 +800,9 @@ func (user *User) handleMessageLoop() {
|
|||||||
puppet := user.bridge.GetPuppetByJID(msg.data.UserID.String())
|
puppet := user.bridge.GetPuppetByJID(msg.data.UserID.String())
|
||||||
if puppet != nil {
|
if puppet != nil {
|
||||||
puppet.Sync(user, groupme.User{
|
puppet.Sync(user, groupme.User{
|
||||||
ID: msg.data.ID,
|
ID: msg.data.ID,
|
||||||
Name: msg.data.Name,
|
Name: msg.data.Name,
|
||||||
|
AvatarURL: msg.data.AvatarURL,
|
||||||
}) //TODO: add params or docs?
|
}) //TODO: add params or docs?
|
||||||
}
|
}
|
||||||
user.GetPortalByJID(msg.chat).messages <- msg
|
user.GetPortalByJID(msg.chat).messages <- msg
|
||||||
|
Loading…
Reference in New Issue
Block a user