Przeglądaj źródła

feedbag: read typing-events pref via BuddyPref codec

Mike 2 tygodni temu
rodzic
commit
326d6ff92d
3 zmienionych plików z 7 dodań i 21 usunięć
  1. 3 3
      foodgroup/feedbag.go
  2. 4 12
      foodgroup/feedbag_test.go
  3. 0 6
      wire/buddy_prefs.go

+ 3 - 3
foodgroup/feedbag.go

@@ -1015,9 +1015,9 @@ func (s *FeedbagService) rejectContact(ctx context.Context, rejecter state.Ident
 // setSessionBuddyPrefs sets session preferences based on the feedbag buddy prefs item, if present.
 // setSessionBuddyPrefs sets session preferences based on the feedbag buddy prefs item, if present.
 func setSessionBuddyPrefs(items []wire.FeedbagItem, instance *state.SessionInstance) {
 func setSessionBuddyPrefs(items []wire.FeedbagItem, instance *state.SessionInstance) {
 	for _, item := range items {
 	for _, item := range items {
-		if item.ClassID == wire.FeedbagClassIdBuddyPrefs && item.HasTag(wire.FeedbagAttributesBuddyPrefs) {
-			buddyPrefs, _ := item.Uint32BE(wire.FeedbagAttributesBuddyPrefs)
-			instance.Session().SetTypingEventsEnabled(buddyPrefs&wire.FeedbagBuddyPrefsWantsTypingEvents == wire.FeedbagBuddyPrefsWantsTypingEvents)
+		if item.ClassID == wire.FeedbagClassIdBuddyPrefs {
+			_, wantsTyping := wire.BuddyPref(item.TLVList, wire.FeedbagBuddyPrefsDiscloseTyping)
+			instance.Session().SetTypingEventsEnabled(wantsTyping)
 			break
 			break
 		}
 		}
 	}
 	}

+ 4 - 12
foodgroup/feedbag_test.go

@@ -976,9 +976,7 @@ func TestFeedbagService_UpsertItem(t *testing.T) {
 						{
 						{
 							ClassID: wire.FeedbagClassIdBuddyPrefs,
 							ClassID: wire.FeedbagClassIdBuddyPrefs,
 							TLVLBlock: wire.TLVLBlock{
 							TLVLBlock: wire.TLVLBlock{
-								TLVList: wire.TLVList{
-									wire.NewTLVBE(wire.FeedbagAttributesBuddyPrefs, uint32(wire.FeedbagBuddyPrefsWantsTypingEvents)),
-								},
+								TLVList: wire.SetBuddyPref(nil, wire.FeedbagBuddyPrefsDiscloseTyping, true),
 							},
 							},
 						},
 						},
 					},
 					},
@@ -993,9 +991,7 @@ func TestFeedbagService_UpsertItem(t *testing.T) {
 								{
 								{
 									ClassID: wire.FeedbagClassIdBuddyPrefs,
 									ClassID: wire.FeedbagClassIdBuddyPrefs,
 									TLVLBlock: wire.TLVLBlock{
 									TLVLBlock: wire.TLVLBlock{
-										TLVList: wire.TLVList{
-											wire.NewTLVBE(wire.FeedbagAttributesBuddyPrefs, uint32(wire.FeedbagBuddyPrefsWantsTypingEvents)),
-										},
+										TLVList: wire.SetBuddyPref(nil, wire.FeedbagBuddyPrefsDiscloseTyping, true),
 									},
 									},
 								},
 								},
 							},
 							},
@@ -1017,9 +1013,7 @@ func TestFeedbagService_UpsertItem(t *testing.T) {
 										{
 										{
 											ClassID: wire.FeedbagClassIdBuddyPrefs,
 											ClassID: wire.FeedbagClassIdBuddyPrefs,
 											TLVLBlock: wire.TLVLBlock{
 											TLVLBlock: wire.TLVLBlock{
-												TLVList: wire.TLVList{
-													wire.NewTLVBE(wire.FeedbagAttributesBuddyPrefs, uint32(wire.FeedbagBuddyPrefsWantsTypingEvents)),
-												},
+												TLVList: wire.SetBuddyPref(nil, wire.FeedbagBuddyPrefsDiscloseTyping, true),
 											},
 											},
 										},
 										},
 									},
 									},
@@ -3047,9 +3041,7 @@ func TestFeedbagService_Use(t *testing.T) {
 								{
 								{
 									ClassID: wire.FeedbagClassIdBuddyPrefs,
 									ClassID: wire.FeedbagClassIdBuddyPrefs,
 									TLVLBlock: wire.TLVLBlock{
 									TLVLBlock: wire.TLVLBlock{
-										TLVList: wire.TLVList{
-											wire.NewTLVBE(wire.FeedbagAttributesBuddyPrefs, uint32(wire.FeedbagBuddyPrefsWantsTypingEvents)),
-										},
+										TLVList: wire.SetBuddyPref(nil, wire.FeedbagBuddyPrefsDiscloseTyping, true),
 									},
 									},
 								},
 								},
 							},
 							},

+ 0 - 6
wire/buddy_prefs.go

@@ -129,12 +129,6 @@ const (
 	FeedbagBuddyPrefsImblastInviteFromBuddyOnly uint16 = 0x4F
 	FeedbagBuddyPrefsImblastInviteFromBuddyOnly uint16 = 0x4F
 )
 )
 
 
-// FeedbagBuddyPrefsWantsTypingEvents is the DiscloseTyping (0x16) preference in
-// raw uint32-mask form (bit 22 of the fixed BuddyPrefs field). It is used when
-// reading the whole 4-byte bitmask as a single integer rather than by pref
-// number.
-const FeedbagBuddyPrefsWantsTypingEvents uint32 = 0x400000
-
 // buddyPrefTags returns the (valid, value) TLV tags that hold prefNum.
 // buddyPrefTags returns the (valid, value) TLV tags that hold prefNum.
 func buddyPrefTags(prefNum uint16) (validTag, valueTag uint16) {
 func buddyPrefTags(prefNum uint16) (validTag, valueTag uint16) {
 	if prefNum < 32 {
 	if prefNum < 32 {