Skip to content

Commit

Permalink
Fixed a lot of issues; version 0.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjunetime committed Nov 11, 2020
1 parent 5fb1667 commit 6d696bd
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 352 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The source code may be updated past the latest released version, so don't be sur
If there are any issues, questions, or feature requests at all, don't hesitate to create an issue or pull request here, or email me at [email protected]. I may not run into all issues that could possibly come up, so I would really appreciate any issues you let me know about.

### Acknowledged issues:
- Creating new conversations does not work on iOS 14+. This is being worked on.
- Although typing indicators do appear when the other party starts typing, they don't always disappear when they stop typing. This is also being worked on.

### To file an issue:
Expand All @@ -86,7 +87,7 @@ Please include the following information:
Also, if the app did not crash on startup, but rather crashed after it was already up and running, I would appreciate if you could do the following:
- Install the package 'oslog' from your package manager
- ssh into your device and run (as root): `oslog --debug | grep -i -e "SMServer_app" -e "mryipc"`; do not redirect the output into a file.
- Enable debug on the app, then kill the app in app switcher
- Enable debug on the app, then hit the purple 'refresh' button in the bottom left of the main view.
- Start the app and let it reach the error point
- Manually copy the output from the above command (as much as you can get) into a text file.
- Email me the file at [email protected]. This file may have sensitive information, such as contact phone numbers, so it wouldn't be smart to upload it to a public site. Feel free to filter out (with something like regex or by hand) the sensitive information.
Expand Down
7 changes: 5 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All requests to `/requests` return JSON information.
Retrieves the most recent $num messages to or from $person, offset by $offset.

- person: parameter is necessary, and value is consequential; must be chat_identifier of conversation. chat_identifier will be the email address or phone number of an individual, or 'chat' + $arbitrary_number for a group chat. chat_identifiers for group chats and email addresses must be exact, and phone numbers must be in the form of '+\<country code>\<area code>\<number>'. e.g. "+16378269173". Using parentheses or dashes will mess it up and return nothing.
$\qquad$ As of version 0.5.4, you may also send multiple addresses to this parameter, separated by single commas, and it will return a merged text list with all of the texts from the listed addresses included. This can be useful if you'd like to treat multiple conversations as one, such as if you have multiple conversations for talking with one person.

- num: Parameter is not necessary, but value is consequential. The value of this parameter must be an integer, and will be the number of most recent messages that are returned from the app. If it is 0, it will return all the messages to or from this person, and if it is not specified, it will use the default number of messages on the app, which is currently 100 at the time of writing this.

Expand All @@ -23,10 +24,11 @@ Retrieves the most recent $num messages to or from $person, offset by $offset.
- read: Parameter is not necessary, but value is consequential. The value of this parameter must be a string, either `true` or `false`. If it is `true`, or the parameter is not included but the 'mark conversation as read when viewed on web interface' option is checked in the app's settings, the conversation whose messages are being requested will be marked as read on the host device.

Example queries:
- /requests?person=chat192370112946&num=500
- /requests?person=chat192370112946281736&num=500
- /requests?person=+15202621138
- /requests?person=[email protected]&num=50&offset=100&read=false
- /requests?person=[email protected]&offset=200
- /requests?person=[email protected],+15202621138,[email protected]&num=100&read=true

## `chat`, `num_chats`, `chats_offset`

Expand All @@ -47,11 +49,12 @@ Example queries:

Retrieves the contact name that accompanies chat_identifier $name

- name: Parameter is necessary, and value is consequential. Value must be the chat_identifier for the contact whose name you want. It can get the name if given an email address or phone number of an individual, but it cannot get a contact name for a group chat, since none such exist. Email must be given in the regular format, and phone number must be given in the format that the above 'person' section specifies.
- name: Parameter is necessary, and value is consequential. Value must be the chat_identifier for the contact whose name you want. It can get the name if given an email address or phone number of an individual, or the chat_identifier of a group chat. Email must be given in the regular format, and phone number must be given in the format that the above 'person' section specifies. If there is no name for the email address, phone number, or chat_identifier given, then it will return the given address (in the case of a phone number or email address) or list of recipients (in the case of a group chat chat_identifier)

Example queries:
- /requests?name=[email protected]
- /requests?name=+12761938272
- /requests?name=chat193827462058278283

