From 4df9a2207579e993596852443a2cf2ddf0e2041b Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 5 May 2021 13:05:02 -0700 Subject: [PATCH 1/3] New Cwtch Group API --- features/groups/group_functionality.go | 2 +- go.mod | 4 ++-- go.sum | 10 ++++++++++ lib.go | 15 +++++++++++++-- utils/eventHandler.go | 22 +++++++++++++++------- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/features/groups/group_functionality.go b/features/groups/group_functionality.go index d1ce1dd..29c4911 100644 --- a/features/groups/group_functionality.go +++ b/features/groups/group_functionality.go @@ -117,7 +117,7 @@ func (gf *GroupFunctionality) HandleImportString(peer peer.CwtchPeer, importStri return features.ConstructResponse(importBundlePrefix, err.Error()) } else if strings.HasPrefix(importString, groupPrefix) { //eg: torv3JFDWkXExBsZLkjvfkkuAxHsiLGZBk0bvoeJID9ItYnU=EsEBCiBhOWJhZDU1OTQ0NWI3YmM2N2YxYTM5YjkzMTNmNTczNRIgpHeNaG+6jy750eDhwLO39UX4f2xs0irK/M3P6mDSYQIaOTJjM2ttb29ibnlnaGoyenc2cHd2N2Q1N3l6bGQ3NTNhdW8zdWdhdWV6enB2ZmFrM2FoYzRiZHlkCiJAdVSSVgsksceIfHe41OJu9ZFHO8Kwv3G6F5OK3Hw4qZ6hn6SiZjtmJlJezoBH0voZlCahOU7jCOg+dsENndZxAA== - if err := peer.ImportGroup(importString); err != nil { + if _, err := peer.ImportGroup(importString); err != nil { return features.ConstructResponse(importBundlePrefix, err.Error()) } return features.ConstructResponse(importBundlePrefix, "success") diff --git a/go.mod b/go.mod index 85a35f7..c578091 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module git.openprivacy.ca/flutter/libcwtch-go go 1.15 require ( - cwtch.im/cwtch v0.6.10 - git.openprivacy.ca/openprivacy/connectivity v1.4.2 + cwtch.im/cwtch v0.7.1 + git.openprivacy.ca/openprivacy/connectivity v1.4.3 git.openprivacy.ca/openprivacy/log v1.0.2 golang.org/x/mobile v0.0.0-20210220033013-bdb1ca9a1e08 // indirect ) diff --git a/go.sum b/go.sum index 1fa7c3e..b437428 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,10 @@ cwtch.im/cwtch v0.6.9 h1:R4UgKd8ucw8qGZ0K0RrYB+tZrgCXJ83HsH/MrNfsqps= cwtch.im/cwtch v0.6.9/go.mod h1:KDy4lWWxcYAjeKclwVFkoTQ2dWnZcM0k3Xck+zEuBmE= cwtch.im/cwtch v0.6.10 h1:5w9G3HXBLIFE1Jrn2tQ+Alc8+td3ty5bWOOq4xeTXXk= cwtch.im/cwtch v0.6.10/go.mod h1:KDy4lWWxcYAjeKclwVFkoTQ2dWnZcM0k3Xck+zEuBmE= +cwtch.im/cwtch v0.7.0 h1:iBAPk2h9onxAoUAqTpr4w9HHTD8thQrufKEgk7Uwekw= +cwtch.im/cwtch v0.7.0/go.mod h1:CVgA/YFG1BUlGLqgxOLgCfYQayquw7D0c25VIK4ZCog= +cwtch.im/cwtch v0.7.1 h1:H+/LWucU2TO6j+reMcf7CJcU6s+qq0FlxdZWEOxTvNo= +cwtch.im/cwtch v0.7.1/go.mod h1:S0JRLSTwFM+kRrpOPKgUQn/loKe/fc6lLDnOFopRKq8= cwtch.im/tapir v0.2.1 h1:t1YJB9q5sV1A9xwiiwL6WVfw3dwQWLoecunuzT1PQtw= cwtch.im/tapir v0.2.1/go.mod h1:xzzZ28adyUXNkYL1YodcHsAiTt3IJ8Loc29YVn9mIEQ= git.openprivacy.ca/cwtch.im/tapir v0.3.2 h1:thLWqqY1LkirWFcy9Tg6NgWeYbvo9xBm+s2XVnCIvpY= @@ -30,6 +34,10 @@ git.openprivacy.ca/cwtch.im/tapir v0.3.3 h1:Q7F8JijgOMMYSy3IdZl7+r6qkWckEWV1+EY7 git.openprivacy.ca/cwtch.im/tapir v0.3.3/go.mod h1:ZMg9Jzh0n3Os2aSF4z+bx/n8WBCJBN7KCQESXperYts= git.openprivacy.ca/cwtch.im/tapir v0.3.4 h1:g7yZkfz/vWr/t2tFXa/t0Ebr/w665uIKpxpCZ3lIPCo= git.openprivacy.ca/cwtch.im/tapir v0.3.4/go.mod h1:+Niy2AHhQC351ZTtfhC0uLjViCICyOxCJZsIlGKKNAU= +git.openprivacy.ca/cwtch.im/tapir v0.3.5 h1:AlqAhluY4ivznGoHh37Khyxy0u9IbtYskP93wgtmYx8= +git.openprivacy.ca/cwtch.im/tapir v0.3.5/go.mod h1:eH6dZxXrhW0C4KZX18ksUa6XJCrEvtg8cJJ/Fy6gv+E= +git.openprivacy.ca/cwtch.im/tapir v0.4.0 h1:clG8uORt0NKEhT4P+Dpw1pzyUuYzYBMevGqn2pciKk8= +git.openprivacy.ca/cwtch.im/tapir v0.4.0/go.mod h1:eH6dZxXrhW0C4KZX18ksUa6XJCrEvtg8cJJ/Fy6gv+E= git.openprivacy.ca/openprivacy/bine v0.0.4 h1:CO7EkGyz+jegZ4ap8g5NWRuDHA/56KKvGySR6OBPW+c= git.openprivacy.ca/openprivacy/bine v0.0.4/go.mod h1:13ZqhKyqakDsN/ZkQkIGNULsmLyqtXc46XBcnuXm/mU= git.openprivacy.ca/openprivacy/connectivity v1.2.0/go.mod h1:B7vzuVmChJtSKoh0ezph5vu6DQ0gIk0zHUNG6IgXCcA= @@ -41,6 +49,8 @@ git.openprivacy.ca/openprivacy/connectivity v1.4.1 h1:zoM+j7PFj8mQeUCNiDNMe7Uq9d git.openprivacy.ca/openprivacy/connectivity v1.4.1/go.mod h1:bR0Myx9nm2YzWtsThRelkNMV4Pp7sPDa123O1qsAbVo= git.openprivacy.ca/openprivacy/connectivity v1.4.2 h1:rQFIjWunLlRmXL5Efsv+7+1cA70T6Uza6RCy2PRm9zc= git.openprivacy.ca/openprivacy/connectivity v1.4.2/go.mod h1:bR0Myx9nm2YzWtsThRelkNMV4Pp7sPDa123O1qsAbVo= +git.openprivacy.ca/openprivacy/connectivity v1.4.3 h1:i2Ad/U9FlL9dKr2bhRck7lJ8NoWyGtoEfUwoCyMT0fU= +git.openprivacy.ca/openprivacy/connectivity v1.4.3/go.mod h1:bR0Myx9nm2YzWtsThRelkNMV4Pp7sPDa123O1qsAbVo= git.openprivacy.ca/openprivacy/log v1.0.0/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw= git.openprivacy.ca/openprivacy/log v1.0.1/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw= git.openprivacy.ca/openprivacy/log v1.0.2 h1:HLP4wsw4ljczFAelYnbObIs821z+jgMPCe8uODPnGQM= diff --git a/lib.go b/lib.go index 9766ae8..85b7d17 100644 --- a/lib.go +++ b/lib.go @@ -93,7 +93,6 @@ func StartCwtch(appDir string, torPath string) { event.EncryptedGroupMessage, event.NewMessageFromPeer, event.PeerAcknowledgement, - event.NewGroupInvite, event.PeerError, event.SendMessageToGroupError, event.NewGetValMessageFromPeer, @@ -461,9 +460,20 @@ func GetMessage(profileOnion, handle string, message_index int) string { if len(profile.GetGroup(handle).Timeline.Messages) > message_index { message.Message = profile.GetGroup(handle).Timeline.Messages[message_index] 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..") + } } } else { - message.Message = profile.GetContact(handle).Timeline.Messages[message_index] + message.Message = profile.GetContact(handle).Timeline.Messages[message_index] message.ContactImage = ph.GetProfilePic(handle) } bytes, _ := json.Marshal(message) @@ -497,6 +507,7 @@ func SendMessage(profileOnion, handle, msg string) { if ph.IsGroup(handle) { groupHandler, err := groups.ExperimentGate(utils.ReadGlobalSettings().Experiments) if err == nil { + log.Debugf("Group Sending Enabled... Sending message to %v", handle) groupHandler.SendMessage(profile, handle, msg) } } else { diff --git a/utils/eventHandler.go b/utils/eventHandler.go index b8d7a21..0593a2a 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -7,11 +7,13 @@ import ( "cwtch.im/cwtch/model/attr" "cwtch.im/cwtch/protocol/connections" groups2 "cwtch.im/cwtch/protocol/groups" + "encoding/base64" "encoding/json" "git.openprivacy.ca/flutter/libcwtch-go/constants" "git.openprivacy.ca/flutter/libcwtch-go/features/groups" "git.openprivacy.ca/openprivacy/log" "strconv" + "strings" ) import "cwtch.im/cwtch/event" @@ -70,7 +72,8 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { eh.startHandlingPeer(onion) if e.Data[event.Created] == event.True { - profile.SetAttribute(attr.GetPublicScope(constants.Name), profile.GetName()) + name, _ := profile.GetAttribute(attr.GetLocalScope(constants.Name)) + profile.SetAttribute(attr.GetPublicScope(constants.Name), name) profile.SetAttribute(attr.GetPublicScope(constants.Picture), ImageToString(NewImage(RandomProfileImage(onion), TypeImageDistro))) } if e.Data[event.Status] != event.StorageRunning || e.Data[event.Created] == event.True { @@ -258,12 +261,17 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { case event.SendMessageToPeerError: uiManager.AddSendMessageError(e.Data[event.RemotePeer], e.Data[event.EventID], e.Data[event.Error]) */ - case event.NewGroupInvite: + case event.NewGroup: var invite = groups2.GroupInvite{} - json.Unmarshal([]byte(ev.Event.Data[event.GroupInvite]), &invite) - groupPic := ph.GetProfilePic(invite.GroupID) - ev.Event.Data["PicturePath"] = groupPic - + serializedInvite := ev.Event.Data[event.GroupInvite] + if strings.HasPrefix(serializedInvite, "torv3") { + inviteJson, err := base64.StdEncoding.DecodeString(serializedInvite[5:]) + if err == nil { + json.Unmarshal(inviteJson, &invite) + groupPic := ph.GetProfilePic(invite.GroupID) + ev.Event.Data["PicturePath"] = groupPic + } + } case event.PeerStateChange: cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]] contact := peer.GetContact(ev.Event.Data[event.RemotePeer]) @@ -341,7 +349,7 @@ func (eh *EventHandler) startHandlingPeer(onion string) { eventBus.Subscribe(event.PeerAcknowledgement, q) eventBus.Subscribe(event.IndexedAcknowledgement, q) eventBus.Subscribe(event.NewMessageFromGroup, q) - eventBus.Subscribe(event.NewGroupInvite, q) + eventBus.Subscribe(event.NewGroup, q) eventBus.Subscribe(event.AcceptGroupInvite, q) eventBus.Subscribe(event.SendMessageToGroupError, q) eventBus.Subscribe(event.SendMessageToPeerError, q) From c2e3488a45d4dee010fd48d0bf27bfcbfeffda34 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 5 May 2021 15:17:35 -0700 Subject: [PATCH 2/3] Remove Debug --- lib.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib.go b/lib.go index 85b7d17..5eb9b34 100644 --- a/lib.go +++ b/lib.go @@ -1,6 +1,6 @@ -//package cwtch +package cwtch -package main +//package main import "C" import ( @@ -507,7 +507,6 @@ func SendMessage(profileOnion, handle, msg string) { if ph.IsGroup(handle) { groupHandler, err := groups.ExperimentGate(utils.ReadGlobalSettings().Experiments) if err == nil { - log.Debugf("Group Sending Enabled... Sending message to %v", handle) groupHandler.SendMessage(profile, handle, msg) } } else { @@ -587,4 +586,4 @@ func SetGroupAttribute(profileOnion string, groupHandle string, key string, valu } // Leave as is, needed by ffi -func main() {} +//func main() {} From 699d249ad74858364ad9742ab18e0a0e0ecda9ba Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 5 May 2021 15:19:07 -0700 Subject: [PATCH 3/3] Switch FFI --- lib.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib.go b/lib.go index 5eb9b34..e708e59 100644 --- a/lib.go +++ b/lib.go @@ -1,6 +1,6 @@ -package cwtch +//package cwtch -//package main +package main import "C" import ( @@ -586,4 +586,4 @@ func SetGroupAttribute(profileOnion string, groupHandle string, key string, valu } // Leave as is, needed by ffi -//func main() {} +func main() {}