From 347bb273100ae9435f5ea5c0c09d5393b8ec7832 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 20 Apr 2021 15:23:20 -0700 Subject: [PATCH] Push Group Information to UI, Fix bug with fetching messages for groups --- lib.go | 22 ++++++++++++++++------ utils/contacts.go | 1 + utils/eventHandler.go | 25 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/lib.go b/lib.go index 4e40cdb..de4b7ed 100644 --- a/lib.go +++ b/lib.go @@ -425,9 +425,15 @@ func c_GetMessage(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, ha return C.CString(GetMessage(profile, handle, int(message_index))) } -// Deprecate - 2021.01.14 - not used -func GetMessage(profile, handle string, message_index int) string { - message := application.GetPeer(profile).GetContact(handle).Timeline.Messages[message_index] +func GetMessage(profileOnion, handle string, message_index int) string { + profile := application.GetPeer(profileOnion) + ph := utils.NewPeerHelper(profile) + var message model.Message + if ph.IsGroup(handle) { + message = profile.GetGroup(handle).Timeline.Messages[message_index] + } else { + message = profile.GetContact(handle).Timeline.Messages[message_index] + } bytes, _ := json.Marshal(message) return string(bytes) } @@ -467,19 +473,23 @@ func ResetTor() { } //export c_CreateGroup -func c_CreateGroup(profile_ptr *C.char, profile_len C.int, server_ptr *C.char, server_len C.int) { +func c_CreateGroup(profile_ptr *C.char, profile_len C.int, server_ptr *C.char, server_len C.int, name_ptr *C.char, name_len C.int) { profile := C.GoStringN(profile_ptr, profile_len) server := C.GoStringN(server_ptr, server_len) - CreateGroup(profile, server) + name := C.GoStringN(name_ptr, name_len) + CreateGroup(profile, server, name) } -func CreateGroup(profile string, server string) { +// CreateGroup takes in a profile and server in addition to a name and creates a new group. +func CreateGroup(profile string, server string, name string) { peer := application.GetPeer(profile) _, err := groups.ExperimentGate(utils.ReadGlobalSettings().Experiments) if err == nil { gid, _, err := peer.StartGroup(server) if err == nil { log.Debugf("created group %v on %v: $v", profile, server, gid) + // set the group name + peer.SetGroupAttribute(gid, attr.GetPublicScope(name), name) } else { log.Errorf("error creating group or %v on server %v: %v", profile, server, err) } diff --git a/utils/contacts.go b/utils/contacts.go index fc1b57a..a279e0f 100644 --- a/utils/contacts.go +++ b/utils/contacts.go @@ -10,4 +10,5 @@ type Contact struct { Messages int `json:"numMessages"` Unread int `json:"numUnread"` LastMessage string `json:"lastMsgTime"` + IsGroup bool `json:"isGroup"` } diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 7d55577..bd0d1d5 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -150,6 +150,31 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { Messages: contactInfo.Timeline.Len(), Unread: 0, LastMessage: strconv.Itoa(getLastMessageTime(&contactInfo.Timeline)), + IsGroup: false, + }) + } + + for _, groupId := range profile.GetGroups() { + group := profile.GetGroup(groupId) + ph := NewPeerHelper(profile) + cpicPath := ph.GetProfilePic(groupId) + + authorization := model.AuthUnknown + if group.Accepted { + authorization = model.AuthApproved + } + + contacts = append(contacts, Contact{ + Name: ph.GetNick(groupId), + Onion: group.GroupID, + Status: group.State, + Picture: cpicPath, + Authorization: string(authorization), + SaveHistory: event.SaveHistoryConfirmed, + Messages: group.Timeline.Len(), + Unread: 0, + LastMessage: strconv.Itoa(getLastMessageTime(&group.Timeline)), + IsGroup: true, }) }