Push Group Information to UI, Fix bug with fetching messages for groups
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2021-04-20 15:23:20 -07:00
parent f9b4e1179e
commit 347bb27310
3 changed files with 42 additions and 6 deletions

22
lib.go
View File

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

View File

@ -10,4 +10,5 @@ type Contact struct {
Messages int `json:"numMessages"`
Unread int `json:"numUnread"`
LastMessage string `json:"lastMsgTime"`
IsGroup bool `json:"isGroup"`
}

View File

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