## `search`, `case_sensitive`, `bridge_gaps`, `group_by`

Expand Down
9 changes: 8 additions & 1 deletion docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
0.5.3 &rightarrow; 0.5.4
- Texts now have prettier bubble tails and no tails when sent close after each other
- Texts also have proper spacing when sent far from each other to indicate the gaps in conversation
- Added experimental option to combine numbers that are assigned to the same contact as similar chats
- Added option in API to get chats from multiple addresses as if they were one conversation
- Revamped settings view
- Completely rewrote javascript that prints list of texts
- Sending a text now creates a new time display when it's been more than an hour
- Web interface is better at waiting for attachments to fully upload when sending a text before displaying the new text in the web interface
- Web interface now only tries to mark a conversation as read when the window becomes focused if it was already unread
- Unread indicators look much cleaner now
- Texts wholly made of emojis now show without background and with a larger font
- Fixed issue with z-indices on multiple overlayed reations
- Fixed coloring issues with dark and light themes
- Fixed spacing issues in text area
- Fixed issue where order of texts would be messed up when reactions were inserted
- Fixed issue where conversations would not appear as selected if they were not the top of the list when you sent a text to them
- Fixed issue where textbox wouldn't properly resize when going from 2 lines to 1
- Fixed issue where some memojis wouldn't load into the web interface
- Fixed issue where sometimes chats without a contact would return an empty name, thus causing more issues
- Fixed issue where sender name wouldn't appear in a group chat after a time display

0.5.2 &rightarrow; 0.5.3
- Added inline audio displays
Expand Down
Binary file not shown.
49 changes: 22 additions & 27 deletions src/SMServer/ChatDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class ChatDelegate {
let prefix: String = "SMServer_app: "

static let addressBookAddress: String = "/private/var/mobile/Library/AddressBook/AddressBook.sqlitedb"
static let imageStoragePrefix: String = "/private/var/mobile/Library/SMS/Attachments/"
static let imageStoragePrefix: String = "/private/var/mobile/Library/SMS/"
static let photoStoragePrefix: String = "/var/mobile/Media/"
static let userHomeString: String = "/private/var/mobile/"

Expand Down Expand Up @@ -147,7 +147,7 @@ final class ChatDelegate {
var display_name_array = [[String:String]]()

/// Support for group chats
if chat_id.prefix(4) == "chat" && !chat_id.contains("@") && chat_id.count > 20 {
if chat_id.prefix(4) == "chat" && !chat_id.contains("@") && chat_id.count >= 20 {
let check_name = selectFromSql(db: sms_db, columns: ["display_name"], table: "chat", condition: "where chat_identifier is \"\(chat_id)\"", num_items: 1)

if check_name.count == 0 || check_name[0]["display_name"]?.count == 0 {
Expand All @@ -171,10 +171,10 @@ final class ChatDelegate {
let unc = selectFromSql(db: sms_db, columns: ["uncanonicalized_id"], table: "handle", condition: "WHERE id is \"\(chat_id)\"")

guard unc.count > 0, let ret = unc[0]["uncanonicalized_id"] else {
return ""
return chat_id
}

return ret
return ret.count == 0 ? chat_id : ret
}

/// combine first name and last name
Expand Down Expand Up @@ -276,7 +276,7 @@ final class ChatDelegate {
self.log("Getting \(String(num_to_load)) chats")

var pinned_chats: [String] = [""]
var combine = UserDefaults.standard.object(forKey: "combine_contacts") as? Bool ?? false
let combine = UserDefaults.standard.object(forKey: "combine_contacts") as? Bool ?? false
var return_array = [[String:String]]()

if offset == 0 && Float(UIDevice.current.systemVersion) ?? 13.0 >= 14.0 {
Expand All @@ -297,40 +297,35 @@ final class ChatDelegate {

let chats = selectFromSql(db: db, columns: ["m.ROWID", "m.is_read", "m.is_from_me", "m.text", "m.item_type", "m.date_read", "m.date", "m.cache_has_attachments", "c.chat_identifier", "c.display_name", "c.room_name"], table: "chat_message_join j", condition: "inner join message m on j.message_id = m.ROWID inner join chat c on c.ROWID = j.chat_id where j.message_date in (select max(j.message_date) from chat_message_join j inner join chat c on c.ROWID = j.chat_id group by c.chat_identifier) order by j.message_date desc", num_items: num_to_load, offset: offset)

inner: if combine { /// uhhh sketchy times. Seems to not impact performance that much but isn't perfect
inner: if combine {
/// This `if` gets all the addresses associated with your contacts, parses them with regex to get all possible `chat_identifier`s,
/// then puts them into a nested array. Later on, the conversations check themselves with the nested arrays to find the associated `chat_identifier`s.
/// This section is probably not very optimized and probably also inaccurate. That's why it's optional.

addresses = selectFromSql(db: contacts_db, columns: ["c.c16Phone", "c.c17Email"], table: "ABPersonFullTextSearch_content c")

/// If can reverse, using #"((?<= )[0-9]{5,}\+|(?<= )([0-9]{5,7})(?= )(?!.*\2))"# accurately removes duplicates but is less accurate in other ways
let pattern = #"(?<= )(\+|)[0-9]{5,}(?= )"#
var regex: NSRegularExpression
do {
regex = try NSRegularExpression(pattern: pattern, options: [])
} catch {
self.log("Unable to create regex; not merging contacts", warning: true)
combine = false
break inner
}
addresses = selectFromSql(db: contacts_db, columns: ["c16Phone", "c17Email"], table: "ABPersonFullTextSearch_content")
let identifier_array = selectFromSql(db: db, columns: ["chat_identifier"], table: "chat", condition: "where chat_identifier not regexp \"chat[0-9]{10,}\"")
let identifiers: [String] = identifier_array.map({$0["chat_identifier"] ?? ""})

for i in addresses {
var personal_addresses = i["c.c17Email"]?.split(separator: " ").map({String($0)}) ?? [String]()
let phone = i["c.c16Phone"] ?? ""
let range = NSRange(phone.startIndex..<phone.endIndex, in: phone)
var personal_addresses = i["c17Email"]?.split(separator: " ").map({String($0)}) ?? [String]()
let phone = i["c16Phone"] ?? ""

var checked_matches = [String]()
let matches = regex.matches(in: phone, options: [], range: range)
personal_addresses += matches.map({String(phone[Range($0.range, in: phone)!])})
var checked_matches = personal_addresses
personal_addresses += phone.split(separator: " ").map({String($0)})

outerfor: for j in personal_addresses {
let len = j.components(separatedBy: .decimalDigits).joined().count
if !(j.count >= 5 && (len == j.count || (len == j.count - 1 && j.first == "+"))) {
continue outerfor
}
for l in checked_matches {
if (l.contains(j)) {
continue outerfor
}
}
checked_matches.append(j)
if identifiers.contains(j) {
checked_matches.append(j)
}
}

chat_identifiers.append(checked_matches)
Expand Down Expand Up @@ -538,13 +533,13 @@ final class ChatDelegate {
final func getAttachmentFromMessage(mid: String) -> [[String]] {
/// This returns the file path for all attachments associated with a certain message with the message_id of $mid

self.log("Gettig attachment for mid \(mid)")
self.log("Getting attachment for mid \(mid)")

/// create connection, get attachments information
var db = createConnection()
if db == nil { return [[String]]() }

let file = selectFromSql(db: db, columns: ["filename", "mime_type", "hide_attachment"], table: "attachment", condition: "WHERE ROWID in (SELECT attachment_id from message_attachment_join WHERE message_id is \(mid))")
let file = selectFromSql(db: db, columns: ["filename", "mime_type"], table: "attachment", condition: "WHERE ROWID in (SELECT attachment_id from message_attachment_join WHERE message_id is \(mid))")

var return_val = [[String]]()
self.log("attachment file length: \(String(file.count))")
Expand Down
5 changes: 0 additions & 5 deletions src/SMServer/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ struct ContentView: View {

self.log("GET main: " + ip)

/*if self.checkIfAuthenticated(ras: ip) {
res.send(self.main_page)
} else {
res.send(self.gatekeeper_page)
}*/
res.send(self.checkIfAuthenticated(ras: ip) ? self.main_page : self.gatekeeper_page)
}

Expand Down
Loading

0 comments on commit 6d696bd

Please sign in to comment.