Upgrade Cwtch - rely on Cwtch methods for fetching group timelines.
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2021-11-01 14:11:30 -07:00
parent a3e3c221ca
commit a36e439589
4 changed files with 22 additions and 22 deletions

View File

@ -22,8 +22,11 @@ func FunctionalityGate(experimentMap map[string]bool) (*Functionality, error) {
// SendMessage handles sending messages to contacts
func (pf *Functionality) SendMessage(peer peer.SendMessages, handle string, message string) features.Response {
eventID := peer.SendMessageToPeer(handle, message)
return features.ConstructResponse(sendMessagePrefix, eventID)
err := peer.SendMessage(handle, message)
if err == nil {
return features.ConstructResponse(sendMessagePrefix, "success")
}
return features.ConstructResponse(sendMessagePrefix, err.Error())
}
// HandleImportString handles contact import strings

View File

@ -56,7 +56,7 @@ func (gf *GroupFunctionality) SendMessage(peer peer.CwtchPeer, handle string, me
return "", err
}
}
return peer.SendMessageToGroupTracked(handle, message)
return "", peer.SendMessage(handle, message)
}
// ValidPrefix returns true if an import string contains a prefix that indicates it contains information about a

4
go.mod
View File

@ -3,10 +3,10 @@ module git.openprivacy.ca/cwtch.im/libcwtch-go
go 1.15
require (
cwtch.im/cwtch v0.12.2
cwtch.im/cwtch v0.13.0
git.openprivacy.ca/openprivacy/connectivity v1.5.0
git.openprivacy.ca/openprivacy/log v1.0.3
golang.org/x/mobile v0.0.0-20210716004757-34ab1303b554 // indirect
golang.org/x/mod v0.5.0 // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
)
)

31
lib.go
View File

@ -255,7 +255,7 @@ func ReconnectCwtchForeground() {
// fix peergroupcontact message counts
groupList := application.GetPeer(profileOnion).GetGroups()
for _, groupID := range groupList {
totalMessages := application.GetPeer(profileOnion).GetGroup(groupID).Timeline.Len() + len(application.GetPeer(profileOnion).GetGroup(groupID).UnacknowledgedMessages)
totalMessages := len(application.GetPeer(profileOnion).GetGroup(groupID).GetTimeline())
eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{
event.Identity: profileOnion,
event.GroupID: groupID,
@ -537,7 +537,7 @@ type EnhancedMessage struct {
ContactImage string
}
func GetMessage(profileOnion, handle string, message_index int) string {
func GetMessage(profileOnion, handle string, messageIndex int) string {
var message EnhancedMessage
// There is an edge case that can happen on Android when the app is shutdown while fetching messages...
// The worker threads that are spawned can become activated again when the app is opened attempt to finish their job...
@ -549,28 +549,25 @@ func GetMessage(profileOnion, handle string, message_index int) string {
ph := utils.NewPeerHelper(profile)
if ph.IsGroup(handle) {
if profile.GetGroup(handle) != nil {
// If we are safely within the limits of the timeline just grab the message at the index..
if len(profile.GetGroup(handle).Timeline.Messages) > message_index {
message.Message = profile.GetGroup(handle).Timeline.Messages[message_index]
exists, timelineMessage, length := profile.GetGroup(handle).GetMessage(messageIndex)
if exists {
message.Message = timelineMessage
message.ContactImage = ph.GetProfilePic(message.Message.PeerID)
} else {
// Message Index Request exceeded Timeline, most likely reason is this is a request for an
// unacknowledged sent message (it can take a many seconds for a message to be confirmed in the worst
// case).
offset := message_index - len(profile.GetGroup(handle).Timeline.Messages)
if len(profile.GetGroup(handle).UnacknowledgedMessages) > offset {
message.Message = profile.GetGroup(handle).UnacknowledgedMessages[offset]
message.ContactImage = ph.GetProfilePic(message.Message.PeerID)
} else {
log.Errorf("Couldn't find message in timeline or unacked messages, probably transient threading issue, but logging for visibility..")
}
eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{
event.Identity: profileOnion,
event.GroupID: handle,
event.Data: strconv.Itoa(length),
}))
log.Errorf("Couldn't find message in timeline %v / %v or unacked messages, probably transient threading issue, but logging for visibility..", messageIndex, length)
}
}
} else {
if profile.GetContact(handle) != nil {
// If we are safely within the limits of the timeline just grab the message at the index..
if len(profile.GetContact(handle).Timeline.Messages) > message_index {
message.Message = profile.GetContact(handle).Timeline.Messages[message_index]
if len(profile.GetContact(handle).Timeline.Messages) > messageIndex {
message.Message = profile.GetContact(handle).Timeline.Messages[messageIndex]
message.ContactImage = ph.GetProfilePic(handle)
} else {
// Otherwise Send a counter resync event...this shouldn't really happen for p2p messages so we