Merge pull request 'include ACL struct in relevant conversation events' (#82) from acl into trunk

Reviewed-on: cwtch.im/libcwtch-go#82
Reviewed-by: Sarah Jamie Lewis <sarah@openprivacy.ca>
This commit is contained in:
Dan Ballard 2022-04-06 23:25:18 +00:00
commit 3d8ef9f06b
2 changed files with 34 additions and 17 deletions

View File

@ -1,20 +1,23 @@
package utils
import "cwtch.im/cwtch/model"
type Contact struct {
Name string `json:"name"`
Onion string `json:"onion"`
Status string `json:"status"`
Picture string `json:"picture"`
DefaultPicture string `json:"defaultPicture"`
Accepted bool `json:"accepted"`
Blocked bool `json:"blocked"`
SaveHistory string `json:"saveConversationHistory"`
Messages int `json:"numMessages"`
Unread int `json:"numUnread"`
LastMessage string `json:"lastMsgTime"`
IsGroup bool `json:"isGroup"`
GroupServer string `json:"groupServer"`
IsArchived bool `json:"isArchived"`
Identifier int `json:"identifier"`
NotificationPolicy string `json:"notificationPolicy"`
Name string `json:"name"`
Onion string `json:"onion"`
Status string `json:"status"`
Picture string `json:"picture"`
DefaultPicture string `json:"defaultPicture"`
Accepted bool `json:"accepted"`
AccessControlList model.AccessControlList `json:"accessControlList"`
Blocked bool `json:"blocked"`
SaveHistory string `json:"saveConversationHistory"`
Messages int `json:"numMessages"`
Unread int `json:"numUnread"`
LastMessage string `json:"lastMsgTime"`
IsGroup bool `json:"isGroup"`
GroupServer string `json:"groupServer"`
IsArchived bool `json:"isArchived"`
Identifier int `json:"identifier"`
NotificationPolicy string `json:"notificationPolicy"`
}

View File

@ -260,6 +260,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
Picture: cpicPath,
DefaultPicture: defaultPath,
Accepted: conversationInfo.Accepted,
AccessControlList: conversationInfo.ACL,
Blocked: blocked,
SaveHistory: saveHistory,
Messages: count,
@ -395,6 +396,8 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
accepted = constants.True
}
acl, _ := json.Marshal(conversationInfo.ACL)
lastMessage, _ := profile.GetMostRecentMessages(conversationID, 0, 0, 1)
ev.Event.Data["unread"] = strconv.Itoa(count) // if this is a new contact with messages attached then by-definition these are unread...
ev.Event.Data[constants2.Picture] = RandomProfileImage(conversationInfo.Handle)
@ -403,6 +406,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
ev.Event.Data["nick"] = conversationInfo.Handle
ev.Event.Data["status"] = connections.ConnectionStateName[profile.GetPeerState(conversationInfo.Handle)]
ev.Event.Data["accepted"] = accepted
ev.Event.Data["accessControlList"] = string(acl)
ev.Event.Data["blocked"] = blocked
ev.Event.Data["loading"] = "false"
ev.Event.Data["lastMsgTime"] = strconv.Itoa(getLastMessageTime(lastMessage))
@ -411,6 +415,11 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
// condition *should* never happen.
groupPic := RandomGroupImage(ev.Event.Data[event.GroupID])
ev.Event.Data[constants2.Picture] = groupPic
conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID])
conversationInfo, _ := profile.GetConversationInfo(conversationID)
acl, _ := json.Marshal(conversationInfo.ACL)
ev.Event.Data["accessControlList"] = string(acl)
case event.NewGroup:
// This event should only happen after we have validated the invite, as such the error
// condition *should* never happen.
@ -418,8 +427,13 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
if invite, err := model.ValidateInvite(serializedInvite); err == nil {
groupPic := RandomGroupImage(invite.GroupID)
ev.Event.Data[constants2.Picture] = groupPic
conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID])
conversationInfo, _ := profile.GetConversationInfo(conversationID)
acl, _ := json.Marshal(conversationInfo.ACL)
ev.Event.Data["accessControlList"] = string(acl)
} else {
log.Errorf("received a new group event which contained an invalid invite %v. this should never happen and likely means there is a bug in cwtch. Please file a ticket @ https://git.openprivcy.ca/cwtch.im/cwtch", err)
log.Errorf("received a new group event which contained an invalid invite %v. this should never happen and likely means there is a bug in cwtch. Please file a ticket @ https://git.openprivacy.ca/cwtch.im/cwtch", err)
return ""
}
case event.PeerStateChange: